Xah Ep741 Wolfram Language, Advent of Code 2025, Day 7
Автор: Xah Lee
Загружено: 2026-01-09
Просмотров: 114
Advent of Code 2025, Day 7, using Wolfram Language (0:05).
The problem involves a "tachyon manifold" diagram, where a beam originating from 'S' travels downward and splits into two (left and right) upon encountering a splitter character ('^').
Problem is to compute the total number of times the beam splits (1:13:35).
Lee first analyzes the problem by reading the description and understanding the beam's behavior (8:10). He then devises a step-by-step algorithm (27:10).
Input Processing: Convert the raw text input into a matrix for easier manipulation (30:05). Replace the empty spaces ('.') with 0 and splitters ('^') with 1 to simplify calculations (36:40).
Beam State Management: Maintain a list of the current beam positions (indexes) (35:55). The initial state is the position of 'S' in the first row (41:59).
Iteration and Comparison: Loop through each row of the matrix, comparing the current beam positions with the splitter positions in the next row (21:53).
Splitting and Merging Logic:
If a beam's position matches a splitter's position, that beam splits into two new positions: (original_position - 1) and (original_position + 1) (26:36, 1:00:28).
Beam merges are handled by removing duplicate positions from the list of beam states (22:33, 1:12:12).
Edge Cases: Lee notes that the specific puzzle input does not require handling beams going off the grid (25:24).
Wolfram Language Implementation: demo use functions like StringReplace (37:04), Characters (31:14), Position (49:28), Intersection (57:18), Map (58:24), and Flatten (1:07:56) to implement the logic.
Heart of the solution is the function f_new_state that takes the current beam state and a row, returning the next beam state (1:14:49).
Final Calculation: The Fold function is used to apply f_new_state iteratively across all rows, and the final answer is the Length of the resulting beam state list (1:21:04).
Towards the end, he debugs a minor issue related to function definition, highlighting the iterative process of coding (1:23:19).
Two major problems that costed 30 minute each, is 2 logical errors in our algorithm. One, we forgot to keep the beams that did not collide. Two, we forgot to remove the beams that did collide.
Notes at
http://xahlee.info/talk_show/xah_talk...
If browser says security error, that is because it auto changes URL from HTTP to HTTPS.
It's a way to censor 22 million old websites.
Remove the S in HTTPS.
Or use brave browser or safari.
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: