Xah Talk Show 2026-01-13 Ep744 Wolfram Language, Advent of Code 2025, Day 7, part 2
Analysis of the problem
you got a particle at the top, it flows down, each time it encounters a splitter “^”, it may move to the left or right.
the question asks, how many total possibilities in the end.
so, in each instance of time, there is may be n particles, and each has a position.
now lets focus on a single particle. when it runs into a splitter, it may go left or right. so that means, it adds 2 possibilities to the existing number of possibilities
- so, we begin with a state: numberOfPossibilities = 0. in each flow of a row, this may increase, and always by 2 per collision.
- then we need another state: number of particles and their positions. e.g. xstate = {8}
- the algo, is just write a function, and loop it thru the rows, and update the states. the solution is numberOfPossibilities.
.......S....... ............... .......^....... ............... ......^.^...... ............... .....^.^.^..... ............... ....^.^...^.... ............... ...^.^...^.^... ............... ..^...^.....^.. ............... .^.^.^.^.^...^. ...............
......|.|...... ......^.^......
......|.|...... .....|^|^|.....
ok, now i think, the question is about how many total possible path from top to bottom.
ok, we try this. when a particle encounter a splitter, increase possible path by 2, but when there is a particle merge, decrease by 1.
solution
xinput = ".......S....... ............... .......^....... ............... ......^.^...... ............... .....^.^.^..... ............... ....^.^...^.... ............... ...^.^...^.^... ............... ..^...^.....^.. ............... .^.^.^.^.^...^. ..............."; xmatrix = ReplaceAll[ Map[ Characters , StringSplit[xinput, "\n"]] , { "." -> 0 , "^" -> 1}]; xtotalMultiverse = 0; (* fnewState[xbeamState, xRow] return a new xbeamState. *) fnewState = Function[{xbeamState, xRow}, Print["xbeamState is ", xbeamState]; Print[xRow]; DeleteDuplicates@ Flatten@With[{xcollideList = Intersection[xbeamState, Flatten@Position[xRow, 1]]}, If[Length@xcollideList === 0, xbeamState, With[{xnewBeamState = Complement[ Union[xbeamState, Flatten @ Map[Function[xpos, xpos + {-1, 1}], xcollideList ]] , xcollideList] }, xtotalMultiverse = xtotalMultiverse + Length@xnewBeamState; xnewBeamState ] ]]]; Length @ Fold[ fnewState , Flatten @ Position[ First @ xmatrix, "S" ] , Rest @ xmatrix ] (* 9 *) xtotalMultiverse (* 40 *)
xinput = ".......S....... ............... .......^....... ............... ......^.^...... ............... .....^.^.^..... ............... ....^.^...^.... ............... ...^.^...^.^... ............... ..^...^.....^.. ............... .^.^.^.^.^...^. ..............."; xmatrix = ReplaceAll[ Map[ Characters , StringSplit[xinput, "\n"]] , { "." -> 0 , "^" -> 1}]; xtotalPaths = 0; (* fnewState[xbeamState, xRow] return a new xbeamState. *) fnewState = Function[{xbeamState, xRow}, Print["xbeamState is ", xbeamState]; Print[xRow]; DeleteDuplicates@ Flatten@With[{xcollideList = Intersection[xbeamState, Flatten@Position[xRow, 1]]}, If[Length@xcollideList === 0, xbeamState, With[{xnewBeamState = Complement[ Union[xbeamState, Flatten @ Map[Function[xpos, xpos + {-1, 1}], xcollideList ]] , xcollideList] }, xtotalPaths = xtotalPaths + Length @ xnewBeamState; xnewBeamState ] ]]]; Length @ Fold[ fnewState , Flatten @ Position[ First @ xmatrix, "S" ] , Rest @ xmatrix ] (* 9 *) xtotalPaths (* 40 *)
incorrect solution when run on personal input
Advent of Code 2025
- Xah Talk Show 2025-12-08 Ep720 Wolfram Language, Advent of Code 2025, Day 1
- Xah Talk Show 2025-12-09 Ep721 Wolfram Language, Advent of Code 2025, Day 1, Part 2
- Xah Talk Show 2025-12-11 Ep723 Wolfram Language, Advent of Code 2025, Day 1, Part 2, take 2
- Xah Talk Show 2025-12-12 Ep724 Wolfram Language, Advent of Code 2025, Day 2
- Xah Talk Show 2025-12-15 Ep725 Wolfram Language, Advent of Code 2025, Day 2, Part 2
- Xah Talk Show 2025-12-17 Ep726 Wolfram Language, Advent of Code 2025, Day 3 (aborted)
- Xah Talk Show 2025-12-18 Ep727 Wolfram Language, Advent of Code 2025, Day 3, take 2
- Xah Talk Show 2025-12-19 Ep728 Wolfram Language, Advent of Code 2025, Day 3, Part 2 (failed)
- Xah Talk Show 2025-12-20 Ep729 Wolfram Language, Advent of Code 2025, Day 4
- Xah Talk Show 2025-12-21 Ep730 Wolfram Language, Advent of Code 2025, Day 4, take 2
- Xah Talk Show 2025-12-22 Ep731 Wolfram Language, Advent of Code 2025, Day 4, Part 2. Wolfram vs SageMath
- Xah Talk Show 2025-12-23 Ep732 Wolfram Language, Advent of Code 2025, Day 4, Part 2. take 2
- Xah Talk Show 2025-12-26 Ep733 Wolfram Language, Advent of Code 2025, Day 5
- Xah Talk Show 2025-12-27 Ep734 Wolfram Language, Advent of Code 2025, Day 5, Part 2 (failed)
- Xah Talk Show 2026-01-02 Ep736 Wolfram Language, Advent of Code 2025, Day 6
- Xah Talk Show 2026-01-05 Ep738 Wolfram Language, Advent of Code 2025, Day 6, Part 2
- Xah Talk Show 2026-01-09 Ep741 Wolfram Language, Advent of Code 2025, Day 7
- Xah Talk Show 2026-01-13 Ep744 Wolfram Language, Advent of Code 2025, Day 7, part 2