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
pasteif 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!
98
Upvotes
7
u/hwartig Dec 04 '21 edited Dec 04 '21
I build a visualization for todays puzzle in Javascript and ReactJS. You can copy & paste your input or drag n drop a text file and then step through the bingo process or let it auto play for you.
The visualization will show you which card would go to the squid and which card would go to santa according to the rules of part two.
You can see a screenshot and the somewhat still messy code on glitch.
6
u/Loiuy123_ Dec 04 '21
Tweetable Python Part 1
This was my first time doing code golf and it worked! It also fits in tweet :)
4
u/obijywk Dec 04 '21 edited Dec 04 '21
Python 80/36.
Somewhat verbose, but I wrote it quickly! The first line it prints is the answer to part 1, and the last line it prints is the answer to part 2.
4
u/No-Requirement-8723 Dec 04 '21 edited Dec 05 '21
## Python
A rather short numpy solution here. Assumes the input file has been loaded and parsed into a 1d array `numbers` (shape = `(M,)`) for the bingo numbers, and a 3d array `boards` (shape= `(N, 5, 5)`) for the bingo boards.
The returned array has the score for every board, ordered by when they achieved bingo. So the answer to part one is the first element, the answer to part two is the last element.
3
u/BluFoot Dec 04 '21 edited Dec 04 '21
Ruby 234 bytes (331/181)
I would have hit leaderboard but I wasted several minutes implementing diagonal checking, and then debugging why I was getting the wrong solution.
3
u/JoMartin23 Dec 04 '21 edited Dec 04 '21
Common Lisp
So my solutions should have been called loop, so here's some mapcar.
3
u/jitwit Dec 04 '21
J Programming Language
in =: aoc 2021 4
bs=:}.&>}.in[b=:,>{.in=:(([:<".;._2);.2~(2#LF)&E.)' '(I.','=in)}in,LF
rs =: (+./"1@:(*./"_2)+.+./"1@:(*./"_2)@:(|:"_2)) bingo=:bs&e.\b
'i j'=.ij=:{.0 0-.~,/(*(,"0/~&i.)~/@$) rs
(i{b)*+/,(j{bs)*-.(<ij){bingo NB. part a
'i j'=.ij=:1 0+{:0 0-.~,/(-.*(,"0/~&i.)~/@$) rs
(i{b)*+/,(j{bs)*-.(<ij){bingo NB. part b
3
u/disklosr Dec 04 '21 edited Dec 04 '21
Python 3
Kept things really simple:
['*','*','*','*','*',]pattern.*char) multitiplied by the drawn number3
u/zerothepyro Dec 04 '21 edited Dec 05 '21
Had a lot of fun and challenges with this one. Had a why does this not work and then a why does this work since the code did not change lol
Python 3.10
3
u/anothergopher Dec 04 '21 edited Dec 05 '21
Java, regular expressions and lists only
3
u/Sykout09 Dec 05 '21
Rust:
Single pass solution.
Manage to figure out that if you know the calling numbers order ahead of time, you can actually calculate the board winning position independantly.
Just need to create an array mapping from
call_number => called_turn. Then remap all the board numbers to the called turn number.From there, you just have to find the max in each of the winning line (a.k.a. the turn that this line will win on) And then calculate the min of all those winning turn number, resulting in the turn which the board will win on.
The reset is just find the board with either the minimum or maximum win turn.
Timing is:
[4.7715 us 4.7799 us 4.7913 us][4.7767 us 4.7897 us 4.8111 us]2
u/soodssr Dec 04 '21 edited Dec 06 '21
PHP
2
u/sdolotom Dec 04 '21 edited Dec 04 '21
Haskell
Each board is a mapping from a number to its row and column. After each turn we remove the number from the mapping and increment the corresponding row and column until we reach 5. First and second part solutions differ in one line:
Full code
2
u/SV-97 Dec 04 '21 edited Dec 04 '21
Going for a more array-programming-ish style with python and numpy this year which seems great in terms of readability and code size (21 / 24 lines that could be brought down a bit by removing comments and assertions):
Part 1: https://github.com/SV-97/AdventOfCode2021/blob/main/Day_04_1/main.py
Part 2: https://github.com/SV-97/AdventOfCode2021/blob/main/Day_04_2/main.py
2
u/nirgle Dec 04 '21
Oh look, a giant squid to play bingo with. If they think we're intimidated by cephalopods they don't know us, do they
Solution in C# with a dabbing of LINQ to ease the monotony of handily defeating a basic squid. Is this all the ocean has in store for adversity?
2
u/adarsh0d Dec 04 '21 edited Dec 04 '21
https://github.com/adarsh0d/advent-of-code-2021/blob/master/day4/day4.js - feels suboptimal, but I got right answer (JavaScript)
2
u/[deleted] Dec 04 '21 edited Dec 04 '21
Python
fun problem, but my worst solution. for loops overload: https://github.com/rbusquet/advent-of-code/blob/main/2021/04/day4.py
2
u/tkdonut Dec 04 '21 edited Dec 05 '21
My solution, very inexperienced at Rust so any and all feedback welcome :) Feel like I'm just throwing for loops at everything.
https://github.com/thomaskendrick/advent_of_code_2021/blob/main/src/bin/day4.rs
Edit: Unbroke link, Ty daggerdaggon for flagging.
2
u/uNxe Dec 04 '21
Scala
Part1
part2
2
u/gualopezb Dec 04 '21 edited Dec 05 '21
Javascript
Part 1
Part 2
2
u/Standard-Affect Dec 05 '21 edited Dec 07 '21
R Solved, after some agonizing debugging. R's complex matrices and functions for input reading make it an ideal choice for this problem.
I had a working solution for the second part pretty quickly, except I stopped iterating when there was only one board left, not when it actually won. When debugging, I thought I was doing something wrong because several rounds had multiple winners, which the description didn't mention, but that was a red herring.
2
u/itsa_me_ Dec 05 '21 edited Dec 05 '21
Object Oriented Python
Part 1
Part 2, I modified mark_and_check_boards and main
2
u/cjb230 Dec 05 '21 edited Dec 06 '21
Python
Part A:
https://github.com/cjb230/advent_of_code_2021/blob/main/day_4_a.py
It's basically the first method that came to mind, so it's a little profligate with data structures, but that allows it to go through the data once and be done. Part B is the same with a couple of very small changes to get the worst board rather than the best board.
I have two questions:
2
u/vimsee Dec 05 '21 edited Dec 06 '21
Completed with 0 if statements - Python
Completed with no external libs, no if statements and to much free time this weekendhttps://github.com/emilbratt/adventofcode/tree/main/2021/4
2
u/Ok-Hearing9361 Dec 08 '21 edited Dec 08 '21
Simple PHP parser and solver. I use XAMPP with Eclipse debugger.
Part one was reductive solution and part two was additive. Only had to change/add a couple lines.
https://topaz.github.io/paste/#XQAAAQDSCgAAAAAAAAAeD8qHAhP+0dx3SZG1Jlr7aeG8goc5IY/yrukxPTpPcBpaX4UBno9avPUIjIlm1YKdaGD8qKBA2SSUiYfLCidR/EJUTjXIwLrnmMoemqAnibZGQQUcRXi1n+BpN//8rzlptwnuLKmk6XtDAtR4cMNjckbulgcSzJtBOPBiKm4Eh2RsJfgq2v77TqByExxxfS+jGWNvdwIa8LxUKbKvkOcfzxnfOBCxKksEP+MQgI66wO7Xb0TIQoUJWnArIB+PnzmU3Ty4tywdin050LKwvuk5DT4H+ED8fzTr2gSQEGZrHGjZHDpCm65GgD7T51AW2ctcsB8Oa6nRwp7Stha90UGETX0i6FuiuApokBfQUZixRdmKNdlgbR3FjQW+ooRncuipgJ9MZ8bGd8M+LSURAAn+cgr6NysY5wffG2pvPHZ8QyQRCdISgOFKQAzzrrC/Typ/IvK3hSEBmlihjqO5KdAfYD3hQQ362qjXiQaKIT51M5XZGx44TwBL8wM4JVYWaWNJHAa2KH2kDX6XFx1AIfnLwdOtoDM5H0Tu5roLFHHmCoLb+TdlAohdmHbaM0l3wVHEmPGkhwUmebveDoEc97Kf0kct/U6eZpHU2HhNiAgp2UdcCkD0pA0aE6AMr4eaScvq3SZgAzEZHYer7Xqcgcpz/Uk2UMUN1jRN5+Ra5GDOjekMhboFYAKEENoh1OswG2lvxpFLaGl+//r7AtmhNCyCjLzeZ1usGSsmiM04sYOmCJC663v9xSgwhkvMVz6n29VBWOl/aau8WXdyBQHR+pdg6pDcAkVRTL7BWKVOnHwvta2bcMmmT0QCCXHWpYvLDQrVtJWa+bRSUHpcZegi4Nm9kBWHs0zZH42+fgRq+9bovPAMkvX+xT/okzVrQs8Sv45EYiZp5J4z3/lw4K2yaFXrqhIVTaee31xSwFyO3ZSfyWNMb5xThfD+929l4g==)
2
u/[deleted] Dec 08 '21
Here is a list-comprehension-based python code, it prints the solution to part 1 and part 2 :
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.
2
u/x3mcj Dec 16 '21 edited Dec 18 '21
This one, really kicked me hard!
Python
Part 1
Part 2
2
u/pgaleone Dec 17 '21 edited Dec 24 '21
Tutorial: advent of Code 2021 in pure TensorFlow - day 4
Code: https://github.com/galeone/tf-aoc/blob/main/4/main.py
30
u/CCC_037 Dec 04 '21
Rockstar
Same program for both parts (will tell you how long each board takes to complete and what their scores are, but won't pick out the one you want)
28
u/4HbQ Dec 04 '21 edited Dec 05 '21
Python, with some useful NumPy operations:
Update: I've managed to store all board states (at all rounds) in a single 4-dimensional matrix. The computations (determining all winners, computing all scores) are now just simple array operations like
cumsum()orargmax().23
u/4HbQ Dec 04 '21 edited Dec 04 '21
Python, using a 4-dimensional NumPy array to store marked numbers for all boards and all rounds. This way, we don't need any loops or comprehensions!
Here
mis a 4-D matrix containing each board after drawing each number. It indicates whether a position on a board has been drawn in a round (or before, because ofcumsum()). Now we can simply compute the scoressfor each board after each round and find each board's winning roundwusingargmax(). Finally, we print the scores of the first and last winner.16
u/autid Dec 04 '21
FORTRAN
Anyone else lose a buttload of time because they skim read over "(Diagonals don't count.)" or was that just me?
14
u/Tails8521 Dec 04 '21 edited Dec 05 '21
Motorola 68000 assembly (On a Sega MegaDrive)
Part 1 works, part 2 currently doesn't work on my input (but it works on the example), I'm still trying to figure out whyBoth parts work properly now, all I had to do to fix part 2, was to add these 2 lines:
after
found_winner:It's one of these cases where you make assumptions in part 1 "why would I make sure to keep that pointer pointing to the correct location for the next iteration? We found a winner already, we're done" and it ends up biting you for part 2.
13
u/janiczek Dec 04 '21
APL
Meh, today it took three lines just to parse the input into a nice-to-work-with shape! Can you imagine the embarrasment?
13
u/Smylers Dec 05 '21 edited Dec 05 '21
Vim keystrokes for both parts. Load your input, ensure
gdefaultis off and the cursor is on the first line, then:That should leave you with two lines, with the part 1 answer on the top line and part 2 on the second.
The main substitution and pattern match are the same as in my Perl solution.
As each board wins, it is squashed into a single line and moved out of the way, prepending the most recently called number. Once there are no more boards left, all but the lines containing the first and last boards to win are deleted, leaving something like:
The next three
:%s///s at the end then convert those numbers into the required arithmetic expressions, with the above becoming:And the final
:%s///evaluates those, giving the answers.11
u/THE_DR_IS_PRESENT Dec 04 '21 edited Dec 04 '21
230/765
Brute-forced it in VS Code by performing a regular expression search in the text editor with the call numbers OR’d and scrolling to see if boards were solved yet or not
11
u/jayfoad Dec 04 '21
Dyalog APL
10
u/DFreiberg Dec 04 '21 edited Dec 04 '21
Mathematica, 26 / 62
For some reason, coming up with a reasonably way to loop through the games and do both parts at once was much easier than finding a reasonably elegant way to get the input from the text file without having to manually adjust either the calls or the boards.
Setup:
Main Loop:
Answers:
[POEM]: There Was a Sub That Had a Squid
Across and down,
You count to five;
You fear to drown,
But you're alive.
The squid is big
Enough to hew,
Like one small twig
Your sub in two.
It wants a show
And you've the thing
Which ends in 'o'
And starts with 'bing'.
It makes a bet
And you agree
(You've racked some debt
Out here at sea).
It weighs a ton,
Your questioned sin:
Should it have fun,
Or should you win?
You've rigged the boards,
So now, you think:
What use rewards
If then, you sink?
10
u/GaloisGirl2 Dec 04 '21 edited Dec 11 '21
COBOL
9
u/jonathan_paulson Dec 04 '21
Python. 30th on part 1; 15th on part 2. Video of me solving.
I found parsing the input tricky.
8
u/firetech_SE Dec 04 '21
Ruby 165/328
I never thought I'd come that close to actual points (I'm mainly playing on a private leaderboard from the company I work at). Considering I was going quite slow and steady, I was quite surprised by the 165 rank for part 1.
Just when I was considering how to (somewhat cleanly) implement a check of the board diagonals, I read "(Diagonals don't count.)" in the corner of my eye, making the check a one-liner:
:)
8
u/benn_88 Dec 04 '21 edited Dec 04 '21
I spent most of my time solving part 0 (reading the input file into nice data structures).
Python: https://github.com/bennuttall/advent-of-code-2021/blob/main/04/04.ipynb
Each board comprised a list of sets (the numbers in each row and column). I built up a set of called numbers and each board checked to see if it had a set which was a subset of the called numbers set.
7
u/[deleted] Dec 04 '21
Python 147/93
7
u/xelf Dec 04 '21 edited Dec 04 '21
python,
looped over numbers setting them to -1 as I found them, then looked for sum() == -5
runs in about 15ms, which outpaces the numpy and pandas solutions I tried.
7
u/relativistic-turtle Dec 04 '21
IntCode
Day 4 Int-count: 5030 integers
Not giving up!
(Note: IntCode-program assumes 100 numbers drawn, and 100 bingo-boards)
7
u/Smylers Dec 04 '21 edited Dec 05 '21
Perl regexp solution for both parts at once:
I wrote this without seeing /u/quappa's solution, honestly! But our approach has turned out very similar, even down to using
##as the characters to indicate found numbers. Running it requires a little boilerplate at the top (pretty minimal today).Each time through the
whileloop (over the numbers being called),grepis used to filter out winning boards: if the regexp doesn't match, then keep the board in; otherwise, print the relevant product if either we haven't had a winner yet or this is the final board.Edit: Made the first line shorter by removing an unnecessary
localand combining the variable initializations and assignments.7
u/miran1 Dec 04 '21
Python
Using set operations (
<=,-):Full code (parsing input, custom functions, etc.) at: https://github.com/narimiran/AdventOfCode2021
7
u/voidhawk42 Dec 04 '21 edited Dec 05 '21
APL, think this can still be golfed a bit:
EDIT: Ah, here we go - a much nicer (imo) solution without recursion:
EDIT2: And a video walkthrough of the second solution if you're so inclined.
6
u/NohusB Dec 04 '21
Kotlin
Part 1
Part 2
6
u/RandomGuyJCI Dec 04 '21
This is literally my first time working with recursive loops in APL so I'm sure this can be made much cleaner, but it works:
Please do let me know of a better way to do this!
6
u/clumsveed Dec 04 '21
Java Solution
I'm a high school AP Comp Sci teacher, so as always, the goal is for my solutions to be easily understood by first year programming students.
Day 4 Solution
all solutions - repl.it
The last 'hiccup' that I had to iron out for part 2 was playing until the final card actually won. I thought it would be okay just to play the game until there was only 1 card left. For some insane reason, I assumed the next number called would complete that card. Once again, trying to save 3 nanoseconds of runtime cost me 10 minutes of life haha.
6
u/Pinkamina_D_Pie Dec 05 '21
APL
2
u/Brofistastic Dec 05 '21
After reading through some of these answers, i'm not convinced most of the people on this subreddit are humans.
5
u/hugh_tc Dec 04 '21 edited Dec 04 '21
Python 3, 29/57.
Part 1, Part 2, and (edit) the cleaned-up version.
Tripped up on Part 2 by using
ias an index for multiple nested loops. Classic!5
u/MuumiJumala Dec 04 '21
Ruby 31/169
I think getting excited about getting my first leaderboard points ever slowed me down for the second part but I'll take it!
5
u/leijurv Dec 04 '21 edited Dec 04 '21
Python. 4th place, 434th place
Screen recording https://youtu.be/apwicp85-50
I wrote part 1 counting diagonals and it worked. I hit a wall on part 2 and it took me a long time to go back and realize that part 1 working was a fluke and I needed to not count diagonals. :( I got the 1 minute, 1 minute, then 5 minute timeouts. :(
Part 1
Part 2
5
u/ka-splam Dec 04 '21
PowerShell
Part 1:
Part 2:
I said I wouldn't race this year, it was too stressful, I wish I hadn't. Tried to do it without splitting the boards into 2D grids, and got as far as marking the numbers, checking the rows with regex, and then getting stuck on checking columns. Screwed up the grid split and took ages to work out what was going wrong (powershell automatic array enumeration, for one). 45 minutes for part 1. Couldn't fit removing the winning boards in, major rewrite for Part 2 and several failed submissions later, and working through the test cases, realised I messed up the row check in a way that coincidentally didn't break before. ~85 minutes to finish.
5
u/0rac1e Dec 04 '21 edited Dec 04 '21
Raku
More dirty nested-loops today, but this problem was certainly easier than yesterdays.
I'm parsing the input (to an array of integers, and an array of integer matrices) in one expression, thanks to the power of destructuring binds.
Hrm, now I have arrays of
Ints, how do I keep track of which are marked? I guess I'll just convert them to aNum(float), then I can tell the difference with type checks later. I could have maybe created aMarkedrole and applied that, but this was less effort.Loop variables in Raku are read-only by default, so in order to "mark" the numbers I need the loop var to be in a read-write container. I could do that with a trait, like so
for @row -> $i is rw { ... }, but instead I'm using the syntactic versionfor @row <-> $i { ... }. This might be the first time I've used this syntax as I typically prefer the more visually obvious trait.Now after marking a board, I just have to check if
anyof the board rows (@b) or columns ([Z] @b) areallaNumtype... so thatsif any(|@b, |[Z] @b).all ~~ Num. Then I just pull out all theInt's, sum them together and multiply by the current number.Lastly for part 2, I just created a hash to track which boards have won and wait until the won count (elems) matches the number of boards. Calling
.elemsis not necessary here, because checking==on Iterables will numify to their elem count, but I like being explicit here.5
u/imbadatreading Dec 04 '21
This is as concise as I can get my code while hopefully still being readable.
Python:
5
u/chicagocode Dec 04 '21
Kotlin -> [Blog/Commentary] - [Code] - [All 2021 Solutions]
Parsing - I used filter and chunked to do most of the real work, and got to use a typealias.
Part 1 - Keep drawing numbers until we have a winner. Kind of like how bingo is played IRL.
Part 2 - Flip part 1 around. Instead of trying to find the first winner, run it all backwards and find the first loser and calculate its score.
Fun!
5
u/AtomicShoelace Dec 04 '21
Quick and simple python solution:
5
u/phil_g Dec 04 '21
My solution in Common Lisp.
Well, today was an "Advent of Reading Comprehension" for me. I went out of my way to check diagonal lines, having missed the part that said they didn't count. Fortunately, the example data included a board that completed a diagonal before a row, so I was able to get things sorted out without too much difficulty.
This is also the first day this year that I actually had significant data structures. I made board objects, where each one had a map of numbers to cells and a map of cells to their marked status. For ease of processing, each object also had the size of the board and a map from cells to sets of the cells' neighbors.
Part two tripped me up briefly with the fact that more than one board could get a bingo at the same time. My initial code assumed one board at a time.
As a side note, I took inspiration from a post the other day about adding AoC badges to your repository README file. I use GitLab, which lets you define badges as properties of your repository. So I added badges to my repository's header area, driven by a JSON file in the repository. The JSON file is updated manually by a script. (I might add some automated updates at some point, but manual works okay for now.)
5
u/mavus74 Dec 04 '21
Finally got around to do today's puzzle - F#: day04.fsx
5
u/probablyfine Dec 04 '21
JQ (Source and tests)
5
u/tmp_advent_of_code Dec 04 '21
Rust:
https://github.com/McSick/AdventOfCode2021/blob/main/04/bingo/src/main.rs
New to Rust and trying to wrap my head around it. Open to feedback.
5
u/mgkhuie Dec 05 '21 edited Dec 05 '21
Been tackling AoC using only Google Sheets (see yesterday's snippet here). Today's challenge took some more effort to design and structure, but here it is: Snippet of Day 4
Didn't plan for it, but this design let me answer Part 2 immediately without any modifications 👍
5
u/skarlso Dec 05 '21
Go / Golang Tutorial Blog Post.
4
u/LtHummus Dec 04 '21 edited Dec 04 '21
Scala. It's ugly, but i don't care haha. Prints the winning boards' scores in order of their wins:
My Bad Code
edit: reading it now i want to clean it up, ugh haha
edit 2: there, now it's at least all functional (ooooOOOOOO) My Slightly Less Bad Code
4
u/mcparadip Dec 04 '21
Python 10/13
Code is horrendous but was easy to copy/paste.
4
u/BaineWedlock Dec 04 '21
F# https://github.com/bainewedlock/aoc-2021-fsharp/blob/master/aoc-2021-04/Solution.fs
4
u/SuperSmurfen Dec 04 '21 edited Dec 04 '21
Rust (1528/2213)
Link to full solution
Kind of messy today. The problem itself was not that hard, there were just a lot of things that could go wrong along the way. Finished at an ok place, I guess, but I really felt like using a strictly typed language like Rust slowed me down here.
A trick for parsing the input is to split by "\n\n":
For part 2 I used a hashset of the remaining boards and removed winners until the last had won:
4
u/quappa Dec 04 '21 edited Dec 04 '21
Perl
Upd: added "/s" modifier as pointed by Smylers in comments.
4
u/sim642 Dec 04 '21 edited Dec 04 '21
My Scala solution.
I'm just using sets for the numbers appearing in rows and columns, makes it easy to mark numbers. Once one of the sets becomes empty, just add up everything in the row sets to get the remaining sum.
EDIT: I now came up with an alternative and even more optimal solution. You can first construct the map from number to its index. Then for each board square you can separately look up the index when it will be marked. Take maximum by rows and columns (last one in the row/column marks the entire thing) and then minimum by all those maximums (to find the earliest marked row/column). This gives the time when the board wins without iterating through the numbers to mark them.
4
u/u794575248 Dec 04 '21 edited Dec 04 '21
J Language, Part 2
At first I tried to iterate over the numbers (first line of the input) and mark a number in all the boards, until some row or column in a board has all cells marked. But then the next approach dawned on me. Comments by line:
4
u/zedrdave Dec 04 '21
Extremely straightforward, if not particularly witty, Python solution:
4
u/SetiPL Dec 04 '21 edited Dec 04 '21
Kotlin:
4
u/AOC_2020 Dec 04 '21 edited Dec 04 '21
// KOTLIN
4
u/[deleted] Dec 04 '21 edited Dec 06 '21
My solution in Python.
4
u/allaboutthatmace1789 Dec 04 '21
Clojure:
Source Code
Blog / Long form
4
u/qwesda_ Dec 04 '21 edited Dec 04 '21
Postgresql
Today was less bad than I expected when I first read the description, thankfully diagonals didn't count ...
part 1 github explain.dalibo.com
part 2 github explain.dalibo.com
4
u/frerich Dec 04 '21
Elixir
I'm trying to make a habit of using DocTests a lot. So far, it has worked out beautifully. It's so convenient to be able to just run
mix testall the time and have it verify everything (including example output and whatnot). :-)I hope the verbosity doesn't hurt readability of the code too much!
4
u/autra1 Dec 04 '21
SQL
Solutions are here: https://gitlab.com/autra/adventofcode/-/tree/master/year_2021/day4
It still fits in one screen ;-) Here is part2 https://imgur.com/a/TXF7xO7
4
u/The_VoltKnight Dec 04 '21
Haskell solution:
https://github.com/ezrasitorus/AdventOfCode2021/tree/main/Day4
4
u/[deleted] Dec 04 '21
Python
Part 2 took me some time to wrap my head around. I didn't realize that the same number could lead to multiple boards winning so I wasn't removing all the winning boards from my list of boards.
Otherwise, it was not too difficult.
For part 1, that was it. Part two, I had to collect the winners and then remove them from my list of boards.
4
u/nxrblJugger Dec 04 '21 edited Dec 04 '21
Nim, Julia, Python
Essentially, i replaced the called number on a bingo card with -1. when any row/column has 5 -1s in row, that card wins and i calculate the card total (by subtracting each called number from the max total ie. empty card state). As i go through each card, i look for the quickest and longest win times.
4
u/nilgoun Dec 04 '21
Rust
I made nearly a year pause from Rust and it's brutal how many things I've forgotten.
Wen't for an OOP solution that probably needs some optimization, but this is the first day I think is somewhat worth sharing.
Open for any criticism! :) (But please ignore my input parsing hack^^)
Day4 in Topaz' paste
4
u/baktix Dec 04 '21
Rust
I'm pretty happy with part 1, but in part 2 my code starts to get messy again. I think my solutions will require a little more forethought until I'm truly used to the ins and outs of the language and can structure my solutions around the Rust way of thinking more. The mix of pure and mutative functions I alternate between doesn't exactly feel fluent either.
Part 1
Part 2
4
u/Marcus316 Dec 04 '21
This is only going to get uglier as the days go on, but here's more bash command line solutions:
4
u/xSoliot Dec 04 '21
Python 3
4
u/dirtydave0221 Dec 04 '21
SnapLogic IIP
I've continued my using the "no code" project that I work on to attempt to solve the Advent of Code puzzles. I was able to do todays maybe easier than I had initially anticipated. I was worried that I'd have to script the input file into the bingo numbers to be called and the bingo boards, but it was actually quite a bit easier to do this processing (though if there was a variable amount of items between the input documents, I would've been in trouble, there's no way to preserve empty lines as a "document" using SnapLogic and we can't do scripting on a binary input, but we can convert it to a document specifically for further processing in the scripts.
The downside in this situation is that there's no way to break out of a "foreach" except for maybe an error being thrown and it routing to the error view of the foreach...something I still need to investigate a bit on my side.
While SnapLogic is "no code" we do have an expression language, which allows for things like filter, map, reduce of arrays, etc. so that's where much of the potentially complicated logic takes place in this case.
I've really enjoyed getting to better know the product that I work on, on a daily basis in order to potentially help our customers improve their experience, what a way to get around doing that.
4
u/schovanec Dec 04 '21
C#
https://github.com/schovanec/AdventOfCode/blob/master/2021/Day04/Program.cs
4
u/sonofdynamite Dec 04 '21
Language: Google sheets / Excel
I have been doing Advent in various languages but I like challenging non programmers to participate using spreadsheets. Here are days 1-4 in Google sheets. It took a little less than 2 hours to complete all 4
https://docs.google.com/spreadsheets/d/1in4iAUaRdCJJEAvNUoFZyU76aM-2sH8N1ltmzHFGEbc/edit?usp=drivesdk
4
u/Johnsenfr Dec 04 '21
My **R** solution ...this time in my opinion matrices are more intuitive to use than data.frames so more base **R** than using the tidyverse.
https://github.com/JohannesFriedrich/AdventOfCode2021/blob/master/Day4/Day4.md
4
u/[deleted] Dec 04 '21
[Julia]
end
4
u/oantolin Dec 04 '21 edited Dec 04 '21
In Perl we distinguish between splitting on the string
" "and splitting on the regex/ /, and I think that's beautiful. :POn the positive side, parsing is such a breeze in Perl!
That's the entire parsing code! Full solution.
4
u/danvk Dec 04 '21
Golang
https://github.com/danvk/aoc2021/blob/master/day4/day4.go
I'm using Advent of Code to learn Go this year, so I'd love tips on how to make this more idiomatic. Today felt a bit clunky.
4
u/[deleted] Dec 04 '21
A fairly terse python solution (21 lines): https://github.com/MagicLemma/advent-of-code-2021/blob/main/day4.py, I found that storing each board as a dict where the keys were the bingo numbers and the values were the positions in the board gives quite an efficient solution, since you can pop in O(1) and keep a separate dict of line counts so its just a single lookup to see if the board is solved
4
u/Vastutsav Dec 04 '21
Perl
Perl noob here. Please review my code. Please tell me things I can cut off, things I could have written smaller code for.
Thanks in advance.
Part 1 #!/usr/bin/perl
Part 2
4
u/baer89 Dec 04 '21
Python
More classes work. Got stuck for a bit on Part 2 because I was counting diagonals as wins. Borrowed a regex function to help parsing the boards as I got stuck on that a while too. For part 2 I just looked at the last printed output.
4
u/[deleted] Dec 04 '21 edited Dec 05 '21
Google Sheets
Part 1
A1; A2:A501 = input
In C1
In B1
This assumes the input in A2:A501 is 100 5x5 tables and the input in A1 doesn't have numbers with more than 2 digits.
Part 2: N/A
4
u/[deleted] Dec 04 '21 edited Dec 05 '21
python
part 1 & 2, put input in
input.txt:This prints every winning score in order of winning so that it solves part 1 and 2. The bit before the loop is just parsing the boards to an int matrix.
The meat of the solution can obviously be done in one line but it's readable like this at least.
4
u/curlymeatball38 Dec 04 '21 edited Dec 04 '21
Haskell
4
u/TheMightyPidgeon Dec 04 '21
Javascript
Solution for both parts
I replace each board number with the time it was drawn (for example: for input 7,4,9,5... 7 becomes 0, 4 becomes 1 and so on). Then I just need to find the maximum of each row and column -> smallest maximum shows the time when the board was completed. To solve the challenge we search for the boards with fastest and slowest completion time.
4
u/amlybon Dec 05 '21
Raku, without actually simulating the draw. If you substitute numbers on boards with the order they were called all you need to do is find max number in row/column, then min of those in a board, them min(part 1)/max (part 2) of THOSE across all boards.
4
u/rawlexander Dec 05 '21
R / Rstats: Code
I also stream the process. And make videos for the results. :)
4
u/soylentgreenistasty Dec 05 '21
Python solution using Numpy to keep a separate list of boards to check for row/column sums of 5. One of the first times my first submitted solution was right to both parts! Keen to see the more elegant solutions out there:
4
u/sotsoguk Dec 05 '21
Python 3
Nothing fancy today, had a shit day and just made it before day5 starts. Implemented a BingoBoard Class and when that worked part1 and part2 were easy.
Today is one of the days I always have at AoC where I'm just happy to get the stars but am not proud of my solution. It's just plain boring ... :)
https://github.com/sotsoguk/AdventOfCode2021/blob/6dc32bde011b2e3665575668c1499273fcd7f387/python/day04/day04.py
4
u/Dullstar Dec 05 '21
Python
Nearly forgot to post this!
Part 2 ran with minimal modifications to the original Part 1 code: all I really had to do was not to break after I found a winner, and addition of a single boolean field and if statement to skip checking for bingos on cards that already won.
4
u/quodponb Dec 05 '21
Python3
I started these a couple of days late, so I'm just posting my solutions to the older days for completeness!
I had a lot of fun with this one. After completing it the regular way, like this:
I decided I wanted to try combining the two into just one function, with one more boolean argument. The first step, I thought, was to rewrite them as recursive functions:
And that worked okay, and made it easier to write one big one to handle both cases:
4
u/odnoletkov Dec 05 '21
JQ
1
u/l_ugray Dec 04 '21 edited Dec 04 '21
Ruby. The full code is at https://github.com/lugray/advent_of_code/blob/main/2021/day04.rb, but I'm particularly prod of how this looks:
1
u/teije01 Dec 04 '21 edited Dec 04 '21
python numpy solution
1
u/t1ngel Dec 04 '21 edited Dec 05 '21
Java solution for Day 4
My highlight: The
BingoFieldimplementation:See on Github: https://github.com/feedm3/advent-of-code-2021/blob/main/src/main/java/me/dietenberger/Day4.java#L16-L100
1
u/wleftwich Dec 04 '21 edited Dec 04 '21
Python and numpy
1
u/tinyfrox Dec 04 '21 edited Dec 04 '21
Python
1
u/natron- Dec 04 '21 edited Dec 04 '21
Brute forced + PYTHON + reddit keeps messing up my formatting
base = BaseFactory.get_instance()
raw_input = base.get_raw_input(day=4) input = raw_input.split("\n")[0:-1]
board = [ "68 73 98 51 49", "82 56 87 64 8", "46 7 21 38 30", "66 5 86 97 74", "60 63 76 55 39", ]
class BingoBoard: def init(self, data): self.map = {} # map is a key with the value and tuple of position self.data = self._parse_data(data)
bingo_board = BingoBoard(["1 2 3", "4 5 6", "7 8 9"]) print(bingo_board.data) print(bingo_board.map) print(bingo_board.mark_number(4)) print(bingo_board.mark_number(5)) print(bingo_board.map) print(bingo_board._check_rows()) print(bingo_board.mark_number(9)) print(bingo_board._check_rows()) print(bingo_board._check_cols()) print(bingo_board.mark_number(2)) print(bingo_board.mark_number(8)) print(bingo_board.map) print(bingo_board._check_cols()) print(bingo_board.calculate_score(10)) print(bingo_board.mark_number(120))
print(input)
def solution(keep_scores=False): numbers = [int(num) for num in input.pop(0).split(",")] i = 0 input.pop(i) board = [] boards = [] while input: val = input.pop(0) if val == "": boards.append(BingoBoard(board)) board = [] else: board.append(val)
print(solution(keep_scores=True))
1
u/[deleted] Dec 04 '21
Python
1
u/tipx2 Dec 04 '21
# Python
this was the first day that was actually pretty tricky for me, took around 6 hours to crack :(
the solution is quite slow because of all the nested loops
1
u/Dalibane Dec 05 '21
[PYTHON, newbie could need help]
Hello everyone !
I've tried a solution for the part 1 in Python. My solution is based on 3 dimensional numpy arrays, with a binar 3rd dimension to check the different numbers for each grid.
My solution works well on the example given, but unfortunately it's not working on the true exercise. Dammit rabbit.
I'm quite frustrated here as I do not see what's wrong in this code (of course, "my code is perfect" the usual blablabla as I'm a pretty new amateur)
Here is the formated code. There are the puzzles input also, the true one and the example. If you find where I failed, I owe you one!
Thank you thank you !
The new one
1
u/berbeflo Dec 06 '21 edited Dec 07 '21
PHP: Solution for Part 2
(Yep, I overcomplicated it.)
1
u/theabbiee Dec 07 '21
1
u/pistacchio Dec 07 '21 edited Dec 08 '21
Typescript:
3
u/maeevick Dec 04 '21 edited Dec 04 '21
Day 4 with Naive Haskell (maybe more cryptic and inefficient than naive).
/!\ "ugly brute force" with pattern matching) ;-)
https://github.com/Maeevick/adventofcode2021/blob/main/src/D4.hs
3
u/Biggergig Dec 04 '21 edited Dec 04 '21
Python 66/37!
Best so far!
3
u/emilhvitfeldt Dec 04 '21
R (459/238)
My uncleaned mess, reading the boards in one by one took the longest time to code
3
u/gavindaphne Dec 04 '21
Python, 323/288. I had forgotten about AoC this year until today, so this was my first competitive evening.
3
u/Chitinid Dec 04 '21 edited Dec 04 '21
Python 3 class
EDIT: streamlined a bit
3
u/ritobanrc Dec 04 '21
Rust -- Happy with how my code turned out for today. I used
nalgebra'sMatrix5for storing the boards, which made checking for wins pretty easy.3
u/e36freak92 Dec 04 '21 edited Dec 04 '21
Awk
More efficient version
3
u/LiterallyJustTheCarp Dec 04 '21
Python 3 Rank 337/277
Solution (produces answer for both parts): paste
My big-brain moment was using zip(*rows) to check the columns, aside from that nothing impressive
3
u/goldenlion5648 Dec 04 '21 edited Dec 04 '21
[Python (547/386)] (https://github.com/Goldenlion5648/AdventOfCode2021/blob/master/3.py)
Video of me solving here: https://youtu.be/tFj122MmVCI
I struggled to parse the bingo cards so much. Wasn't until after the fact that I realized I could cut the parsing down to 1 line using
chunkedfrom themore-itertoolslibrary. (After removing line 1 of the input, also some help from mynumsfunction which finds all integers, similar to other peoplesintsfunction).3
u/GrossGrass Dec 04 '21
Python 478/382
Cleaned up my solution post-submission, tried to make it relatively readable. I didn't want to do any iterating for checking win conditions so I used collections.Counters to keep track of the number of times rows or columns got marked on the board.
3
u/frontpageminus Dec 04 '21 edited Dec 05 '21
Ruby (1663/1458)
paste
3
u/RigidityMC Dec 04 '21
TypeScript solution
https://github.com/Rigidity/AoC-2021/blob/main/src/day4.ts
3
u/vypxl Dec 04 '21
Python 3 724/655
Had much fun with numpy today.
I like
np.sum(board * np.abs(marks - 1)) * last_numto calculate the score very much.Also, like seemingly everyone, I spent minutes not knowing that diagonals do not count..
3
u/gzipgrep Dec 04 '21 edited Dec 06 '21
oK
Edit: A solution in fewer characters (source / inspiration):
Try it online!
3
u/[deleted] Dec 04 '21
Scala Solution
I feel like I tried too hard, but it's done so it'll be interesting to see what others came up with!
3
u/landimatte Dec 04 '21
Common Lisp
I am sure others would have solved this in less than 10 lines of code; well, this is definitely not one of those solutions!
Anyways, nothing crazy, and nothing optimized either; the only noteworthy thing here (and probably a bit overkill too), is the use of conditions to notify when a board wins, so in the runner I can easily store the score of the first winning board, as was as the last.
I will probably come back to this later, but this is it!
3
u/TallPeppermintMocha Dec 04 '21
Python 3 using numpy and sets https://github.com/moprak/aventofcode/blob/master/2021/4.py.
Notes:
3
u/rossmacarthur Dec 04 '21
🦑 Rust solution
3
u/compdog Dec 04 '21
Javascript [Part 1] [Part 2]
Another simple solution - just a whole bunch of loops. Oh, and about an hour of my life lost because I can't read. DiAgOnAls DoN't CoUnt
Pro tip: don't mutate an array that you're actively looping through. It ends... badly. And JS doesn't throw an exception like many other languages.
3
u/MichalMarsalek Dec 04 '21
Nim
I first did id in plain Nim but I wished I was doing it in Python's numpy. Than I remebered I heard about a similar project for Nim and so I'm learning arraymancer now:
3
u/mebeim Dec 04 '21 edited Dec 04 '21
1168/1037 - Python 3 solution - Walkthrough
Woah people are fast! Took me longer than expected, especially since the second part should have been pretty easy to implement after the first. Nice puzzle though!
3
u/InKahootz Dec 04 '21
C
I have a ton of existing methods for working with 2D arrays (
int[,]). So this one was quite easy.https://github.com/InKahootz/AdventOfCode/blob/master/csharp/Solutions/Year2021/Day04.cs
3
u/q3w3e3_ Dec 04 '21
Google Sheets
this one was tough as i cant iterate over anything to filter, and i didn't spot the "find the round each cell goes out on and minimize that" until id spent about an hour playing with recursion in sheets. Once i got to the implementable algorithm it was just a case of implementing it!
3
u/francescored94 Dec 04 '21
Nim Solution
3
u/zniperr Dec 04 '21 edited Dec 07 '21
python3, using sets to make crossing off numbers linear:
3
u/kupuguy Dec 04 '21
I seem to have done this a different way than most of the solutions I can see posted here.
The solutions here are taking each number in turn, marking all the boards and checking if any won.
I took all the numbers and played the entire game on each board in turn so I got a list of tuple of count of used numbers, score. Then print(min(results)[1]) is the answer to part 1 and print(max(results)[1]) the answer to part 2.
3
u/__Abigail__ Dec 04 '21
Perl
Initially, I got the right answer for the example, but the wrong answer of the input. Careful inspection of the input file revealed the game of bingo on submarines is played with a
0-- and I marked played numbers with0. Duh! Marking played numbers with-1fixed the issue.I created a class
BingoCardfor bingo card and added methodplay(to scratch off a number),bingo(return true if the card has bingo), andleft(counts the unplayed numbers).Then it's just a matter of playing numbers and scratching off the numbers, keeping track of the first and last winning cards.
See the program on GitHub
3
u/rukke Dec 04 '21 edited Dec 04 '21
JavaScript (edit, pasted old version)
3
u/kwenti Dec 04 '21
Python
My solution in Python, using a stateful approach that amounts to object-oriented programming. Keeps bingo checks quick. Unmarked sum could maybe have been delayed though...
Cheers,
Quentin
3
u/domm_plix Dec 04 '21
Perl
https://github.com/domm/advent_of_code/blob/main/2021/04_2.pl
I convert the horizontal rows and vertical cols into lines, so each bingo card has 10 lines. Each line is a Hash where key and value are the number (i.e.
42 => 42)because I thought that in part 2 we might need to do something with the checked values (with turned out to not be the case, ah, well..)When a number is drawn, go through all the boards and all the rows, mark the drawn number with a
X, and check if a line has 5Xs (my @checked = grep {/X/} values $line->%*;). If it has, we have a winner, so calc the value and report it.In theory part 2 only needed to remove the
exit, but as I had to remove bingo cards that have already one I had to convert my loop to use an iterator.3
u/Archeleons Dec 04 '21
C#
Converted the input list to a 3D array and used an index array to keep track of winning boards.
Github code
3
u/Mintopia_ Dec 04 '21
PHP
Seemingly the second PHP solution posted.
The extensive array functionality in the PHP standard library made this particularly easy today.
Day 4 Code
Grid Class
3
u/SadBunnyNL Dec 04 '21 edited Dec 04 '21
It's not pretty... But it works. AWK:
3
u/__Abigail__ Dec 04 '21
Python
In my Python solution, I didn't want to repeatedly scan rows and columns to see whether all entries in the row/column had been drawn. Instead, for each card, I keep a dictionary which maps numbers of the card to row/column positions, and for each row and column, I track how many numbers in that row/column haven't been drawn yet. I also track the sum of the remaining numbers. Now, if a ball is drawn, and on the card, I subtract 1 from the row and column counts: if either count reaches 0, we have a bingo. Then I update the sum of the remaining numbers.
Python implementation on GitHub
3
u/k0ns3rv Dec 04 '21
Rust
Solution on Github
I also streamed today, video recording here. I had two hiccups with dumb mistakes on the way, but got there in the end.
3
u/[deleted] Dec 04 '21
So much nesting
Python
3
u/auxym Dec 04 '21
Nim
https://github.com/auxym/AdventOfCode/blob/master/2021/day04.nim
3
u/EliteTK Dec 04 '21
Python 3.10
3
u/SpaceHonk Dec 04 '21
Swift
Haven't seen any Swift solutions so far this year, so here's my attempt: https://github.com/gereons/AoC2021/blob/main/Sources/AdventOfCode/puzzle4.swift
3
u/sebastiannielsen Dec 04 '21
Here is my <3 Perl <3 solution:
https://pastebin.com/8UZm9jNw
a LOT of nested loops!
3
u/tuvang Dec 04 '21
Julia
3
u/qSplit Dec 04 '21
Part 1 and 2 in Haskell. About 30 lines of code
3
u/kkirsche Dec 04 '21
Python, using a strategy design pattern. Pretty happy with this. The implementation and pytest unit tests are in one file.
https://github.com/kkirsche/AdventOfCode/blob/2021/adventofcode/test_day4.py
3
u/kmb5 Dec 04 '21
Python with OOP and lots of comments (both parts)
3
u/averageITenjoyer Dec 04 '21 edited Dec 04 '21
Bash
Haven't seen any in bash yet :D gist
3
u/hrunt Dec 04 '21
Python 3
Code
This uses a simple object to represent the board, and then plays the number on each board until it wins. Winner sets are used to track bingos. It took a little longer than I expected because I originally implemented diagonal bingos, too.
3
u/_Heziode Dec 04 '21
Ada
This is an Ada 2012 solution:
3
u/cylab Dec 04 '21 edited Dec 04 '21
Kotlin: https://github.com/cylab/advent-of-code-2021/blob/main/src/test/kotlin/day4/Day4.kt
didn't work out to do expression only style today :(Edit: With the help of solution r/adventofcode/comments/r8i1lq/comment/hn6n91j, this now looks much nicer:
3
u/rasqall Dec 04 '21
Haskell: https://github.com/v-olin/AOC-2021/blob/master/Day%204/sol.hs
Really putting my Haskell knowledge to its limits. I am trying to freshen up for a course next term in Haskell.
92 LOC and an execution time of 28ms.
3
u/michalopler Dec 04 '21
Python, both parts in a single tweet:
https://twitter.com/joppi07/status/1467167610001399817
3
u/Sandbucketman Dec 04 '21
PHP
Made an effort to try and trim the amount of code for today and came up with 27 lines which is one of my first attempts at writing concise code. I'm sure I missed an awesome easy solution somewhere but I'd still like to give a shoutout to php for having some great array functions.
3
u/bsoyka Dec 04 '21
Did some nice Python OOP! Split into three files, part 1, part 2, and shared classes.
3
u/__Abigail__ Dec 04 '21
Blog post: Giant Squid (Perl/Python)
3
u/TommiHPunkt Dec 04 '21
Matlab:
drawnis just a column vector of the drawn numbers,boardsis a 5x5x100 matrix of the boards.3
u/drbolle Dec 04 '21
My solution in Kotlin: https://github.com/ThomasBollmeier/advent-of-code-kotlin-2021/blob/3dea998faf7ba82fae684460c0281c1290dfd772/src/de/tbollmeier/aoc2021/day04/Day04.kt
3
u/[deleted] Dec 04 '21 edited Dec 04 '21
My solution in Kotlin, using only immutable data, functional constructs and tail recursion: https://github.com/Tohnmeister/advent-of-code-2021/blob/main/src/main/kotlin/nl/tonni/adventofcode2021/Day4.kt
I'm sure any functional programming and algorithm expert could do this with less lines of code.
3
u/inokichi Dec 04 '21
yet another nim solution paste - I need to get better at reusing code from part 1 in part 2...
3
u/isukali Dec 04 '21
Solution in C++ paste feel like it could have been done in a more efficient way but any feedback is appreciated :P
3
u/Mclarenf1905 Dec 04 '21
clojure
src
I was fairly happy with how todays turned out,
(not (empty? col))is frowned upon but I just find having anot-empty?reads better. I also find myself always reaching forreducebut for some reason i feel like thats not idiomaticclojurebut Im always happier withreduceoverloop/recurso meh(ns aoc-2021.days.04 (:require [aoc-2021.util :as util] [clojure.string :as str] [clojure.set]))
3
u/plant_magnet Dec 04 '21
R
https://github.com/ddavis3739/advent_of_code_2021/blob/main/code/day4.R
3
u/stevelosh Dec 04 '21
Common Lisp https://github.com/sjl/advent/blob/master/src/2021/days/day-04.lisp
This one ended up being more verbose than I would have liked, probably because I used 2d arrays of conses for the boards instead of nested lists.
3
u/Kulero0 Dec 04 '21
APL
Github
Apparently there's this thing called trains? They look fun to mess around with. Part two was also a nice surprise, just change 1 symbol.
3
u/[deleted] Dec 04 '21
My Clojure solution. I also have a little write-up for solving the problem.
3
u/systolicarray Dec 04 '21
Clojure, source and tests. Any feedback welcome!
3
u/Atila_d_hun Dec 04 '21
C++
GitHub Solution
Tried to minimize run time today. The
card_tstruct keeps track of its numbers and their position, so when a new number is called, it can be quickly looked up and crossed off without looping through the whole grid. Also used a<list>to efficiently remove cards once they were finished.3
u/oziomajnr Dec 04 '21
Kotlin
https://github.com/Oziomajnr/AdventOfCodeSolutions/blob/main/year_2021/day4/Part1And2