d04 part two

This commit is contained in:
Arthur 2023-12-04 10:32:36 +01:00
parent 389d684862
commit f4741b6158
1 changed files with 28 additions and 0 deletions

28
d04/run2.py Normal file
View File

@ -0,0 +1,28 @@
import sys
from functools import reduce
def main(myList, S = 0):
card=[c.split(": ")[1] for c in myList]
win_str_one = [s.split(" | ")[0] for s in card]
sto_str_one = [s.split(" | ")[1] for s in card]
win_str = [s.split(" ") for s in win_str_one]
sto_str = [s.split(" ") for s in sto_str_one]
win = [ [int(i) for i in item if i != ''] for item in win_str]
sto = [ [int(i) for i in item if i != ''] for item in sto_str]
copy = [1] * len(win)
for idx, p in enumerate(sto):
n = 0
for j in p:
if win[idx].count(j) > 0:
copy[idx+n+1]+= copy[idx]
n+=1
return reduce(lambda x, y: x+y, copy)
if __name__ == '__main__':
print(main(sys.stdin.read().splitlines()))