d04 part one

This commit is contained in:
Arthur 2023-12-04 09:03:00 +01:00
parent 1796d6a0c9
commit 389d684862
2 changed files with 34 additions and 0 deletions

6
d04/exemple1.txt Normal file
View File

@ -0,0 +1,6 @@
Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19
Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83
Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36
Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11

28
d04/run1.py Normal file
View File

@ -0,0 +1,28 @@
import sys
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]
#print(win)
#print(sto)
for idx, p in enumerate(sto):
n = 0
for j in p:
#print(j, win[idx])
n += win[idx].count(j)
S+= 2 ** (n-1) if n > 0 else 0
return S
if __name__ == '__main__':
print(main(sys.stdin.read().splitlines()))