Skip to content

Latest commit

 

History

History
57 lines (45 loc) · 1.31 KB

4.md

File metadata and controls

57 lines (45 loc) · 1.31 KB

Day 4

I got sloppy and didn't read the description fully.

Part 1 Part 2 Total
Time 8:17 11:20 19:37

Part 1

Time slowers involved the following

  • Not realizing the example data wasn't as wide as the real data
  • Accidentally including the card number
  • Accidentally submitting the wrong answer because of these several times
from helpers.datagetter import aocd_data_in

din, aocd_submit = aocd_data_in(split=True, numbers=True)
ans = 0

for card in din:
    winners = card[1:11]
    mine = card[11:]

    w = 0
    for num in winners:
        if num in mine:
            w += 1

    if w > 0:
        ans += 2 ** (w - 1)

aocd_submit(ans)

Part 2

Nothing too special, just took a little to think of the solution. Then of course to remember to switch the 6 back to 11 again, which cost me a minute due to timeout.

from helpers.datagetter import aocd_data_in

din, aocd_submit = aocd_data_in(split=True, numbers=True)
copies = [1 for _ in range(len(din))]

for i in range(len(din)):
    card = din[i]
    winners = card[1:11]
    mine = card[11:]

    w = 0
    for num in winners:
        if num in mine:
            w += 1
    if w > 0:
        for j in range(i+1, i+w+1):
            copies[j] += copies[i]

ans = sum(copies)
aocd_submit(ans)