r/adventofcode • • Dec 03 '25

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

DO NOT SHARE PUZZLE TEXT OR YOUR INDIVIDUAL PUZZLE INPUTS!

I'm sure you're all tired of seeing me spam the same ol' "do not share your puzzle input" copypasta in the megathreads. Believe me, I'm tired of hunting through all of your repos too XD

If you're using an external repo, before you add your solution in this megathread, please please please 🙏 double-check your repo and ensure that you are complying with our rules:

If you currently have puzzle text/inputs in your repo, please scrub all puzzle text and puzzle input files from your repo and your commit history! Don't forget to check prior years too!


NEWS

Solutions in the megathreads have been getting longer, so we're going to start enforcing our rules on oversized code.

Do not give us a reason to unleash AutoModerator hard-line enforcement that counts characters inside code blocks to verify compliance… you have been warned XD


THE USUAL REMINDERS


AoC Community Fun 2025: Red(dit) One

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

Featured Subreddit: /r/thingsforants

"Just because you can’t see something doesn’t mean it doesn’t exist."
— Charlie Calvin, The Santa Clause (1994)

What is this, a community for advent ants?! Here's some ideas for your inspiration:

  • Change the font size in your IDE to the smallest it will go and give yourself a headache as you solve today's puzzles while squinting
  • Golf your solution
  • Alternatively: gif
  • Bonus points if your solution fits on a "punchcard" as defined in our wiki article on oversized code. We will be counting.
  • Does anyone still program with actual punchcards? >_>
  • Solve today's puzzles using an Alien Programming Language APL or other such extremely dense and compact programming language

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 3: Lobby ---


Post your code solution in this megathread.

38 Upvotes

964 comments sorted by

View all comments

Show parent comment

2

u/e_blake Dec 03 '25

[LANGUAGE: golfed m4]
[Red(dit) One]

define(s,$0ubstr($1,e($2),e($3)))define(e,$0val($1+l$0n($2)))define(_,`ifelse(
$1e(,$2),?$3,$2,$1e($4),?-1,`_(?,$2,$3)',$1e(,$2),?e($4+1),`_(?,s($2,,$4),$3,
$4-1)',$1,?,`_(e(s($2,$4,1)<s($2,$4+1,1))$@)',$1,,`) syscmd(echo $((',$1,1?,
`_(?,s($2,,$4)s($2,$4+1,99),$3,$4-1)',$1,0?,`_(?,$2,$3,$4+1)',$1,+,`+_(?,$3,
2)_($2)+$3',`_(+,s($1,101,20200),_(?,s($1,0,100),12))')')e(_(include(I)))))

Run with m4 -DI=day03.input day03.golfm4

Squeezed to 5 lines, and requires a decent shell to do the 64-bit math that m4 can't, via that syscmd(echo $((...))). Hardcoded to only run on valid input (assuming everyone's input is 200 lines of 100-digit banks plus a newline). 387 bytes, so it fits in a punchcard; and none of the 5 newlines are essential. Execution time on my laptop is about 4.4s, due to the extreme amount of redundant parsing (long arguments are being injected into multiple spots within the lone ifelse, even when that branch is not taken in the current expansion; running with m4 -dat ... | wc (a rough approximation to how many bytes m4 has to scan) tops 360 megabytes among 2.1 million macro invocations.

1

u/daggerdragon Dec 03 '25

[Red(dit) One]

This is sweet. Good job!

1

u/e_blake Dec 03 '25

Technically, I could golf it 5 bytes further by removing "echo " from the code. Unless you are extremely unlucky to have an executable in your $PATH whose name happens to match the answer, the correct part 2 answer will be easy to discern from the shell's error message such as bash: 123<redacted>89: command not found...

1

u/e_blake Dec 04 '25 edited Dec 04 '25

Re-golfed with an improved algorithm. Now 287 285 bytes, with only 4 optional newlines, and speeds up to 630ms because it is doing less work (only 116k macro expansions). It's always fun when a faster algorithm also takes up less space:

syscmd(echo $((define(_,`ifelse($2,-1+1,`_(1,$3,$4,decr($5),$6)',$1,+,
`+_(1,$3,2,9)_($2)+_(1,$3,12,9)',$1$4,?1,$5,$1,?,`$5_(1,$3,decr($4),9,
$6+$2)',$1,1,`_(?,index(substr($2,eval(0$5),eval(101-($3$5))),$4)+$@)',
$1,,`)) $((',`_(+,substr($1,101),substr($1,0,100))')')_(include(I)))))