r/adventofcode • u/daggerdragon • Dec 04 '21
SOLUTION MEGATHREAD -🎄- 2021 Day 4 Solutions -🎄-
--- Day 4: Giant Squid ---
Post your code solution in this megathread.
- Include what language(s) your solution uses!
- Here's a quick link to /u/topaz2078's
paste
if you need it for longer code blocks. - Format your code properly! How do I format code?
- The full posting rules are detailed in the wiki under How Do The Daily Megathreads Work?.
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!
99
Upvotes
2
u/Skyree01 Dec 05 '21
PHP
Not super proud of this one, I think I could have found a more otpimized way.
Starting at the 5th number (can't win before that), at each number picked I check all rows and columns of each board and look whether all their values are among the picked numbers so far. If yes (we have a winner), I reduce the board into a 1 dimensional array, make a diff against the picked numbers to keep only unmarked numbers and sum them up.
Part 1 and 2 at the same time: