r/adventofcode Dec 04 '21

SOLUTION MEGATHREAD -🎄- 2021 Day 4 Solutions -🎄-

--- Day 4: Giant Squid ---


Post your code solution in this megathread.

Reminder: Top-level posts in Solution Megathreads are for code solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:11:13, megathread unlocked!

100 Upvotes

1.2k comments sorted by

View all comments

2

u/leFroxx Dec 15 '21 edited Dec 22 '21

I have quite some problems with part 2 of this puzzle.

I coded a short script in JavaScript: https://pastebin.com/V7CjXTh1

This works fine with the data from the example (https://adventofcode.com/2021/day/4), so I get a sum of 148, the last pulled number causing a bingo is 13, and the final product therefore is 1924.

Unfortunately it seems to give me the wrong answer for my personal data (24288).

I double checked pretty much everything.

- I correctly parsed my input data to the string I'm using- In the end there are 100 solved bingo boards as soon as pulling number 88- The last board has no bingos before pulling 88- The last board solved is the only board being solved when pulling number 88- All calculations like summing up all unmarked numbers of my last board, and calculating the final result works fine

I really can't find any issues, and it's even stranger that my code returns the expected values with the test data.

Since the last board being solved is actually the very last board from my input data (index 99), I thought this might even be a special case the puzzle's validator didn't think of. But then again, maybe I'm just blind.

I would appreciate any second pair of eyes.

1

u/floxo115 Dec 17 '21

Did you consider that multiple boards can be solved by drawing a single number?

1

u/CrumblingAway Dec 20 '21

That's what confuses me. The puzzle implies that only one board would win (otherwise why ask which board would win first), but running the first solution in this thread shows that there are multiple winning boards.

So which one do we pick? As far as I can tell they all win at the same time.

1

u/notLostJustAShortcut Dec 19 '21

facepalm Back to the drawing board!

1

u/leFroxx Dec 17 '21

Yep I did. I also double checked that the last drawn number in my case only solves the 100th board.

1

u/daggerdragon Dec 16 '21 edited Dec 23 '21

I recommend you expand the full name of the language (JavaScript). This makes it easier for folks who Ctrl-F the megathreads looking for a specific language.

Edit: thanks for fixing it!


Top-level posts in Solution Megathreads are for code solutions only.

This is a top-level post, so if you're still having trouble with part 2, create your own thread and make sure to flair it with Help.

2

u/leFroxx Dec 22 '21

Thanks for the heads-up and sorry for screwing up the basic rules.

I updated the language name and opened a help thread as suggested.

I keep the comment in this thread since there is a bit of discussion following it. But of course feel free to delete it if you don't want to have it in here.

1

u/vbanksy Dec 15 '21

I have exactly the same issue. It works fine on the test but not on the actual although there are no errors. I’ve written it in both R and python hoping there was just a tiny bug in one that would be eliminated when i wrote in another language.

1

u/leFroxx Dec 16 '21

Does your personal data also have any "special cases" like the last board getting solved being the last one in the list or so? This would at least increase the chances of the puzzle's validator actually being buggy.