Datasets:
Download code/math_code_003_verify.py from efe-T/bilingual-math-code-verification-v1: direct link, hf CLI and curl.
- Browser
- Download file 649 Bytes
-
https://huggingface.co/datasets/efe-T/bilingual-math-code-verification-v1/resolve/main/code/math_code_003_verify.py
- Command line
-
hf download hf://datasets/efe-T/bilingual-math-code-verification-v1/code/math_code_003_verify.py
-
curl -L -o math_code_003_verify.py https://huggingface.co/datasets/efe-T/bilingual-math-code-verification-v1/resolve/main/code/math_code_003_verify.py
649 Bytes
| from itertools import combinations | |
| items = [("A", 2, 3), ("B", 3, 4), ("C", 4, 5), ("D", 5, 8), ("E", 9, 10)] | |
| feasible = [] | |
| for size in range(6): | |
| for subset in combinations(items, size): | |
| weight = sum(x[1] for x in subset) | |
| value = sum(x[2] for x in subset) | |
| if weight <= 10: | |
| feasible.append(([x[0] for x in subset], weight, value)) | |
| best_value = max(x[2] for x in feasible) | |
| best = [x for x in feasible if x[2] == best_value] | |
| assert len(best) == 1 | |
| names, weight, value = best[0] | |
| result = {"items": names, "weight": weight, "value": value} | |
| import json | |
| print(json.dumps(result, ensure_ascii=False, sort_keys=True)) | |