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

.......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