GitHub

Day 07 - Solver

Solver Code (src/solvers/day07.ts):

/**
 * Solver for Day 7 of Advent of Code 2025
 *
 * To use this solver:
 * 1. Implement the solve function below
 * 2. The function receives the puzzle input as a string
 * 3. Return the solution (can be a string, number, or object)
 */

function findEmitter(lines: string[]): { row: number; col: number } {
  for (let row = 0; row < lines.length; row++) {
    const col = lines[row].indexOf('S')
    if (col !== -1) {
      return { row, col }
    }
  }
  throw new Error('No emitter "S" found in input')
}

function countSplits(lines: string[], startRow: number, startCol: number): number {
  let splitCount = 0
  let activeBeams = new Set<number>([startCol])

  for (let row = startRow; row < lines.length && activeBeams.size > 0; row++) {
    const line = lines[row]
    const nextBeams = new Set<number>()

    for (const col of activeBeams) {
      if (col < 0 || col >= line.length) continue
      const cell = line[col]

      if (cell === '^') {
        splitCount++
        if (col - 1 >= 0) nextBeams.add(col - 1)
        if (col + 1 < line.length) nextBeams.add(col + 1)
      } else {
        nextBeams.add(col)
      }
    }

    activeBeams = nextBeams
  }

  return splitCount
}

function countQuantumTimelines(
  lines: string[],
  startRow: number,
  startCol: number,
): bigint {
  let activeTimelines = new Map<number, bigint>([[startCol, 1n]])

  for (
    let row = startRow;
    row < lines.length && activeTimelines.size > 0;
    row++
  ) {
    const line = lines[row]
    const nextTimelines = new Map<number, bigint>()

    for (const [col, count] of activeTimelines) {
      if (col < 0 || col >= line.length) continue
      const cell = line[col]

      if (cell === '^') {
        if (col - 1 >= 0) {
          nextTimelines.set(col - 1, (nextTimelines.get(col - 1) ?? 0n) + count)
        }
        if (col + 1 < line.length) {
          nextTimelines.set(col + 1, (nextTimelines.get(col + 1) ?? 0n) + count)
        }
      } else {
        nextTimelines.set(col, (nextTimelines.get(col) ?? 0n) + count)
      }
    }

    activeTimelines = nextTimelines
  }

  let totalTimelines = 0n
  for (const count of activeTimelines.values()) {
    totalTimelines += count
  }
  return totalTimelines
}

export function solve(input: string): Promise<string | number | object> {
  const lines = input
    .trim()
    .split('\n')
    .filter((line) => line.length > 0)

  const { row: startRow, col: startCol } = findEmitter(lines)
  const part1 = countSplits(lines, startRow, startCol)
  const part2 = countQuantumTimelines(lines, startRow, startCol)

  return Promise.resolve({
    part1,
    part2: part2.toString(),
  })
}


How to add your solver:

Create a file at src/solvers/day07.ts with the following structure:

export async function solve(input: string): Promise<string | number | object> {
  // Your solution here
  // The input parameter contains the puzzle input as a string
  
  // Example:
  const lines = input.trim().split('\n');
  
  // Process and return your answer
  return 'Your answer here';
}

Then, import it in src/solvers/index.ts and add it to the solvers object:

import * as day07 from './day07'

export const solvers = {
  // ... existing solvers
  '07': day07,
}

The solver function will receive the puzzle input as a string and should return the solution (string, number, or object).

Day 07 - Advent of Code 2025

--- Day 7: Laboratories ---

--- Day 7: Laboratories ---

You thank the cephalopods for the help and exit the trash compactor, finding yourself in the familiar halls of a North Pole research wing.

Based on the large sign that says "teleporter hub", they seem to be researching teleportation; you can't help but try it for yourself and step onto the large yellow teleporter pad.

Suddenly, you find yourself in an unfamiliar room! The room has no doors; the only way out is the teleporter. Unfortunately, the teleporter seems to be leaking magic smoke.

Since this is a teleporter lab, there are lots of spare parts, manuals, and diagnostic equipment lying around. After connecting one of the diagnostic tools, it helpfully displays error code 0H-N0, which apparently means that there's an issue with one of the tachyon manifolds.

You quickly locate a diagram of the tachyon manifold (your puzzle input). A tachyon beam enters the manifold at the location marked S; tachyon beams always move downward. Tachyon beams pass freely through empty space (.). However, if a tachyon beam encounters a splitter (^), the beam is stopped; instead, a new tachyon beam continues from the immediate left and from the immediate right of the splitter.

For example:

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

In this example, the incoming tachyon beam (|) extends downward from S until it reaches the first splitter:

.......S.......
.......|.......
.......^.......
...............
......^.^......
...............
.....^.^.^.....
...............
....^.^...^....
...............
...^.^...^.^...
...............
..^...^.....^..
...............
.^.^.^.^.^...^.
...............

At that point, the original beam stops, and two new beams are emitted from the splitter:

.......S.......
.......|.......
......|^|......
...............
......^.^......
...............
.....^.^.^.....
...............
....^.^...^....
...............
...^.^...^.^...
...............
..^...^.....^..
...............
.^.^.^.^.^...^.
...............

Those beams continue downward until they reach more splitters:

.......S.......
.......|.......
......|^|......
......|.|......
......^.^......
...............
.....^.^.^.....
...............
....^.^...^....
...............
...^.^...^.^...
...............
..^...^.....^..
...............
.^.^.^.^.^...^.
...............

At this point, the two splitters create a total of only three tachyon beams, since they are both dumping tachyons into the same place between them:

.......S.......
.......|.......
......|^|......
......|.|......
.....|^|^|.....
...............
.....^.^.^.....
...............
....^.^...^....
...............
...^.^...^.^...
...............
..^...^.....^..
...............
.^.^.^.^.^...^.
...............

This process continues until all of the tachyon beams reach a splitter or exit the manifold:

.......S.......
.......|.......
......|^|......
......|.|......
.....|^|^|.....
.....|.|.|.....
....|^|^|^|....
....|.|.|.|....
...|^|^|||^|...
...|.|.|||.|...
..|^|^|||^|^|..
..|.|.|||.|.|..
.|^|||^||.||^|.
.|.|||.||.||.|.
|^|^|^|^|^|||^|
|.|.|.|.|.|||.|

To repair the teleporter, you first need to understand the beam-splitting properties of the tachyon manifold. In this example, a tachyon beam is split a total of 21 times.

Analyze your manifold diagram. How many times will the beam be split?