File size: 740 Bytes
93237a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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))