Part 1
The problem asks us to count how many times tachyon beams are split as they travel downward through a grid containing
splitters (^). To solve Part 1:
- We locate the starting beam column marked by
Son the top row and initialize a set of active beam column indices. - We simulate beam propagation row-by-row down the grid.
- For each active column, if a beam encounters a splitter (
^), we increment our split counter and spawn new beams at column indicesc - 1andc + 1. Otherwise, the beam continues directly down columnc. - Using a
Setfor active column indices naturally deduplicates beams that land in the same column at the same time. - Finally, we return the total count of split events once all beams exit the grid.
Part 2
In Part 2, quantum tachyon splitting dictates that every beam reaching a splitter splits timeline history itself, requiring us to count all distinct timeline paths through the manifold. To compute the total active quantum timelines:
- Instead of tracking unique beam positions, we maintain a frequency map (
Map<Int, Long>) of active timeline counts per column index, starting with1timeline at the starting columnS. - As we propagate row-by-row, any timeline hitting a splitter (
^) adds its current count to both adjacent columns (c - 1andc + 1) for the next row. - Columns without splitters simply carry their full timeline count straight down to the next row.
- Using
Longvalues prevents integer overflow caused by the exponential growth of quantum paths. - Finally, we sum the timeline counts across all active columns after processing the last row.