add 2023/day4.2
This commit is contained in:
parent
4c9b296e55
commit
2b7037676d
1 changed files with 12 additions and 0 deletions
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue