Day 04
This commit is contained in:
13
day04/part1.py
Normal file
13
day04/part1.py
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
lines = (x.strip() for x in open("input.txt"))
|
||||
result = 0
|
||||
|
||||
for line in lines:
|
||||
winnings = set(int(x.strip()) for x in line[line.find(":")+1:line.find("|")].split(" ") if len(x))
|
||||
you_have = set(int(x.strip()) for x in line[line.find("|")+1:].split(" ") if len(x))
|
||||
num_overlap = len(you_have.intersection(winnings))
|
||||
if num_overlap > 0:
|
||||
result += 2**(num_overlap-1)
|
||||
|
||||
print(result)
|
||||
Reference in New Issue
Block a user