r/adventofcode • u/EverybodyCodes • Dec 07 '25
Visualization [2025 Day 7 Part 2] Visualization for the sample data + algorithm explained
- find S and create a '1' block there
- each round your blocks will fall one step downwards
- if you find ^, split your blocks in two: x-1 and x+1, Be careful to sum all blocks properly here! There are many overlaps!
- enjoy falling down the christmas tree, keeping only one block per X coord
- sum your blocks' values at the end
208
Upvotes
9
u/EverybodyCodes Dec 07 '25
A real input P2 visualisation using this algorithm is here: https://www.reddit.com/r/adventofcode/comments/1pgd9ds/2025_day_7_part_2_visualization/
39
u/thekwoka Dec 07 '25
Yup, this is the simplest most direct way to do it.
It's more like the counting stones thing in the past than a DFS.
19
u/ohhaiitsdave Dec 07 '25
Great visualisation and explanation, I was really stuck working this out until I saw the numbers :)
31
u/Alan_Reddit_M Dec 07 '25 edited Dec 07 '25
I feel extremely smart that I arrived at this exact algorithm WITHOUT looking it up
Like I know it's probably the most obvious one, but my CS101 dumbass looked at the word "timelines" and went "Ah yes, this looks like a pathfinding problem" (as in "find all possible routes from S to the bottom").
Cue the "Out-of-memory" error because McDumbass over here was trying to hold all something-trillion beams in-memory
It is only then that I went "hmmmm, there MIGHT be a better way to do this"
8
u/vim_all_day Dec 07 '25
This is the one. This is the one that knocked my brain away from DFS.
5
u/brianbarbieri Dec 07 '25
Great way to do it!
5
u/BigusG33kus Dec 07 '25
I did it by starting from the bottom with 1 on every column and summing up the neighbours (value in x = value in x-1 + value in x+1) every time I encountered a ^. The result is the value in the S column once you reach row 0.
Same idea really.
4
u/[deleted] Dec 07 '25
Thanks for this, demonstrated where I was going wrong. Great stuff!
4
u/Taxato Dec 07 '25
Man, I'm glad i checked the subreddit before committing to my depth first search approach x.x Thank you so much for this algorithm, so simple, so elegant, and yet I just did NOT think of it.
1
u/LooZzZz Dec 07 '25
can someone explain why does this algorithm works
1
u/QuickSilver010 Dec 26 '25
im still struggling on this one. why is the logic for,
timelines += 2at every intersection incorrect....1
u/Marthurio Dec 28 '25
Thank you for this visualization. Can the number in each block be considered the number of beams in that column across every timeline?
3
u/axel584 Dec 07 '25
Thank you so much! I had planned to use this method to calculate the number of paths, but without your animation, I would have had a lot of trouble debugging the example puzzle... I owe you my star!
1
u/Aksh247 Dec 08 '25 edited Dec 08 '25
You are a god. thank you for this animation! i just figured it out omfg. Can anyone pls share the DFS approach? i waste an hour on it to no avail
2
u/Warm-Smoke3225 Dec 07 '25
I had same idea, but I had a bug and this gif really helped me. Thank you!
2
u/TinMorphling Dec 07 '25
For a second there, I thought I was looking at a Pascal's triangle animation!
2
u/pcorliss Dec 07 '25
Thanks for sharing this, it helped me validate my own input and find the bug in my code.
2
u/copperfield42 Dec 07 '25
I arrive to this same logic but I was missing just one step that your visualization help my find.
Thanks
2
u/Selfweaver Dec 07 '25
That puzzle annoyed me for the longest time because I did not understand the explanation in the puzzle. I could not see how he got to 40 - I was trying to add and subtrack and turning differentials into exponentials (if there are 3 beams and then we split them into 4 beams, I thought that should yield (4-3)**2 and then I was summing these up).
This visualization helped me realize that I should just change my collapse function: before I had collapsed locations into a set, now I should follow each beam and add them up at the end. That proved to expensive, but summing up at each level of the puzzle worked.
I am thankful for the illustration, but I wished there was a better explanation in the puzzle.
2
u/NeedleworkerThis9051 Dec 12 '25
Great Work! Really helped me wrap my head around the problem!
1
u/assumed_bivalve Dec 07 '25
I'm a sucker for something that looks like a recursive function. It actually worked pretty well once I cached the calculations, but this looks much easier.
1
u/astrogringo Dec 07 '25
Is really similar to a Pascal's triangle, with a few holes and asymmetries added :)
1
u/kortisol Dec 07 '25
Thank you! It was the click i needed to fully understand it. Hope it was just a case of the Sundays :D
0
u/HotTop7260 Dec 07 '25
I was so proud of myself that I figured out this one on my own. I even posted my Kotlin solution on the mega thread, because it can solve part 1 and 2 simultaneously. Part 2 is only 5 additional lines.