def checksum(code, awards={'A': 15, 'B': 20, 'C': 30, '': 40}, joker='D'):
return sum(
awards.get(''.join(set(triplet)-{joker}), 0) for triplet in zip(*[iter(code)]*3)
)
checksum('ABCAABDCA') # 0
checksum('ADAAABDCA') # 15
def checksum2(code, awards={'A': 15, 'B': 20, 'C': 30, '': 40}, joker='D'):
return reduce(
lambda xsum, triplet: xsum + awards.get(
''.join(set(triplet).difference(joker)), 0
),
(code[0:3], code[3:6], code[6:9]), 0
)
if len(set(line[:3])) == 1:
income_amount += values[line[:3]]
elif 'D' in set(line[:3]) and len(set(line[:3])) == 2:
income_amount += values[line[:3].replace('D', set(line[:3])-{'D'})]
if len(set(line[3:6])) == 1:
income_amount += values[line[3:6]]
elif 'D' in set(line[3:6]) and len(set(line[3:6])) == 2:
income_amount += values[line[3:6].replace('D', set(line[3:6])-{'D'})]