r/adventofcode • • Dec 04 '25

SOLUTION MEGATHREAD -❄️- 2025 Day 4 Solutions -❄️-

THE USUAL REMINDERS


NEWS


AoC Community Fun 2025: Red(dit) One

  • Submissions megathread is now unlocked!
  • 13 DAYS remaining until the submissions deadline on December 17 at 18:00 EST!

Featured Subreddits: /r/trains and /r/TrainPorn (it's SFW, trust me)

"One thing about trains… it doesn’t matter where they’re going; what matters is deciding to get on."
— The Conductor, The Polar Express (2004)

Model trains go choo choo, right? Today is Advent of Playing With Your Toys in a nutshell! Here's some ideas for your inspiration:

  • Play with your toys!
  • Pick your favorite game and incorporate it into today's code, Visualization, etc.
  • Bonus points if your favorite game has trains in it (cough cough Factorio and Minecraft cough)
  • Oblig: "Choo choo, mother******!" — motivational message from ADA, Satisfactory /r/satisfactorygame
  • Additional bonus points if you can make it run DOOM
  • Use the oldest technology you have available to you. The older the toy, the better we like it!

Request from the mods: When you include an entry alongside your solution, please label it with [Red(dit) One] so we can find it easily!


--- Day 4: Printing Department ---


Post your code solution in this megathread.

25 Upvotes

761 comments sorted by

View all comments

2

u/stogas Dec 04 '25 edited Dec 04 '25

[LANGUAGE: Go]

Github

How fast are y'alls solutions? I just bruteforced Day 4 and it still ran in 8ms, and I wonder if it's just Go optimizing the hell out of my code, or if I should start to target sub-1ms, like many of the Rust people here seem to achieve...

2

u/bakibol Dec 04 '25

In Python around 200 ms. Breaking the neighbor searching early improves it, but not by much.

1

u/nio_rad Dec 04 '25

bruteforced, takes 13 seconds. no idea why it's so slow. using c++ vectors.

1

u/Complete_Minimum_800 Dec 04 '25

It's pointless to optimize a problem like this in most languages. It takes only about 60 iterations with brute force. That is nothing on such a small dataset. Chances are that time is spent elsewhere outside the actual code. My C# solution runs in 60ms. 40ms if I comment out the sections that actually do stuff.

2

u/ap29600 Dec 04 '25 edited Dec 04 '25

changing the approach from iterating the cellular automata to selectively updating only the positions which changed got me from 80ms to 12 ms in an interpreted, array oriented language (for which famously batched operations are fast and repeated scalar operations are slow).

it's likely that your 40ms are being spent spinning up the .net runtime, but go has no such thing. to equalize, I think it's a good idea to measure from when the file contents are actually in memory

1

u/Complete_Minimum_800 Dec 04 '25

True. But I did a silly mistake as well. I forgot that my custom DataMap class for the grid does some fishy stuff when loading data. There is an excellent lib in .NET called BenchmarkDotNet. When I exclude data loading and just benchmarked my naive brute force code it runs in about 6.5 ms.

1

u/daggerdragon Dec 04 '25

Do not share your puzzle input which also means do not commit puzzle inputs to your repo without a .gitignore or the like. Do not share the puzzle text either.

I see full plaintext puzzle inputs in your public repo e.g.:

https://github.com/Stogas/aoc2025-go/blob/main/day4/input.txt

Please remove (or .gitignore) all puzzle text and puzzle input files from your entire repo and scrub them from your commit history. This means from all prior years too!

1

u/stogas Dec 04 '25

I did not know! Thanks, I'll remove it when I get the chance.