This video from the Xah Talk Show, episode 729, focuses on solving an Advent of Code 2025, Day 4 problem using Wolfram Language (0:08).
The host, Xah Lee, emphasizes the high-level nature of Wolfram Language compared to other programming languages (1:00-1:19) and encourages viewers to check out his Wolfram Language tutorial (0:18-0:34).
The core of the video revolves around a grid-based problem where forklifts can access "rows of paper" (represented by '@' signs) if there are fewer than four rows of paper in adjacent positions (6:58-7:24, 9:06-9:36).
The goal is to count how many rows can be accessed.
Xah Lee discusses how to approach this problem by:
Treating the grid as a 2D matrix of zeros and ones (16:01-16:48).
Identifying the concept of Moore neighborhood (including diagonals) versus von Neumann neighborhood (excluding diagonals) for counting neighbors (19:24-19:46).
Exploring Wolfram Language functions for matrix manipulation, such as ArrayPad (55:49-56:05) to handle edge cases when checking neighbors.
Throughout the discussion, Xah Lee frequently digresses into exploring Wolfram Language's extensive documentation and its various functions related to arrays and matrices, such as ArrayMesh (24:19), HilbertMatrix (34:54), BoxMatrix (44:21), and MorphologicalComponents (58:03-59:22).
He highlights the power and depth of the Wolfram Language system for mathematical and computational tasks (53:50-54:24).
(* example of apply operator to list element. like auto map . *)
{ x + {-1,0,+1}, y + {-1,0,+1} }
(* {{-1 + x, x, 1 + x}, {-1 + y, y, 1 + y}} *)(* s------------------------------ *)(* generate the indexes of the neighboring cells, include itself *)Tuples[ { x + {-1,0,+1}, y + {-1,0,+1} }]
(*
{{-1 + x, -1 + y},
{-1 + x, y},
{-1 + x, 1 + y},
{x, -1 + y},
{x, y},
{x, 1 + y},
{1 + x, -1 + y},
{1 + x, y},
{1 + x, 1 + y}}
*)(* s------------------------------ *)(* generate the indexes of the neighboring cells,
but not include itself *)DeleteCases[Tuples[ { x + {-1,0,+1}, y + {-1,0,+1} }], {x,y} ]
(*
{{-1 + x, -1 + y},
{-1 + x, y},
{-1 + x, 1 + y},
{x, -1 + y},
{x, 1 + y},
{1 + x, -1 + y},
{1 + x, y},
{1 + x, 1 + y}}
*)
xinput =
"..@@.@@@@.
@@@.@.@.@@
@@@@@.@.@@
@.@@@@..@.
@@.@@@@.@@
.@@@@@@@.@
.@.@.@.@@@
@.@@@.@@@@
.@@@@@@@@.
@.@.@@@.@."(*
we can represent this as a 2d matrix.
each cell is either on,
represented by 1 or @ , or off as 0 or dot.
the problem is, for each cell, check all its neighors,
including diagonal neighors.
If a cell has 0 to 3 neighbors that are on, then, we consider that cell as special.
The problem asks, how many special cells are there.
*)
xx = {
{1,2,3},
{4,5,6},
{7,8,9}
};
Part[xx, 2, 2]
(* 5 *)