From 2b7037676df7c7cb24cd7714ed9a2548a2e7895a Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Thu, 12 Dec 2024 22:05:14 +0100 Subject: [PATCH] add 2023/day4.2 --- 2023/04/main.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/2023/04/main.py b/2023/04/main.py index e4e87fb..9e447c1 100644 --- a/2023/04/main.py +++ b/2023/04/main.py @@ -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()