Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
12-liner: Solved a System of Linear Equations solution in 3rd party category for How Much Gold by Stensen
from fractions import Fraction
import numpy as np, sympy as sp
METALS = {'gold': 0, 'iron': 1, 'copper': 2, 'tin': 3}
def checkio(alloys):
arr = np.vstack((np.zeros((3, 5), dtype='i'), [1, 1, 1, 1, 1])).tolist()
for idx, c in enumerate(alloys.keys()):
i, j = c.split('-')
arr[idx][METALS[i]] = 1
arr[idx][METALS[j]] = 1
arr[idx][4] = alloys[c]
g, i, c, t = sp.symbols('g i c t')
return Fraction(str(sp.solve_linear_system(sp.Matrix(arr), g, i, c, t)[g]))
Oct. 30, 2020