-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay4PileOfCards.py
More file actions
31 lines (27 loc) · 881 Bytes
/
Day4PileOfCards.py
File metadata and controls
31 lines (27 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import sys, os
import numpy as np
def get_winning_numbers(string: str):
split1 = string.rstrip('\n').split(': ')
split2 = split1[1].split(' | ')
winning_numbers = split2[0].split(' ')
your_numbers = split2[1].split(' ')
winning_numbers = set(winning_numbers)
worth = 0
for yn in your_numbers:
if yn in winning_numbers and yn.isnumeric():
if worth == 0:
worth = 1
else:
worth *= 2
return worth
if __name__ == '__main__':
input_file = 'Day4Input.txt'
# input_file = 'Day4Input_test.txt'
engine_schematic = []
total_worth = 0
with open(input_file, 'r') as f:
curr_line = f.readline()
while curr_line:
total_worth += get_winning_numbers(curr_line)
curr_line = f.readline()
print(total_worth)