Datasets:
Download code/math_code_014_verify.py from efe-T/bilingual-math-code-verification-v1: direct link, hf CLI and curl.
- Browser
- Download file 740 Bytes
-
https://huggingface.co/datasets/efe-T/bilingual-math-code-verification-v1/resolve/main/code/math_code_014_verify.py
- Command line
-
hf download hf://datasets/efe-T/bilingual-math-code-verification-v1/code/math_code_014_verify.py
-
curl -L -o math_code_014_verify.py https://huggingface.co/datasets/efe-T/bilingual-math-code-verification-v1/resolve/main/code/math_code_014_verify.py
740 Bytes
| from itertools import permutations | |
| from fractions import Fraction | |
| A = [[1, 1, 1], [2, -1, 1], [1, 2, -1]] | |
| b = [6, 3, 2] | |
| def det(matrix): | |
| total = 0 | |
| for p in permutations(range(3)): | |
| inversions = sum(p[i] > p[j] for i in range(3) for j in range(i + 1, 3)) | |
| term = (-1) ** inversions | |
| for i in range(3): | |
| term *= matrix[i][p[i]] | |
| total += term | |
| return total | |
| denominator = det(A) | |
| assert denominator == 7 | |
| answer = [] | |
| for col in range(3): | |
| replaced = [row[:] for row in A] | |
| for r in range(3): | |
| replaced[r][col] = b[r] | |
| answer.append(str(Fraction(det(replaced), denominator))) | |
| result = {"solution": answer} | |
| import json | |
| print(json.dumps(result, ensure_ascii=False, sort_keys=True)) | |