1
0
Fork 0

add 2023/day4.2

This commit is contained in:
Sebastian Mark 2024-12-12 22:05:14 +01:00
parent 4c9b296e55
commit 2b7037676d

View file

@ -6,6 +6,8 @@
# pylint: disable=missing-module-docstring,missing-function-docstring,consider-using-f-string
from collections import defaultdict
def readinput():
cards = {}
@ -30,6 +32,16 @@ def main():
win_total += int(2 ** (cardwin - 1))
print("Scratchpad worth %d points" % win_total)
# part 2
cardnumbers = {i: 1 for i in cards}
for cardnumber, count in cardnumbers.items():
for _ in range(count):
numbers = cards[cardnumber]
cardwins = len(set(numbers["winners"]) & set(numbers["mine"]))
for i in range(1, cardwins + 1):
cardnumbers[cardnumber + i] += 1
print("Scratchpads: %d" % sum(cardnumbers.values()))
if __name__ == "__main__":
main()