r/adventofcode • u/daggerdragon • Dec 25 '21
SOLUTION MEGATHREAD -đ- 2021 Day 25 Solutions -đ-
--- Day 25: Sea Cucumber ---
Post your code solution in this megathread.
- Include what language(s) your solution uses!
- Format your code appropriately! How do I format code?
- Here's a quick link to /u/topaz2078's
pasteif you need it for longer code blocks. - 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.
Message from the Moderators
Welcome to the last day of Advent of Code 2021! We hope you had fun this year and learned at least one new thing ;)
Keep an eye out for the community fun awards post: (link coming soon!)
-â - Introducing Your AoC 2021 "Adventure Time!" Adventurers (and Other Prizes) -â -
Thank you all for playing Advent of Code this year and on behalf of /u/topaz2078, /u/Aneurysm9, the beta-testers, and the rest of AoC Ops, we wish you a very Merry Christmas (or a very merry Saturday!) and a Happy New Year!
7
u/CCC_037 Dec 25 '21
Rockstar:
https://pastebin.com/8BuRiQMv
Brute force, no optimisations, 25 minutes.
Could doubtless be done faster, but hey, it works.
4
u/Naturage Dec 25 '21
R
Solution here. Not much to say on the code - fairly straightforward. Glad I managed to implement in-array replacement that doesn't take silly long to run.
That's my first 50 stars done, each on the day! I'd like to thank AoC organisers, this subreddit, ma, pa, the friend who reminded me of AoC on late evening of Dec 1, u/daggerdragon who upvoted my submissions when noone else would, and many more.
Merry Christmas everyone!
4
u/DFreiberg Dec 26 '21 edited Dec 26 '21
Mathematica, 1200 / 954
A nice, easy to day to round off the year...not that being easy stopped me from messing up almost every individual axis coordinate at least once. It's been a lot of fun, and now I look forward to getting some proper sleep for the first time in a month.
Part 1:
And one final poem for the year:
[POEM]: De Profundis
Into the depths we dove, into the sea,
Past lanternfish and amphipod and whale,
To find, beneath the cucumbers, the key
Which sank beneath the waves, over the rail.
Into the depths we delved, into the code,
Aligning beacons, counting all the paths,
Polymers, and dice (when we had slowed),
And helping out some snailfish with their maths.
Into the depths we ducked, behind the scenes
Where Eric and the mods concocted fun,
To keep us in good cheer till we'd the means
To surface once again and see the sun.
Clavis Davidica unlocks the way,
And from the depths, we come home Christmas Day.
2
u/its_spelled_iain Dec 25 '21
It's beautiful
11
u/relativistic-turtle Dec 25 '21
IntCode
Final puzzle! Yey! (but also sad ... :) )
Wow! 24 of 25 puzzles solved using IntCode.
(Puzzle 24 solved with pen and paper - but I did approach the problem with IntCode, implemented an interpreter, tried different strategies - before I saw how my input could be attacked by pen and paper).
My IntCode-adventure went much better than I dared to hope. I thought I would manage 3-4 puzzles at most - but I just couldn't stop!
Thanks AoC-team for another great round of puzzle! See you again next year!
9
u/jonathan_paulson Dec 25 '21 edited Dec 25 '21
43/34. 11th overall! Python. Video of me solving.
Much easier than the past few days. I had one bug, and wasted some time because I copy-pasted the example wrong. Merry Christmas all!
7
u/GrAndAG77 Dec 25 '21 edited Dec 25 '21
Python + Numpy
The last day was very simple. Using numpy.roll() and vector operations the solution fits into literally couple of lines without any circles over matrix elements.
7
u/Smylers Dec 26 '21
Vim keystrokes â well, hopefully. It's a manipulating-a-2D-picture sort of a puzzle, so it seems like it would be a decent fit for Vim. Usually (thank you and kudos to /u/1234abcdcba4321 for the list) I post a write-up of having solved the puzzle in Vim. This is more like a live stream: as I type this I haven't started, so what follows are all the keystrokes I try along the way, hopefully building up to a complete solution, but probably involving some mistakes and wrong turns. I'm hoping it may be easier to understand that simply being presented with a finished block of Vim keystrokes.
Load the (sample) input. The solution is the number of steps, so we're going to need a counter; add a
0at the top withO0â¨EscâŠ.We first want to simultaneously move the entire east-facing herd. To allow for wrapping, let's duplicate the leftmost column at the right:
jâ¨Ctrl+VâŠGy$p.At which point a move east is just swapping round a dot and a cucumber:
:%s/>\./.>/gâ¨EnterâŠ. Ah, then we need to transfer cucumbers from the duplicated rightmost column to the left. But only cucumbers that have just moved there, not any which were there already ... and we can't distinguish them.So
uthat, and this time use}to indicate a cucumber that's just swum east (maybe that's the shape they make when swimming?)::%s/>\./.}/gâ¨EnterâŠ. Now we can wrap that cucumber that's just swum off the right edge, with::%s/\v^.(.*}$)@=/}â¨EnterâŠ. We've now finished with that duplicate right column, so delete it:2G$â¨Ctrl+VâŠ}d.Next we need to move the south-facing herd. Let's do the duplicating the edge trick again. Handily the above command has left the cursor on line 2 (the top of the map, because there's that counter on line 1), so
YGpis all that's needed. Then the movement's going to involve matching something like/\vv(_.{10})\.. Yup, pressingâ¨EnterâŠon that, thenna few times seems to find thevs with spaces below them. So we need to calculate that10from the width of the input.Right at the beginning we could do
YP:s/./+1/gâ¨EnterâŠto get a string of+1s, then evaluate them withCâ¨Ctrl+RâŠ=â¨Ctrl+-âŠâ¨EnterâŠâ¨EscâŠ. The small delete register doesn't seem to being otherwise used, so we can delete that number withdiw, and it should be available in register-throughout. Oh, that leaves a blank line at the top, where the initial0counter needs to go. So we can combine saving the width and initializing the counter withciw0â¨EscâŠ.Back to the southward movements. We can now insert
10(or whatever the appropriate width is) into a pattern withâ¨Ctrl+RâŠ-. But that pattern matches the startingv, the.directly below it, and the entire row in-between: Vim's patterns are inherently horizontal. That's a problem because the skipped-over characters might also contain furthervs that need moving south, and a%s///command can't have overlapping matches. Let's try just matching the destination., so long as it follows avabove it. There's a brief diversion at this pint where I try to use\Kin the pattern, to cut off something that must match but not be part of the match, before I remember that that's Perl regexp syntax, not Vim's./\v(v_.{10})@<=\.seems to do what's required, again confirmed withâ¨EnterâŠandn.So we can âstretchâ moving south-facing sea cucumbers with
:%s/\v(v_.{â¨Ctrl+RâŠ-})@<=\./V/gâ¨EnterâŠâ usingVto indicate where a cucumber has just moved to.Oh, no we can't: a
vabove a column of.s (like the right column in the example) has turned all of the.s into a column ofVs, not just the top one. Ah, that's because the%in:%s///makes the substitution apply separately on each line, and by the time it's processing, say, line 6, it sees theVI've just inserted on line 5 â and I haveignorecaseandsmartcaseon by default, sovin the pattern is also matching the insertedVs. Quick fix: insert a\Cto make the pattern case-sensitive. (Obviously I don't retype the entire pattern here, I press:thenâ¨UpâŠand edit the previous command line, putting the\Cjust before the\v.)Quickly typing
uandâ¨CtrlâŠ+Ra few times to animate the substitution convinces me thatVs have now only appeared in places where they're supposed to. So now to get rid of eachvwhich has been moved â that is, everyvfollowed 11 characters later by aV, which is basically the same substitution but t'other way round::%s/\C\vv(_.{10}V)@=/./gâ¨EnterâŠ. Again a bit ofuandâ¨Ctrl+RâŠverifies this has done the right thing.We've now performed one step, albeit with the side effect of changing the shape of sea cucumbers that have moved. No we haven't: there's still wrapping the bottom to the top to consider. Let's move that bottom duplicate line adjacent to the top line we need to slide any
Vs into:Gdd{p. Hmmm, the first step of the example doesn't actually have aVin this line; let's introduce one now, just so I can check the substitution will work:lrV. Then move down (to the ârealâ top row) and put aVin any place where there's aVabove (that is, 10 characters earlier):j:s/\C\v(V_.{â¨Ctrl+RâŠ-})@<=./V/gâ¨EnterâŠ. (That worked, nowuit, to get rid of theVthat isn't actually supposed to be there in the sample input.) Then back up and delete the duplicate row (again):kdd. Now that's one step completed (with funny shapes).The above needs to be looped for each step. But in any step it might be only east-facing or south-facing sea cucumbers which move, and the
:s///command for the other herd could fail. To avoid causing an error and breaking out of the loop, each of:s///commands will need prefixing with:sil!. But at some point we do want the loop to end â when all the sea cucumbers have stopped moving. So we need a command which will initially succeed, but will fail the first time all the sea cucumbers have stopped moving. Since all the moved sea cucumbers have changed their shape, we can search for/\C[}V]â¨EnterâŠ, and that will succeed so long as at least one sea cucumber has moved.After which, to count a successful step, the counter can be increased with
{â¨Ctrl+AâŠ. No, wait: the}need turning into>andVintov, for the next iteration::sil!%s/}/>/gâ¨EnterâŠdoes the former, andvipguis less typing for the latter, since turning everything lower-case has the same effect.Try putting all that together, recording the commands for a single step into the
aregister, then looping with@a. Bah, it just creates a mess â and the maps are getting wider.Take the looping
@aout of the definition for@a, so I can run each step separately and watch what's happening. For edits like this I don't actually retype all the steps: instead, I make a blank line and paste the register's keystrokes into it:oâ¨EscâŠ"ap; then edit the keystrokes as required; and yank them into registera, overwriting the previous ones, and delete the line:0"aDdd.Now run a single
@a. Then realize that in the process of editing@aI overwrote the small delete register, meaning that no longer contains the required10. Type and delete10to restore that (while wondering whether it was a mistake to rely on the small delete register, and I should've just accepted a couple of extra keystrokes to do"zor whatever).Repeated presses of
@ashow it matches the input for the first few steps. It's at least close to working! After step 5, the example shows the state after 10 steps, so do5@ato jump to that one. It's still fine. Then10@afor step 20. Ah, that's very wrong.u. Run a single step. Why has step 11 suddenly started making the map wider, after the first 10 steps were absolutely fine?Apparently I've hit Reddit's comment length limit, so look for a reply below with the solution to this mystery, what happened next, and the complete finished keystrokes ...
6
u/4HbQ Dec 25 '21 edited Dec 25 '21
Python. Thank for the puzzles, Eric and team!
And thanks to all users here for their questions and feedback on my code!
5
u/[deleted] Dec 25 '21
C#: Solution
This one was fun. Code can probably be cleaned up, but it's fast enough and it works. Also, first time I finished the entire thing, I hope I can do it again next year :)
5
u/WilkoTom Dec 25 '21
Rust
Nice easy puzzle to finish with, just the odd edge case to deal with (where a line of sea cucumbers was split across the edge of the board and the one at the end moved).
Once again, thank you to /u/topaz2078 for the fantastic puzzles, and also to the awesome mod team, especially /u/daggerdragon, for keeping this community as special as it undoubtedly is.
Hope to see you all again next year!
5
u/pimpbot9000k Dec 25 '21
Python
GitHub
Pretty straightforward stuff. Sharing my code was just an excuse to post on this thread to say Merry Christmas to you all! This is my first AoC and managed to get 45/50 stars so I'm quite happy with myself.
5
u/tymscar Dec 25 '21
Today was way easier than the past week which is great, because I can relax a bit.
I have rushed the code, so its not the greatest, but its here, in Javascript, if you want to see!
4
u/satylogin Dec 25 '21
rust
4
u/SuperSmurfen Dec 25 '21 edited Dec 25 '21
Rust (491/411)
Link to full solution
Nice and easy last day. Got caught by a few off-by-one errors along the way but otherwise an ok day! Not sure if you can do this in-place. I copy the grid every iteration which is not super efficient. Takes about
150mson my machine.Thanks to everyone in this community and most of all Eric for another amazing year of AoC. Last year most of my days I landed in the top 3k. During the year I went back and completed years
2015,2016,2017which made me much more prepared for these types of problems. Finished this year with18/25in the top 1k which I am really proud of!Second-year in a row I go full in and go up at 5:50 in the morning for 25 days straight to do programming challenges before work. Nothing else would ever motivate me to do that. Aoc is truly special. Excited to sleep tomorrow, merry Christmas! đ
4
u/allergic2Luxembourg Dec 25 '21 edited Dec 25 '21
Python
Today was pretty simple -
numpy.rolldid all the work. So I took today as an opportunity to learn thecelluloidpackage to make animations out of matplotlib.Here's the main bit of work:
4
u/BenjaminGeiger Dec 25 '21
F#, 2084/1546
The code. Pretty much brute force.
I'm curious how many of the 1545 people who finished part 2 before I did also had the 300 prior stars.
4
u/ropecrawler Dec 25 '21
Rust https://github.com/ropewalker/advent_of_code_2021/blob/master/src/day25.rs
4
u/Diderikdm Dec 25 '21 edited Dec 25 '21
Python
And that's 350 stars!
Thank you Eric and the rest of the team for the amazing puzzles each year and taking the time to plan for and maintain such a wondurful event!
^ To view my entries for this year/other years, visit the link
4
u/wevrem Dec 25 '21
Clojure
Hooray! All done. All 50 stars. Merry Christmas everyone.
Thanks Eric and your support team. I purchased the AoC++ again this year as a thank you.
4
u/aurele Dec 25 '21
Fun to do in Rust with pathfinding's
Matrixrotations4
u/thulyadalas Dec 25 '21 edited Dec 26 '21
RUST
Sloppy end with 150 ms runtime. But my total runtime off AoC2021 is 650 ms, so I spent all my brainpower to optimize previous ones lol. Maybe will look at again later.
4
u/HesletQuillan Dec 25 '21
Fortran
https://github.com/sblionel/AOC2021-in-Fortran/blob/main/AOC25.f90
Pretty much the same solution as u/ZoDalek ended up with, after I corrected some blunders. 25ms.
4
u/chicagocode Dec 25 '21
Kotlin -> [Blog/Commentary] - [Code] - [All 2021 Solutions]
That was a nice end to another enjoyable year of Advent of Code. Nothing much to say about this one, except I'm glad
buildMapandlastIndexare things in Kotlin.Thanks to Eric Wastl for another great year, and thanks to anybody who messaged me about my blog posts, I truly appreciate it.
4
u/semicolonator Dec 27 '21
Python, 28 lines
Using
scipy.ndimage.generic_filter()two times (east and then west movers).1
u/flwyd Dec 25 '21
Raku
I did an implementation on my phone (while drunk and in a food coma after Christmas dinner) that almost workedâŚÂ if the problem hadn't said to move all of the east cucumbers before all of the south cucumbers. Got home and did a new implementation with a pair of sets that didn't work, so I gave up and settled down for a long winter's nap. With the clarity of early afternoon sun I realized that I was performing modulus by the maximum coordinate, which apparently doesn't lead to a stable solution :-)
Only got one star because I gave up on day 23 (my manually-found solution to part 1 (also found by code) was rejected as too high, a buggy solution 20 lower than that was marked as too low, the answer is not 10 or 1 off the manual solution, and I don't feel like taking more stabs in the dark. Day 24 was in no way a fun way to spend Christmas Eve: what would be a reasonable solution if the data weren't so sparse is totally useless, but the lack of a real example and the obfuscated opcode made that sparsity surprising. I'll decide later this week if I care.
6
u/hugh_tc Dec 25 '21
Python 3, 19/14. 66th with 959 points overall. (Was 62nd last year; so close!)
Part 1.
Thanks again for the fantastic puzzles, Eric. Already looking forward to next year!
3
u/seligman99 Dec 25 '21
Python, 101 / 89
Now I need to find some other puzzle to solve every day.
github
3
u/AP2008 Dec 25 '21
Python 542/510 paste
First year of AoC (for me). It was a lot of fun. The best thing after the puzzles was the community. Thanks to Eric, the beta testers and the mods. Did I mention it has been a lot of fun ?
3
u/elementalennui Dec 25 '21
Not worth posting my places, but just wanted to thank the community and Eric for such a fun way to spend December! This was my first AOC and I loved it. Here is my solution to the last puzzle - very inefficient and naĂŻve, but it gets the job done.
Thanks everyone and Happy Holidays!
Python:
Paste
3
u/RoughMedicine Dec 25 '21
Rust.
Today is a good example of how people (i.e. me) can take half an hour on a very easy puzzle. I can't believe how easy this one is after the last couple of days.
3
u/phil_g Dec 25 '21
My solution in Common Lisp.
I don't really go for the leaderboard, but I'm happy with my rank of 1271 for part two today.
For part one, I went with a lot of set manipulation. Each herd is a set of points. To do a move, I add one to the right axis of each point in the set, then do a set difference with the existing herds. Anything left is a move into an empty space.
I just copied, pasted, and modified code for the east and south herds. It could probably be cleaner, but that's future me's problem. For the moment, I just wanted to finish.
The code is also slow. It takes 15 seconds to get an answer. Future me might want to optimize that, but it's good enough for the moment.
3
u/jaybosamiya Dec 25 '21
APL
3
u/Biggergig Dec 25 '21
C++ 100ms :(
Didn't see any c++ so might as well put my code
3
u/autid Dec 25 '21
FORTRAN
Nothing fancy, just some nested loops. Merry Christmas everyone!
3
u/JaegerMa Dec 25 '21
ABAP
Github
3
u/hqli Dec 25 '21
Typescript
brute force simulation and checked when the maps were equal. Nice relaxing end to this years coding challenge.
Merry Christmas and happy new year!
3
u/M1ngXU Dec 25 '21
RUST
https://pastebin.com/hQSV7uZw
3
u/vulpine-linguist Dec 25 '21
C
42 lines of C
3
u/surgi-o7 Dec 25 '21 edited Dec 25 '21
ES6
code here, nothing special
Big applause and thanks to Eric for all the tremendous effort - putting together such set of great, innovative, and sometimes really challenging puzzles must have been extremely time and energy consuming.
Merry Christmas everyone (and keep up the memes)!
3
u/maneatingape Dec 25 '21
Scala 3 solution
I had an absolute blast solving the challenges, especially Day 4, Day 8 and Day 22.
See you all next year!
3
u/MarcoServetto Dec 25 '21
I'm solving the advent of code in 42 The main selling point of 42 is that it enforces modular security, that is not very relevant for the advent of code. Solution for Day 25 If you want to hear more about 42, the best way is to subscribe to the You tube channel
Also, fell free to contact me if you to know more about the language.
3
u/mebeim Dec 25 '21
1540/1201 - Python 3 solution - Walkthrough
Pretty bad day to be honest, lots of stupid errors that made me waste a ton of time. In any case, thankfully this was an easy problem for Christmas day. Merry Christmas everyone!
3
u/[deleted] Dec 25 '21
Haskell, thanks for making AOC Eric, like always it was a lot of fun
https://gist.github.com/daedalus-0/6ca8225050852b36ad5bb3d78b210aa1
3
u/ahmdshbz Dec 25 '21
Q:
3
u/LEPT0N Dec 25 '21
C#: GitHub Commit
My first time completing Advent of Code! Can't wait for next year.
3
u/DeeBoFour20 Dec 25 '21
C
https://gist.github.com/weirddan455/34554390fec92aadbd37a86ef8022d0d
Pretty straight forward problem. Nice to have an easier one after the last several days. I maintain 2 copies of the grid. Read from one to check what the moves should be and write to the second one. Swap the pointers, do a memcpy and repeat.
Maybe not the most efficient way but the grids are small enough. Takes about 50ms on my computer.
3
u/zebalu Dec 25 '21
Java (nothing special, simple implementation of the rules, I have only posted to fit for the rules here)
Merry Christmas to you all!
This year was very hard for me. Not the beginning, but the last week. Yesterday took me half a day, and my current solution is closer to a brute force, than to a valid solution. (I was really lost in my on idea...)
Thank you all for the great talks, and codes, I have learned many things this year again. Thanks for the puzzles, and see you next year!
Merry Christmas and Happy New Year!
3
u/r_so9 Dec 25 '21 edited Dec 25 '21
C
First time ever coding on my phone. Not cleaned up at all!
"IDE" is C# Shell on Android
paste
3
u/xelf Dec 25 '21
Python
Both directions handled with list comprehensions:
full code:
3
u/p_tseng Dec 25 '21 edited Dec 25 '21
Ruby
My original implementation took 1.7 seconds to run my input. That was unacceptable. Got it down to around 200 ms by representing both entire herds as a single huge number each and using bit shifts to check+move the entire herd at once. Much better.
https://github.com/petertseng/adventofcode-rb-2021/blob/master/25_sea_cucumber.rb
Core:
Haskell code for the same (https://github.com/petertseng/adventofcode-hs-2021/blob/master/bin/25_sea_cucumber.hs) runs in about 70 ms.
I'd like to thank Eric and the team for a great year. Hope to see you again next year.
3
u/thibaultj Dec 25 '21
Python3 + Numpy
Using numpy in a naive and straightforward way did the trick.
3
u/azzal07 Dec 25 '21
Postscript, PS. Just a simple iteration following the rules, with a basic visualisation.
Awk, I store the empties as either
0(zero) or".", thus0 ~ grid[x, y]can be used to test for empty cell without having to ever write out".".3
u/LinAGKar Dec 25 '21
Mine in Rust: https://github.com/LinAGKar/advent-of-code-2021-rust/tree/main/day25/src
3
u/nutki2 Dec 25 '21
C
Runs in 2ms (when compiled with clang) or about 5 regions per CPU cycle. Optimized to run all operations on a bit packed representation.
3
u/clumsveed Dec 25 '21
Java Solution
Day 25 Solution
All 25 Solutions - repl.it
Thanks to u/topaz2078 and everybody else in this community for another great year! Happy holidays and happy new year!
3
u/TiagoPaolini Dec 25 '21
Python 3 with NumPy
This is the kind of problem that NumPy makes much easier to solve. NumPy can make easily batch operations on arrays, like moving elements around, testing everything against a condition, and addressing the elements by a mask.
Here is what I did. In a 2D array for the positions, I used 0 to represent "empty", 1 for "east-facing", and 2 for "south-facing". For each step:
AND NOTstarting positions array2to6for the south movementTrueon their destination arrays)1I considered this puzzle easy, when compared to the previous couple of days, but that can change from person to person. Since I was already familiar with NumPy, that helped me a lot. Also the code took 150 milliseconds to finish on my (old) computer.
Code: Solution for Day 25 of 2021
Merry Christmas!
3
u/dcbriccetti Dec 25 '21
Python3. Iâm proud of the color highlighting I did to show, separately, the horizontal movements and the vertical movements of each step and generally, the code quality.
https://www.youtube.com/watch?v=DIcbsg51Y1Y&list=PLBB4Hl2loxIfmiHdR5yL0I9Jh1MQi9dC5
https://github.com/dcbriccetti/advent-of-code-2021-python/blob/main/src/day25.py
3
u/RiemannIntegirl Dec 26 '21
Python 3.9
Just for fun, you can display your current state:
3
u/jf928ngl60g1 Dec 26 '21 edited Dec 26 '21
TypeScript
https://github.com/adrbin/aoc-typescript/blob/main/2021/25/puzzle.ts
Simple solution. Still have 6 puzzles left.
Meanwhile, thanks for fun to everyone!
Merry Christmas!
3
u/rukke Dec 26 '21
JavaScript
Nothing spectacular, each iteration just loops over the map twice, one time each for the east and south bound sea cucumbers, writing updates to a copy which then replaces the original map. About ~200ms runtime. Anyway, it got the job done and my 350:th star star was saved.
Thanks a lot Eric for AoC 2021, can't wait until next year!
gist
3
u/zniperr Dec 27 '21 edited Jan 02 '22
python3:
3
u/ai_prof Dec 28 '21
Python 3 using replace() - 22 lines/fast/simple/commented.
Fiddled about for a while until I realised that
'..>v.>>.' -> '..>v.>.>'just needs a.replace('>.','.>')and a bit of tinkering to deal with ocean currents and transposing the map. The code is here - it's mighty quick and all over in 22 lines (with comments!).4
u/Error401 Dec 25 '21 edited Dec 25 '21
24/18 in Python: https://pastebin.com/jqhcbJiU
My only goal this year was get on global leaderboard. I fell off yesterday after some weak days 21-24, but today's placement clutched me back on at rank 93. Can't wait for next year!
2
u/prendradjaja Dec 25 '21 edited Dec 25 '21
55/64, Python 3.
Merry Christmas!!
paste
2
u/Sourish17 Dec 25 '21
Python 3 61/51
Epic way to end for me!!!!!
link
and thanks for anyone who voted for me in the adventure thing ('m 8th) :)
MERRY XMAS!!!!!!!!
2
u/DARNOC_tag Dec 25 '21 edited Dec 25 '21
Rust 111/111
Code on github. My best leaderboard showing of the year. Just a basic automaton-type simulator on a fixed board with wraparound, no tricks. Runtime is about
23 ms.Big thanks to Eric et al for another fun year. And thanks to the rest of you nerds for chatting about these with me.
2
u/uncountablyInfinit Dec 25 '21
Python, 144/128
First year I've done AoC and it's been so much fun, thanks to Eric and everyone else on the team for the awesome puzzles!
2
u/AP2008 Dec 25 '21
Python 542/510 paste
First year of AoC (for me). It was a lot of fun. The best thing after the puzzles was the community. Thanks to Eric, the beta testers and the mods. Did I mention it has been a lot of fun ?
2
u/dtinth Dec 25 '21
Ruby, 46 / 48 part 1, part 2 (1366 points total)
That was fun, and it is the first year I got all 50 stars! Previous years I gave up when there is a very very hard puzzle. Enjoyed it very much, thanks Eric for running this!
2
u/timrprobocom Dec 25 '21
Python 3 528/442
This was a case where translating the map to a set of coordinates (well, 2 sets of coordinates) seemed to make things easier. I might try it with a text grid just to see how that looks.
github
2
u/oxyphilat Dec 25 '21
Python 3, 610/512, paste
could have done p2 faster but I had to read the description. back to max/350 stars, see you next year!
2
u/morgoth1145 Dec 25 '21
Python 3 278/232
This was so much nicer than yesterday's problem (for me at least). But I goofed bad by failing to actually check
movedto break out of my loop! I lost somewhere between 4 and 8 minutes debugging that on the example. Once fixed it ran so well on my real input. Yay one last dumb bug.2
u/Chitinid Dec 25 '21
Python 3 252/212
Was a good day for set comprehensions
2
u/Biggergig Dec 25 '21
Python
ugly code but hey it works lol, spent too long on stupid mistakes and a lack of reading the question as tradition :P
2
u/hrunt Dec 25 '21
Python 3
Code
I happened to be up at midnight fulfilling my Santa duties, so why not knock out some code so that I can be fully present for Christmas morning?
Thank you Eric for putting together another wonderful year!
2
u/pantaryl Dec 25 '21
Python, didn't place anywhere significant enough.
Thank you Eric for the fantastic year. See you all again this time next year!
Solution
2
u/TheZigerionScammer Dec 25 '21 edited Dec 25 '21
Python 1460
Not as fast as some of the other that are posting here at this time but this was a simple problem so I still got it done pretty quickly. Unfortunately a problem being simpler doesn't make it easier to get a high rank. The only real thing of note is that I considered making my grid of cucumbers into a defaultdict (and have some commented out code in my paste link referring to it) but decided against it as list manipulation is what I know and I didn't want to waste too much time coding it when I didn't understand it as well to get a faster time. My program runs in about 11 seconds, I can probably optimize it by making it run off of a dictionary instead like some of the others are doing.
Since there's only a part one, how are the rest of you posting part 2 scores? Is it based on the time it took you to get all 49 other stars? If that's the case I still have to do part 15.
Paste
2
u/DrSkookumChoocher Dec 25 '21
Deno TypeScript
380. Fun year! I still need to do day 24 to save Santa though :( This solution has some fun optimizations which people may or may not like. I thought it was cool how you could separate out the east heard vs the south herd.
https://github.com/N8Brooks/deno_aoc/blob/main/year_2021/day_25.ts
2
u/aimor_ Dec 25 '21
MATLAB
Nice easy puzzle, though I think I hit every snag by trying to be too 'fancy' (lazy) with indices to deal with the wraparound. That's 350 stars total now :)
Merry Christmas everyone!
2
u/schovanec Dec 25 '21
Solution in C#: GitHub
2
u/LtHummus Dec 25 '21
Go
Normally, I've been doing these things in Scala, but in the spirit of Christmas I decided to mix it up.
Some Code Lives Here
2
u/avsufirwbcskajxb Dec 25 '21 edited Dec 25 '21
Python / numpy: paste (400 ms)
2
u/aardvark1231 Dec 25 '21
My C# Solution
This was a fun one and an enjoyable end to Advent 2021! Run a bit slow, but I can always optimize later. Got it done with plenty of time left in my evening. :)
2
u/seba_dos1 Dec 25 '21
Python 3 (no imports, 759/633)
Ho, ho, ho! 404 characters, but I didn't try too hard :)
2
u/e36freak92 Dec 25 '21 edited Dec 25 '21
C
Super simple brute force
2
u/Jozkings Dec 25 '21
Python 3.7
I divided each step into substeps of moving to the right and to the south. After each substep, I also clear all positions which were occupied by sea cucumbers before moving. It is certainly not necessary to do it this complicated way, but at least it's more clear to me what's happening.
Merry Christmas!
2
u/michaelgallagher Dec 25 '21
Python
Merry Christmas!
Had a lot of fun this year, the last week (besides today) was especially challenging!
Thank you Eric for another great year of puzzles!
2
u/GrossGrass Dec 25 '21
Python, 68/62
First time on the global leaderboard for this year! I guess no better day than the last day.
Developing my grid-parsing library over this year's problems definitely paid off dividends for this problem, ended up being super quick and luckily got my implementation right on the first try.
Also I always get confused by part 2 and forget that you can just click the link to get the final star...I had to read it twice to double-check that I wasn't missing anything.
2
u/gyorokpeter Dec 25 '21
Q:
2
u/yieldtoben Dec 25 '21
PHP 8.1.1 paste
Execution time: 1.7 seconds
MacBook Pro (16-inch, 2019)
Processor 2.3 GHz 8-Core Intel Core i9
Memory 16 GB 2667 MHz DDR4
2
u/itsnotxhad Dec 25 '21
C#/Csharp
Nothing particularly clever here, just a straightforward simulation and count the loops
https://www.toptal.com/developers/hastebin/elogogemuj.csharp
2
u/s3aker Dec 25 '21
Raku solution
2
u/Toanuvo Dec 25 '21
j solution
https://github.com/Toanuvo/Advent-of-code-2021/blob/main/J/day25.ijs
2
u/PendragonDaGreat Dec 25 '21
C#
Nothing fancy.
Thanks again for all the great puzzles.
âď¸đHappy Advent of Codeđâď¸
2
u/sim642 Dec 25 '21
My Scala solution.
I started out with just operating on the 2D grid directly, but implementing the steps would've been kind of annoying to do neatly, so I switched to sets of east- and south-moving sea cucumbers.
2
u/mapleoctopus621 Dec 25 '21
Python
The grid isn't that sparse so I didn't see an advantage of using sets over 2D arrays. I managed to update everything without copying the entire grid.
2
u/tabidots Dec 25 '21
Clojure (GitHub).
Nothing too special, although this is the first time I tried a new way of doing Game of Life stuff in Clojureârather than use a grid, just use sets for each type of cucumber.
I made the mistake of also keeping track of the empty spaces, though, which meant that a single step on the full puzzle took about 12 seconds, and the program never finished đ Took me a while to realize that that was the bottleneck.
Feels good to save Christmas! Thanks, Eric! (Although the lack of a number theory puzzle this year was sorely felt đ)
2
u/marshalofthemark Dec 25 '21 edited Dec 25 '21
Ruby
Like last year, Day 25 was pretty simple and a brute force without optimizations will do the job (my code found the solution in 11 seconds)
Paste
2
u/Cataloons Dec 25 '21
Excel
https://github.com/questionably-assured/Advent_Of_Code_2021/blob/main/Day25.xlsm
I guess this would have made for a better post under visualizations, but for anyone else who wanted to watch their sea cucumbers migrate across the ocean floor, you can simply paste your input into the Data tab and then click the Reset and "Move Cucumbers Until Stuck" buttons on the Cucumber Mover tab.
Ultimately, it was a fairly simple solve that just involved separating the two movesets into a series of nested if statements - the eastward one references my input table and then the southward one references the eastward table. I have a movement checker that compares the input table against the eastward and southward tables. Then I just made a macro button that copies/pastes the southward table into my input table space until the movement checkers both equal 0.
2
u/artesea Dec 25 '21
PHP
https://github.com/artesea/advent-of-code/blob/main/2021/25a.php
Brute force solving in under 0.5s.
With it being 8am here right now I've had to wait for the kids to open their presents. Everything done on my mobile. Editor vi, Terminal JuiceSSH, Keyboard SwiftKey (with symbols showing on keyboard, numbers and cursors).
2
u/Melocactus283 Dec 25 '21
R / Rlang
Merry Christmas!
2
u/VictorTennekes Dec 25 '21
Nim
Nice to end it off with an easy one on Christmas morning. Thanks for another AOC Eric!
2
u/thegreekezio Dec 25 '21 edited Dec 25 '21
Python
Not fast, but it does the job.
Thanks for the amazing puzzles!
Also thanks to all of you who have shared solutions. It's a great way to keep learning.
See you next year!
2
u/FordyO_o Dec 25 '21
PHP
Ignore the input parsing , I was a bit groggy so I kept adding array filters til it worked.
Big thank you to topaz and everyone else who makes AOC happen, I've really enjoyed this year, it's nice to have problems to solve which are a bit outside my comfort zone and force me to learn new things.
and I hope you all have a lovely Christmas.
2
u/BeamMeUpBiscotti Dec 25 '21
ReScript
code
This solution uses an immutable map to represent state, which means that it's pretty slow (maybe 15-20s) since it rebuilds the entire map with tens of thousands of elkements twice per step. Probably more suited for sparse inputs.
Had I done this again I probably would have used a 2d array, which would have made printing a bit easier too.
3
u/enelen Dec 25 '21
R / Rlang
vectorised solution
2
u/diddle-dingus Dec 25 '21
[Python]
Some numpy
rolling and index twiddling2
u/abeyeler Dec 25 '21
Python
I've I've implemented both a set-based and numpy-based solution. The latter is more than 10x faster (even without discounting a rather low world loading method).
Part 1 (numpy) solution: 353 (execution time: 43.79ms)
The code.
2
u/Zeld1 Dec 25 '21
R / Rlang
Modify 1D indices to find the correct destination of each symbol in one operation, with modulo to wrap around the bottom / side
code
2
u/Laugarhraun Dec 25 '21
Common Lisp
https://github.com/brunal/advent-of-code-2021/blob/main/25.lisp
So I cannot get to part2 until I solve days 23 and 24? :-/
2
u/Radiadorineitor Dec 25 '21
Lua: https://pastebin.com/wtdkvbqc
2
u/tuvang Dec 25 '21
Julia
22ms runtime. paste
Nice end to a nice journey :)
2
u/mykdavies Dec 25 '21 edited Jun 29 '23
!> hpwpeok
API FAILURE
2
u/Ily3s_ Dec 25 '21
C++
https://github.com/Ily3s/AdventOfCode2021/blob/master/Day25/Day25.cpp
2
u/HeyHouBenjo Dec 25 '21
Python
Numpy, perfect place for np.roll
2
u/RudeGuy2000 Dec 25 '21
scheme (racket)
first time after a long while that my parsing function is the longest one.
2
u/aoc-fan Dec 25 '21
TypeScript, relatively easy day, proud owner of all 350 stars now, happy holidays everyone...
2
u/veydar_ Dec 25 '21 edited Dec 25 '21
Nothing noteworthy about this. I actually like that this one was fairly predictable and straight forward.
Lua
=============================================================================== Language Files Lines Code Comments Blanks =============================================================================== Lua 1 87 77 0 10
2
u/martino_vik Dec 25 '21 edited Dec 25 '21
Python 3
Day 25 Solution:
I'm very glad that the last day of AoC was doable without external help for me - in 3:29:16 on rank 4282 which is very close to my personal best - except that I wasn't even trying this time :D The strategy I applied was: Move cucumbers to the right, flip rows and columns, repeat the same process just with "v" instead of ">". Flip columns back. Check if field has changed after moving.
While I was debugging following issues came up:
Update: Uploaded a refactored and stylechecked version that runs in about 4s.
2
u/Justinius1981 Dec 25 '21 edited Dec 25 '21
C# Day 25 Github Paste
Straightforward implementation.
Move east, then move south. Repeat.
Has code to generate PGM frames for the visualization I posted.
2
u/qaraq Dec 25 '21 edited Dec 25 '21
Go
Pretty straightforward. I'm sure I could optimize it; 3200ms is not great. I loop over the map three times, once for each herd and once to set all the 'next' values to 'current'. I suppose that third iteration isn't necessary if instead I kept a whole second copy of the board, but meh whatever.
I did save one loop copying next to current each step by having the south-movers look ahead to see if an east-mover had moved in front of them.
It might have been a bit faster to store only the cucumbers and not the whole grid, but I figured I'd still have to loop over them in coordinate order so they all moved in proper coordination; an unordered map wouldn't guarantee that, and sorting the keys would just add more expense. So in the end I'd still be iterating row*col three times per step.
(In fact,
rangeover a map in Go is explicitly random.)Today's other Go lesson is that you can't modify a struct addressed through a map- i.e.
theMap[theKey].name="Fred"doesn't work. You need instead to do this:Pesky but not too hard to work around.
github
2
u/rabuf Dec 25 '21
Common Lisp
It works, rather slow though with the double scanning and creation of 2 new hash tables for the eastward and southward cucumber marches. I was traveling on the 23rd and spending time with family yesterday, everyone is napping now so I was able to knock out today's. Hopefully I'll get to 23 and 24 next week.
2
u/minichado Dec 25 '21
Excel w/ VBA (runtime was 276seconds)
Excel file here
Simple code today, fun problem! I was forgetting to check the new east positions before doing the south moves.. after fixing that silly bit, I got to watch the animation run on my screen for about 5 minutes. excellent way to end the year! 36 star is my best finish so far, with this being the most I've gotten doen the day of, but I expect I can another 2-4 stars in the next few days.
2
u/RookBe Dec 25 '21
rust Per step, this makes a list of all cucumbers that can move first, then mutates those in the overall map.
2
u/aoc-fan Dec 25 '21
F#, Simple array based mutation, kept a track of sea Cucumbers, under 80 lines of code, mostly one liners
2
u/codefrommars Dec 25 '21
C++
Short and simple simulation.
Thanks /u/topaz2078 for another cool AoC :)
2
u/schoelle Dec 25 '21
V
(See https://vlang.io/)
My solution:
https://github.com/schoelle/adventofcode2021/tree/main/25-v
First time I use this language. Simple double-buffer movement steps.
2
u/p88h Dec 26 '21
Elixir, slow.
Plus Python visualisation
2
u/[deleted] Dec 26 '21
Python Numpy
Thanks for the challenge! I couldn't get past day 15 but came back for the finale.
I commented the code to be as clear as possible
My solution
2
u/oantolin Dec 26 '21 edited Dec 26 '21
I didn't try anything clever today, just simulated all the steps, which takes about 2 seconds. I decided to mutate the grid in-place, which requires being careful with the wrap around: you need to make sure that when you test whether the right/bottom edge has moveable sea cucumber, you use the values in the left/top edge from the previous step, not the current one. But other than that, it's straightforward. Here's a Common Lisp program.
Now I have to go back and do day 23 which I didn't have time for earlier.
EDIT: Day 23 is done, so I'm finished!
2
u/SplineGopher Dec 26 '21
GOLANG
https://github.com/Torakushi/adventofcode/tree/master/day25
Very simple, i parallelise the code, so I use two differents maps (one per bunch) so that I havn't concurrent problems :)
Happy christmas !
2
u/sortaquasipseudo Dec 26 '21 edited Dec 27 '21
Rust
Congrats everyone, we've finally made it! As with other years, Advent of Code 2021 closes out with a layup of a problem on Day 25--this was a straightforward simulation of cellular automata, like an easier Conway's Life. The subtle part of this type of problem is separating the state you're using for logic, and the state you are creating for the next iteration. It's easy to conflate the two.
Check out my playlist of solutions to other problems.
2
u/mgoszcz2 Dec 26 '21
Rust
It's a bit ugly but I manage to do each step in-place. Takes around 20ms on my machine.
https://github.com/mgoszcz2/adventofcode/blob/master/2021/solutions/src/day25.rs
2
u/mathsaey Dec 26 '21
Elixir
https://github.com/mathsaey/adventofcode/blob/master/lib/2021/25.ex
Nothing too fancy here. I'm sure this can be done a bit prettier, but I'm too tired for that right now. Quickly did day 25 since I figured it would be easy. Just need to find some time to do day 24 and I've collected all my stars this year :).
2
u/spyr01d Dec 27 '21 edited Dec 27 '21
Kotlin
https://github.com/spyroid/Advent-of-Code-2021/blob/master/src/day25/Day25-Faster.kt
âď¸ Re-writed my super slow solution (30s) to something more faster(225ms) with color output.
2
u/jkpr23 Dec 27 '21 edited Dec 27 '21
Kotlin
Idiomatic Kotlin using sequences. We don't know how many times the sea cucumbers need to march, so a sequence is perfect to model this.
Created the two herds (east and south) as sets of cucumbers. For each set, take the members that can advance, remove them from the set, and add in the new locations after moving the correct direction.
Runs in less than 1 second.
2
u/RewrittenCodeA Dec 27 '21
Elixir
The typical run-of-the-mill "iterate until it does not change" problem. Elixir
Streammodule shines at it, as one can lazily manipulate streams generated by iterating a function.Using just two
MapSetdata structures to track the positions makes the movement check relatively fast.Interestingly, the size of the input is not 100x100 or some other nice value. I have my size hardcoded, but of course it can be computed form the input.
https://github.com/brainch-dev/aoc.ex/blob/main/2021/25.exs
2
u/SwampThingTom Dec 27 '21
Python
I did this Christmas morning but am just getting around to pushing it to GitHub and posting here. It was a nice, simple puzzle for finishing off another year.
Takes about 1,500 ms so could be faster. Not going to bother optimizing it though. :-)
2
u/vss2sn Dec 27 '21
Solution in C++:
Part 1
As always, the file is a self-contained solution
2
u/RibozymeR Dec 28 '21
Factor
2
u/chkas Dec 28 '21
easylang
Solution
Finally done. 22, 23 and 24 have kept me busy for a while this year.
2
u/alykzandr Dec 28 '21
Python 3
Nothing exotic at all and overall a pretty naive approach here. I'm sure there are more compact or efficient approaches but good enough for Day 25.
https://pastebin.com/NFWHsCKx
3
u/roboputin Dec 25 '21
Python, short and sweet
2
u/Kermitnirmit Dec 25 '21
python 453
i got really tripped up by using my
>andvcucumber lists for checking if there's one at that location already. It worked perfectly on the small input but the big input got really cucumbersome and was taking like 2-3 seconds per iteration. Turned them into sets and it flew by. Probably wasted like 4-5 minutes on wondering why it wasn't working...Thanks for a super fun year (even though days 19-24 were really making me question how much i wanted to solve these problems)!
1
u/masterinthecage Dec 29 '21
15 line solution in Python 3 using string manipulation, GitHub
1
u/e_blake Dec 30 '21
m4 day25.m4
Depends on my framework common.m4. Took about 19s on my input, although the time to settle is definitely input-dependent. I loved watching rounds speed up with
-Dverbose=1as fewer points of interest had to be visited each round. The code to iterate once things are parsed is fairly short, and I got it working on the first try - now I just have to finish days 19 and 24.1
u/ephemient Dec 31 '21 edited Apr 24 '24
This space intentionally left blank.
1
u/bozdoz Jan 04 '22
Go! Golang! https://github.com/bozdoz/advent-of-code-2021/blob/main/25/cucumbers.go
Not bad! Had to go finish day 19 in order to get the last part; upsetting.
1
u/aexl Jan 05 '22
Julia
This last day was pretty easy.
Iteratively generate the next state, compare it to the previous state, and if they are equal, stop.
I (mostly) had a lot of fun solving these puzzles, see you next year!
Github: https://github.com/goggle/AdventOfCode2021.jl/blob/master/src/day25.jl
My Repository containing all my solution in Julia for AOC 2021: https://github.com/goggle/AdventOfCode2021.jl
1
u/[deleted] Jan 07 '22
Java
Finally done! The solution's pretty simple. Congrats to everyone who got 50*.
1
u/zdenyhraz Jan 08 '22
C++ here is my C++ OOP-y solution. I've also tried to animate the movements of the cucumbers in each iteration via C++/Qt plotting tool and I find the result kinda beautiful. Nice to see structure emerge from chaos. See for yourself:
Sea Cucumbers Animation
PS: blue is empty space, green is right-moving cucumbers, red is down-moving cucumbers
1
u/joshbduncan Jan 13 '22
Python 3: First year actually sticking with it and finishing đ
Code
1
u/RJdaMoD Jan 24 '22
Mathematica
Very nice to watch on console:
1
u/MarvelousShade Feb 15 '22
C#
This was my first AoC (starting December 5) and I finished it almost in time (December 26).
Here's my code: https://github.com/messcheg/advent-of-code/tree/main/AdventOfCode2021
I'm looking forward to AoC2022.
In the mean time I'm making solutions for previous AoCs.
1
u/[deleted] Feb 18 '22
C: Solutions to day 1, 5 and 25. I did a few others in Rust and Python. Repo
1
u/NeilNjae Apr 24 '22
Haskell.
I used a
Mapto store the cucumbers, built up functions to manipulate the state, thenunfolded the initial state into a list of subsequent states. I then returned the length of the list.Full writeup on my blog and code on Gitlab.
1
u/[deleted] May 03 '22
This is NOT my repo, but just in case anyone comes here, like me, looking for Prolog solutions, including aoc 2021 #25: https://github.com/YauHsien/advent-of-code-2021/tree/main/prolog/src