🔒 - 2025 DAY 1 SOLUTIONS -🔒
Day 1: Secret Entrance
Megathread guidelines
- Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
- You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL
FAQ
- What is this?: Here is a post with a large amount of details: https://programming.dev/post/6637268
- Where do I participate?: https://adventofcode.com/
- Is there a leaderboard for the community?: We have a programming.dev leaderboard with the info on how to join in this post: https://programming.dev/post/6631465
DOS + BIOS boot (hybrid binary)
Repo | day01.asm | day01.c (prototype) | .COM download
Written in x86-16 assembly. Works as a DOS program but also as disk image for older PCs with BIOS support (or older VMs). Getting this setup to work was tricky, especially since when I started this, I had only basic x86-16 experience! Needless to say I've spent much time staring at hex numbers.
The very start of the file determines if it's running in DOS or as a bootloader, in which case it'll have to load the remainder of the file from disk and rearrange the memory layout to emulate the DOS situation.
Right now this is using just one segment of memory (64K). Input data is compressed using a custom run-length encoding scheme. The compressed background image is directly decoded into the VGA framebuffer, after which it is overwritten with the decompressed input file. Space is tight!
My main goal is to finish a few days at least with one or more game consoles supported (GameBoy Advance would be cool) and to do some cool palette tricks, like a day/night transition or animated water and stars.
so many years have passed since i last wrote a line of masm...
Uiua
Today's lesson: Never think that scanning the first 100 lines of input will give you a good understanding of it.
Part 2 is really messy and could probably be much simpler, but I couldn't get the logic straight in my head otherwise.
Just had a look at the Uiua Discord, and Part 2 can be simplified a little...
Sometimes I could just cry.
Rust
Nice solution. Just a little Rust tip if you don't mind: In this case you can avoid cloning the input Vec in the loops by instead looping over references into the list with
for n in self.input.iter()or simplerfor n in &self.input. The only difference is thatnwill be of type&i64instead ofi64.Thanks! I don’t mind tips at all.
I'm far from sure I understand what you're doing in part 2, but I think maybe you hit the same logic bug I did (I solved it with a shameful if statement that I will have to fix later).
the idea is that crossing the zero is easy to detect by dividing the total dial movement by 100. I.e. if you cross from 120 to 90 you will detect that 120/100=1 changed to 90/100=0. The only case when this doesn’t work is when you stop at zero going in the negative direction, hence the extra if
The thing I couldn't comprehend was where 1000000000050 had come from.
ah that’s just because i needed rounding towards infinity and not towards zero. In other words i wanted -10/100 to be -1 and not zero. But i couldn’t figure it out on the spot, so i just made it never negative :)
How could I run this code? Do you use some kind of framework for AoC?
you could say that, yeah, it downloads the inputs, submits the answers, and keeps track of wrong answers. You can grab my entire repository here: https://github.com/hades/aoc25/tree/master
Golang
A straightforward day 1 for a Javascript / NodeJS solution.
::: spoiler Poorly Optimized JS Solution
:::
Brute forcing it like this was my first thought - like they say: if it's stupid and it works, it's not stupid.
So, obviously the bot didnt work, thanks Ategon for covering :D
Here is the dumb solution for pt2, everyone can share in my shame:
Haskell
I think that's a really cool usage of the Writer Monad. I thought about the State Monad but didn't end up using it. Was too hectic for me. Thanks for showing and sharing this!
Rust
Almost missed, that "the dial starts by pointing at 50".
View on github
Nim
That was the rough first day for me. Part 1 was ok. For part 2 I didn't want to go the easy route, so I was trying to find simple formulaic solution, but my answer was always off by some amount. And debugging was hard, because I I was getting the right answer for example input.
After 40 minutes I wiped everything clean and wrote a bruteforce.
Later that day I returned and solved this one properly. I had to draw many schemes and consider all the edge cases carefully to come up with code below.
Full solution at Codeberg: solution.nim
The struggled with a counting solution for a long time. I submitted with a simple enumerative solution in the end but managed to get it right after some pause time:
Haskell
::: spoiler Fast to Run, Stepwise Solution
:::
::: spoiler Fast to Code, Exhaustively Enumerating Solution
:::
Why are you preferring lambda-case over plain old pattern matching as in the following snippet? I didn't know this language feature existed and I am now curious :)
Thank you for the excellent question. This made me reflect on my coding style and why I actually chose this. Maybe you have noticed, my usage of
LambdaCaseis inconsistent: I didn't use it in the definition offoldRotation. Which happened with some refactorings (You couldn't know that, I didn't tell anywhere), but still.After going through some 'old' code I found that I didn't start using it until early this year. (For context: I started doing Haskell in September 2024) But that may just coincide with me installing HLS.
Anyway, back to the topic: I actually think it's very elegant because it saves re-typing the function name and/or other parameters. It also easily allows me to add further arguments to the function (but only before the last one). In my mind, this is where
LambdaCaseshines.Sometimes I end up refactoring functions because it's very hard to match on multiple arguments using
LambdaCase. I also try to avoid adding arguments in the back, which might bite me later and limits flexibility a lot.::: spoiler Moaaar Backstory I picked it up in some forum discussion I read where somebody argued that using explicit matches litters the Codebase with re-definitions of the same functions. It makes
grep-ing the source hard. I was easily influenced by this and adopted it.I think this is not the way I like to go about it. I would rather use Hoogle, Haddock or HLS to search in my source. :::
Elixir
Oh wow I'm late but that's because I decided to do this year in Elixir which I am not really experienced enough yet as it seems. Part 1 was ok but I didn't really put enough thought into Part 2 and got stuck for a while. However I got it done after a few failed tries and a few questions to AI on how to do things in Elixir.
Edit: removed debug output
c
Python
Solved part 1 in a matter of minutes, spent literal days tinkering with part 2 before resorting to brute force, just to finally get a correct result, which allowed me to fix the more optimised approach. Brute force still turned out surprisingly performant, scaling linearly in time with the rotation distance and sub-linearly in memory.
Brute force part 2
Rust
I lost a lot of time struggling with edge cases in part two since I thought it was wasteful to run
rem_euclid()(i.e. modulus) when I'd already got the information to do it more efficiently. While I got there in the end my final code was a bit ugly. This prettier, "unoptimised" version runs in 1.6ms, so I was being an idiot.Haskell
I was late to the part on this one and forgot to post my solution :3
C# ( c sharp )
Kotlin
already rather scuffed for day1, but works:
https://codeberg.org/Eco-Gaming/AdventOfCode/src/branch/main/src/main/kotlin/a2025/puzzles/Day01.kt
Here's my Kotlin version for Part 2.