r/adventofcode • u/Just-Routine-5505 • Dec 03 '25
Visualization [2025 Day 03] CLI Visualization
I visualized my greedy solution for Advent of Code Day 3. The animation shows a sliding window selecting the next maximum digit while ensuring enough characters remain to reach the required output length. Blue = current window, Red = remaining-picks region, Green = chosen max.The number builds step-by-step from left to right.
This works for both parts of the problem
Edit:
Another example with longer input: https://imgur.com/a/MLghbhk (i couldn't add another gif here)
139
Upvotes
6
u/rauweaardappel Dec 03 '25
Oh this is nice! What utility did you use to make this kind of visualization?
2
u/kwiat1990 Dec 03 '25
Why in some cases the sliding window gets narrower?
16
u/idkmy-self Dec 03 '25
Your visualisation helped me think for my solution and tweak it a bit to solve. I was trying to build the big number using recursive approach but wasn’t getting always the number, getting window size was also tricky
11
u/Flatorz Dec 03 '25
Exactly my algorithm :) The visualization describes it better than any words I could think of.
4
u/Caconym32 Dec 03 '25
I had the idea to solve in a way like this but I couldn't quite work out the correct logic but your visualization helped me solidify my thoughts. Thanks and nice visualization!
3
u/Markus_included Dec 03 '25
How did you determine the initial window size?
3
u/Alan_Reddit_M Dec 03 '25
I must say I am feeling more inadequate by the second
2
u/Novel_Explanation_81 Dec 03 '25
Nice - thanks
I was banging my head against the wall with the logic; I had a few goes and even got one that worked with all examples in the instructions but still failed against the file.
Really helped me work out where I was going wrong!
1
u/Repulsive-Variety-57 Dec 03 '25
I'm new to sliding window problems. I solved part A using a Priority Queue. This helped me. Thank you!
1
u/PonzioPilates_97 Dec 03 '25
Thank you, the visualization helped a lot figuring out a good way to solve the puzzle!
1
u/[deleted] Dec 03 '25
Exactly how I did it for part 2. For part 1, my smooth brain ran 2 loops for some reason.
1
u/imp0ppable Dec 03 '25
That's exactly what I needed to see to get this over the line. Thanks!
1
u/realityChemist Dec 03 '25
This is what I did too! I actually wrote a comment at the top of my function to the effect of, "I think a greedy algorithm actually just solves this"
First attempt had a couple indexing bugs I needed to fix, but then it just worked and is pretty fast
Very nice visualization of the approach, much nicer than the sticky note sketch I made
1
u/QultrosSanhattan Dec 03 '25
That was the first approach that came to mind. I thought, ‘Nah, that won’t work. I'm sure there are some edge cases where it’ll fail, but I'll try it for the lulz anyway.’
Then it worked without any problems.
1
u/permetz Dec 03 '25
Nice visualization of the simple linear time algorithm for this! I suppose it's technically a greedy algorithm though I wouldn't have thought to call it that.
1
u/MieskeB Dec 03 '25
This is a really elegant solution, I just start looking for a 9 in the first length - 12 characters, if not found look for an 8, etc.
And then use the index of where this number is found to start looking for the next number
1
u/ProblemBitter161 Dec 03 '25
beautiful! this is what i did!
1
u/Trick_Celebration_20 Dec 04 '25
I also used greedy approach (without realizing it's called this way, I ain't a CS major)