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 kurosawa4434
from re import match
METALS = ('gold', 'tin', 'iron', 'copper')
def checkio(alloys):
wk_alloys = {}
for k, v in alloys.items() :
match_obj = match(r'(.+)-(.+)', k)
metal1 = match_obj.group(1)
metal2 = match_obj.group(2)
other_metals = list(set(METALS) - set((metal1, metal2)))
wk_alloys[k] = v
wk_alloys[other_metals[0] + '-' + other_metals[1]] = 1 - v
a = wk_alloys['gold-tin'] if 'gold-tin' in wk_alloys else wk_alloys['tin-gold']
b = wk_alloys['gold-iron'] if 'gold-iron' in wk_alloys else wk_alloys['iron-gold']
c = wk_alloys['tin-iron'] if 'tin-iron' in wk_alloys else wk_alloys['iron-tin']
return (a + b - c) / 2
July 21, 2016
Comments: