Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for How Much Gold by brownie57
from fractions import Fraction
def checkio(alloys):
bar = 0
for i in alloys.keys():
if 'gold' in i:
bar += alloys[i]
else:
bar += 1 - alloys[i]
return (bar - 1) / 2
#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"
Jan. 19, 2019