Xah Talk Show 2026-01-09 Ep741 Wolfram Language, Advent of Code 2025, Day 7

Video Summary (Generated by AI, Edited by Human.)

Problem analysis

.......S.......
...............
.......^.......
...............
......^.^......
...............
.....^.^.^.....
...............
....^.^...^....
...............
...^.^...^.^...
...............
..^...^.....^..
...............
.^.^.^.^.^...^.
...............

algo gist

xah talk show ep741 aoc 2a5be
xah talk show ep741 aoc 2a5be

Solution. code

sample test case

xinput = ".......S.......
...............
.......^.......
...............
......^.^......
...............
.....^.^.^.....
...............
....^.^...^....
...............
...^.^...^.^...
...............
..^...^.....^..
...............
.^.^.^.^.^...^.
...............";

{x1stRow, xmatrix} = Function[x, {First @ x, Rest @ x }] @
ReplaceAll[ Map[ Characters , StringSplit[xinput, "\n"]] , { "." -> 0 , "^" -> 1}]

(* {0, 0, 0, 0, 0, 0, 0, S, 0, 0, 0, 0, 0, 0, 0}  *)

(* {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} *)

(* a list of indexs *)
xbeamState = Flatten @ Position[ {0,0,0,0,0,0,0,"S",0,0,0,0,0,0,0}, "S" ]
(* {8} *)

xsplitterPos = Flatten @ Position[ {0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0}, 1 ]
(* {6, 8, 10} *)

Intersection[ {8} ,{6, 8, 10} ]
(* {8} *)

(* split. on a single beam state of a single beam *)
Flatten @ Map[ Function[xpos, xpos+{-1,1}] , {8} ]
(* {7, 9} *)

(* split. on a beam state of a 2 beams *)
Flatten @ Map[ Function[xpos, xpos +{-1,1}] , {8, 10} ]
(* {7, 9, 9, 11} *)

(* deal with merged beam. new beam state *)
DeleteDuplicates[{7, 9, 9, 11}]
(* {7, 9, 11} *)
xinput = ".......S.......
...............
.......^.......
...............
......^.^......
...............
.....^.^.^.....
...............
....^.^...^....
...............
...^.^...^.^...
...............
..^...^.....^..
...............
.^.^.^.^.^...^.
...............";

xmatrix = ReplaceAll[ Map[ Characters , StringSplit[xinput, "\n"]] , { "." -> 0 , "^" -> 1}];

xtotalSplit = 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]]},
     xtotalSplit = xtotalSplit + Length@xcollideList;
     If[Length@xcollideList === 0, xbeamState,
Complement[ Union[xbeamState, Flatten @ Map[Function[xpos, xpos + {-1, 1}], xcollideList ]] , xcollideList]
]]];

Length @
Fold[ fnewState ,
 Flatten @ Position[ First @ xmatrix, "S" ] ,
 Rest @ xmatrix
]
(* 9 *)

xtotalSplit
(* 21 *)

now personal input

xinput = "......................................................................S......................................................................
.............................................................................................................................................
......................................................................^......................................................................
.............................................................................................................................................
.....................................................................^.^.....................................................................
.............................................................................................................................................
....................................................................^...^....................................................................
.............................................................................................................................................
...................................................................^.^...^...................................................................
.............................................................................................................................................
..................................................................^.......^..................................................................
.............................................................................................................................................
.................................................................^...^.^.^.^.................................................................
.............................................................................................................................................
................................................................^.....^.^...^................................................................
.............................................................................................................................................
...............................................................^.^.^.^...^.^.^...............................................................
.............................................................................................................................................
..............................................................^.^.^.^.^...^...^..............................................................
.............................................................................................................................................
.............................................................^.^...^.^.^.^...^.^.............................................................
.............................................................................................................................................
............................................................^...^.^.^.......^...^............................................................
.............................................................................................................................................
...........................................................^.^.....^...^.....^.^.^...........................................................
.............................................................................................................................................
..........................................................^...^.^...^...^...^.^.^.^..........................................................
.............................................................................................................................................
.........................................................^.^.^...^.^.^.^.....^.^.^.^.........................................................
.............................................................................................................................................
........................................................^.^.....^.^.^.^.^...^.^...^.^........................................................
.............................................................................................................................................
.......................................................^.^.......^.^.^.^.....^.......^.......................................................
.............................................................................................................................................
......................................................^.^.^.^.^...^...^.^...^.........^......................................................
.............................................................................................................................................
.....................................................^.....^.^.......^.........^.^.^.^.^.....................................................
.............................................................................................................................................
....................................................^.^.^.^...^.^.^...^.....^...^...^.^.^....................................................
.............................................................................................................................................
...................................................^...^.^.^.....^...^.^.^.^.^.^.^.......^...................................................
.............................................................................................................................................
..................................................^.^...^.^.^.^.^...^.^.....^.^.^.^.^.^.^.^..................................................
.............................................................................................................................................
.................................................^.^.^.^.^.......^.^...^.^.^.....^.^...^...^.................................................
.............................................................................................................................................
................................................^.^.^.^...^...^.^.^.^.^.^.^.^.^.^.^.^...^...^................................................
.............................................................................................................................................
...............................................^.^.^.^...^...^...^.^.^...^.^.^.....^.^.^...^.^...............................................
.............................................................................................................................................
..............................................^...^...^...^.....^...^...^...^...^...^.^.^.^...^..............................................
.............................................................................................................................................
.............................................^.^...^.^.^.^.^...^.^...^.^.....^.^.^.^.^.^.......^.............................................
.............................................................................................................................................
............................................^.^.^.^.^...^.^.....^...^.^.^.^.......^...^...^.^...^............................................
.............................................................................................................................................
...........................................^.^...^.^.^...^.^.^.....^.....^...^.^.^...^...^.^.^.^.^...........................................
.............................................................................................................................................
..........................................^...^...^...^.....^.^.^.^...^.^...^.^.^.^.^.^.^.^.^.^.^.^..........................................
.............................................................................................................................................
.........................................^.^.....^.^...^...^...^.^.^.^...^.^...^.........^.^.^.....^.........................................
.............................................................................................................................................
........................................^.^.....^.^.^...^...^...^.....^...^...^.^.^.^.^.^.^.^.^.^.^.^........................................
.............................................................................................................................................
.......................................^...^.^.^.^.^...^...^.^.^.^.^.^...^...^.^...^.......^.^.^...^.^.......................................
.............................................................................................................................................
......................................^.^.^...^.^.^.....^.......^.................^...^.^.^.^.^.^.^.^.^......................................
.............................................................................................................................................
.....................................^.^.......^.....^.^...^.^.^.^.......^...^.^.^...^.^...^.^.^.^...^.^.....................................
.............................................................................................................................................
....................................^.^...^...^.^.^.^.....^...^...^.^.^.....^...^...^.^.^...^...^...^...^....................................
.............................................................................................................................................
...................................^.^.^...^.....^...^.^.^...^...^.^...^.^.^...^.^.......^.^...^.^...^...^...................................
.............................................................................................................................................
..................................^.^.^.^.......^...^.^.^...^.^.^.^...^.^.^.....^.^.^.......^.^.^...^.^...^..................................
.............................................................................................................................................
.................................^...^...^.^.^.^...^...^...^.^.^.....^.^.^...^.^.......^.^.^.^...^.....^.^.^.................................
.............................................................................................................................................
................................^.^.^.....^.^.^.^.^.^.....^.^.^...^.^...^.....^.^.^.^.^.^.^.^.....^.^.^.^.^.^................................
.............................................................................................................................................
...............................^...^.^.^.....^.^...^...^.......^.^.^.....^.^.^.^.^.^.^.^.^...^...^.^.....^.^.^...............................
.............................................................................................................................................
..............................^.^.^.^.^.......^.^...^...^.^.^...^...^.^.^.........^.^.^.^...^.....^...^.^.^.^.^..............................
.............................................................................................................................................
.............................^...^...^.^...^.^.^.^.........^.^.^.^.^.^...^.^...^.....^.....^.^.....^...^...^.^.^.............................
.............................................................................................................................................
............................^.......^...^.^.^.^.^...^...^.^.^.^.^.^...^.^...^.^.^.^...^.^.^.^.^.^.^...^.^.^...^.^............................
.............................................................................................................................................
...........................^.^...^...^.^...^...^.^.^.....^.......^.^.....^.^.^.^.^.^.......^.^.^...^...^.^...^...^...........................
.............................................................................................................................................
..........................^.......^.^.^.^.^.^...^.^.^...^...^.......^...^.^.^...^.....^...^...^.....^...^.^...^.^.^..........................
.............................................................................................................................................
.........................^...^.^.^.^...^.^...^.^.^.^.^.^...^...^.^.....^.^.^.^...^.^...^.^.^.^.^.^.........^.^.^.^.^.........................
.............................................................................................................................................
........................^...^.^...^...^.^.^.^.^.^.^.^.^.^.^...^...^...^...^.......^.^.....^.^.^.^.^.^.....^...^...^.^........................
.............................................................................................................................................
.......................^...^.^...^...^.^.......^.^.^.^.^.^...^.^.^.^...^.^...^.^.^.......^.....^.^.^.^.^.^.....^.^.^.^.......................
.............................................................................................................................................
......................^.^.^.^.^.^...^...^.^.^.^...^.^.....^.....^.^.^.^...^.^.^.^.^.^...^.^...^.^.^.........^.......^.^......................
.............................................................................................................................................
.....................^.^.^.....^.....^.^.^.^.......^.^.^...^.^.^.....^...^.^.^.^...^...^.^.......^...^.^.^.^...^.^.^...^.....................
.............................................................................................................................................
....................^.....^.^.....^...^...^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^.^...^...^.^...^...^...^...^.....^...^....................
.............................................................................................................................................
...................^.^...^...^.^.^.^.....^.^.^...^.^.....^...^...^.^.^.^...^.^...^.^.^.^.^.^.....^.^.^.^.......^...^.^.^.^...................
.............................................................................................................................................
..................^.^.......^.^...^.^...^.^.^...^.^.^.^...^.....^.^.^...^.^.^.^.^...^.^...^...^.^.^.^.^.^...^.^.^.^.^.^...^..................
.............................................................................................................................................
.................^.^.^...^.^.^.^.....^.^.^.^.^.....^.^.....^.^.^.^...^...^.^.......^.^.^.^.^...^.^.....^.^...^.^.^.^...^...^.................
.............................................................................................................................................
................^...^.^.^...^.^.....^.^.^.^.^.^.^.^...^.....^.^...^.^...^...^...^...^.^.^.....^.^.^.^.^.^.^.....^...^.^.^...^................
.............................................................................................................................................
...............^...^.^...^.^.^...^.^...^...^.^.^.^.^.^.^.^.^.^.^.^...^.^.^...^.....^.^.......^.^...^.^...^.^.^.^.^.^.^.^.^.^.^...............
.............................................................................................................................................
..............^.^...^...^.....^...^.^...^.^...^.^.^.^.^.....^...^...^.....^.^.^...^.^...^.^...^.....^...^...^.....^...^.^.^...^..............
.............................................................................................................................................
.............^.....^.^.^.^...^.....^.^.......^.^.^.^.^.^.^.....^...^.....^.^.....^.^.^.....^...^.^...^.^.^.^...^.^.....^...^.^.^.............
.............................................................................................................................................
............^.^...^.^.......^.^.^.^.^...^.^.^.....^.^.^.^...^...^.....^...^.^...^.^.^...^.^.^.^...^...^.....^.^.^.^...^.^...^.^.^............
.............................................................................................................................................
...........^.....^.^.^.^...^...^.^...^...^.....^.^...^...^.^.^...^.^.......^.^.^...^.^...^.^.......^.^...^.......^.^...^...^.^.^.^...........
.............................................................................................................................................
..........^.^.^.^.......^...^.^.^.^.^.^.^...^.....^.^...^.^.^.^.^.^.^.^.^...^.^.....^.^.......^.^.^.^...^.^.......^.^...^.^...^...^..........
.............................................................................................................................................
.........^.^...^.....^.^.^.^.^.^.^.^...^.^.^.^...^.^.^.^.^.^.^.^...^...^...^.^.^.^.^.^.^.^.^.^.^...^.....^.^.^.^.^.^...^.^.^...^.^.^.........
.............................................................................................................................................
........^.^.^...^.^...^.^.^.^...^.......^...^...^.^.^.^.....^.^...^.^.^.....^.^.^.^.^.^.^...^.^...^.^.^.......^...^.^...^.....^.^...^........
.............................................................................................................................................
.......^.^.^.....^.....^.....^.^.^.^.^.^...^.^...^...^...^.........^.^...^.^.^...^.^...^.^.^...^.^.........^.^.^.^.^.^...^...^.^.^.^.^.......
.............................................................................................................................................
......^...^.^...^...^.^.^...^...^.^.^.^.^.^.^.^.^.^...^...^.....^.......^.^.^.^.^.^.^.^...^.^.^...^...^.^...^.....^.......^.^.^...^.^.^......
.............................................................................................................................................
.....^.^.^.....^...^.^.............^...^.^.^.^.^.^...^...^.^.^.^.^.^.^...^...............^.......^.^.^.....^.^...^.^.^.^.......^...^.^.^.....
.............................................................................................................................................
....^...^.^.^...^...^...^.^.......^...^.^.^.^.^.^.^...^.^.^.^.^.....^.^...^.^...^.^.^.^.........^.....^.^...^...^.^.^.^.^...^.^...^...^.^....
.............................................................................................................................................
...^...^.....^.^.^...^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.....^...^...^...^.^.^.^.^...^.^.^.^.^.^.^.^.......^.^.^.^.^.^...^.^...^.^.^...^...^...
.............................................................................................................................................
..^.^...^.^.^.^.^...^.^.^.^.^.^...^.^.^.^.^.^...^...^.....^.^.^.^.^...^.^...........^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.........^.^.^...^.^..
.............................................................................................................................................
.^...^.^.^.^...^.....^.^.^.^.^.^.^.^.^...^.^.^...^.^.^...^.^...^.^.^.^...^...^.....^.....^...^.^...^.^.^...^.^.....^...^.^.^.^.^.^.^.^.^.^.^.
.............................................................................................................................................";

xmatrix = ReplaceAll[ Map[ Characters , StringSplit[xinput, "\n"]] , { "." -> 0 , "^" -> 1}];

xtotalSplit = 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]]},
     xtotalSplit = xtotalSplit + Length@xcollideList;
     If[Length@xcollideList === 0, xbeamState,
Complement[ Union[xbeamState, Flatten @ Map[Function[xpos, xpos + {-1, 1}], xcollideList ]] , xcollideList]
]]];

Length @
Fold[ fnewState ,
 Flatten @ Position[ First @ xmatrix, "S" ] ,
 Rest @ xmatrix
]
(* 87 *)

xtotalSplit
(* 1516 *)

Advent of Code 2025