Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Naive solution in Clear category for How Much Gold by veky
from fractions import Fraction
METALS = ('gold', 'tin', 'iron', 'copper')
def checkio(alloys):
system = [[metal in alloy for metal in METALS] + [alloys[alloy]]
for alloy in alloys] + [[1]*5]
for unknown in 3,2,1,0:
pivot = next(equation for equation in system if equation[unknown])
system.remove(pivot)
for equation in system:
coefficient = Fraction(equation[unknown], pivot[unknown])
for i in range(5): equation[i] -= pivot[i] * coefficient
return pivot[-1] / pivot[0]
Oct. 13, 2013
Comments: