Further optimise day 4

This commit is contained in:
Sijmen 2023-12-05 14:19:16 +01:00
parent 2194015259
commit 4dcc750416

View file

@ -1,13 +1,14 @@
import fileinput
def main():
#
# Part 1
#
cards = []
part1 = 0
for i, line in enumerate(fileinput.input()):
card = line.rstrip().split(": ")[1]
(winning, owned) = ({int(i) for i in h.split()} for h in card.split(" | "))
for line in fileinput.input():
card = line.split(": ", 1)[1]
(winning, owned) = ({int(i) for i in h.split()} for h in card.split(" | ", 1))
count = len(winning & owned)
cards.append(count)
part1 += 1 << count - 1 if count else 0
@ -22,3 +23,5 @@ for i in range(len(cards)):
part2 += dp[i]
print(part1, part2)
main()