You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
833 B
33 lines
833 B
#!/usr/bin/env python3
|
|
|
|
import sys, re
|
|
|
|
|
|
if __name__ == '__main__':
|
|
cards = [line.strip('\n').split(':') for line in open(sys.argv[1])]
|
|
|
|
res1 = 0
|
|
carddict = {}
|
|
for i in range(len(cards)):
|
|
carddict[i] = 1
|
|
for (card, nums) in cards:
|
|
cardnum = int(re.search(r'(\d+)', card).group())
|
|
win, num = nums.split('|')
|
|
win = set(win.split(' '))
|
|
num = set(num.split(' '))
|
|
winnum = win.intersection(num)
|
|
winnum.remove('')
|
|
winnings = len(winnum)
|
|
res1 += 2**(winnings-1) if winnings > 0 else 0
|
|
for i in range(1, winnings+1):
|
|
carddict[cardnum+i] += 1*carddict[cardnum]
|
|
|
|
|
|
# challenge 1
|
|
res1 = str(res1)
|
|
print(f"challenge 1:\n{res1}\n")
|
|
|
|
# challenge 2
|
|
res2 = sum(carddict.values())
|
|
print(f"challenge 2:\n{res2}\n")
|
|
|
|
|