The Problem

You're in a teleporter lab with a broken tachyon manifold. A tachyon beam enters at position S and travels downward through the manifold. When it hits a splitter (^), it stops and emits two new beams: one to the left and one to the right.

Summary

Part

Question

Strategy

1

How many times is the beam split?

Track unique beam positions, count splits

2

How many timelines exist at the end?

Track particle counts per position (many-worlds)

Part 1: Count the Splits

Goal: Count how many times any tachyon beam is split by a ^ splitter.

The Key Insight: Beams Can Merge

Multiple beams can converge on the same column position. When two beams hit adjacent splitters, they might both emit into the same middle column:

Tachyon Manifold
Row1/16
Beams1
Splits0
Timelines1
.......S.......×1
...............
.......^.......
...............
......^.^......
...............
.....^.^.^.....
...............
....^.^...^....
...............
...^.^...^.^...
...............
..^...^.....^..
...............
.^.^.^.^.^...^.
...............
Event Log
Waiting for beam...

Using a Set for beam positions handles this naturally - duplicates are ignored.

let activeBeams = new Set<number>();
activeBeams.add(startCol);

for (let row = 1; row < height; row++) {
    const newBeams = new Set<number>();

    for (const col of activeBeams) {
        if (grid[row]?.[col] !== SPLITTER) {
            newBeams.add(col);  // Beam passes through
            continue;
        }

        splits++;  // Count this split!
        if (col - 1 >= 0) newBeams.add(col - 1);
        if (col + 1 < width) newBeams.add(col + 1);
    }

    activeBeams = newBeams;
}

Part 2: Many-Worlds Interpretation 🌌

Goal: Instead of counting splits, count total timelines at the end.

Now we're dealing with quantum mechanics! Each split creates a fork in time - one timeline where the particle went left, another where it went right.

The Twist: Convergence Creates Parallel Histories

Two particles arriving at the same position are not the same timeline. They took different paths to get there!

Tachyon Manifold
Row1/16
Beams1
Splits0
Timelines1
.......S.......×1
...............
.......^.......
...............
......^.^......
...............
.....^.^.^.....
...............
....^.^...^....
...............
...^.^...^.^...
...............
..^...^.....^..
...............
.^.^.^.^.^...^.
...............
Event Log
Waiting for beam...

The Solution: Count, Don't Just Track

Instead of a Set (which deduplicates), use a Map that tracks how many particles are at each position:

let particles = new Map<number, number>();
particles.set(startCol, 1);  // One particle starts the journey

for (let row = 1; row < height; row++) {
    const newParticles = new Map<number, number>();

    for (const [col, count] of particles) {
        if (grid[row]?.[col] !== SPLITTER) {
            // Pass through: all particles continue
            newParticles.set(col, (newParticles.get(col) ?? 0) + count);
            continue;
        }

        // Split: each particle creates two timelines
        if (col - 1 >= 0) {
            newParticles.set(col - 1, (newParticles.get(col - 1) ?? 0) + count);
        }
        if (col + 1 < width) {
            newParticles.set(col + 1, (newParticles.get(col + 1) ?? 0) + count);
        }
    }

    particles = newParticles;
}

Why This Works

  • Part 1: We only care about where beams are (Set deduplicates)

  • Part 2: We care about how many particles (Map accumulates)

Each split doubles the number of timelines passing through that splitter. The final answer is the sum of all particle counts at the bottom of the manifold.

Performance

Part

Time

Part 1

884µs

Part 2

1.23ms

Both parts are blazing fast because we process row-by-row, only tracking active positions rather than simulating every possible path explicitly.