Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for How Much Gold by nu4nu
from fractions import Fraction
METALS = ('gold', 'tin', 'iron', 'copper')
def checkio(alloys):
r = Fraction(-1, 2)
for k, v in alloys.items():
r += v / 2 if 'gold' in k else (1 - v) / 2
return r
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio({
'gold-tin': Fraction(1, 2),
'gold-iron': Fraction(1, 3),
'gold-copper': Fraction(1, 4),
}) == Fraction(1, 24), "1/24 of gold"
assert checkio({
'tin-iron': Fraction(1, 2),
'iron-copper': Fraction(1, 2),
'copper-tin': Fraction(1, 2),
}) == Fraction(1, 4), "quarter"
June 25, 2014
Comments: