December ProofsEDITION / 2026

DAY 01 ADVENT OF CODE 2026

Dusty Shed.

A retired Christmas train. A shed full of anonymous crates. A lesson in finding what matters by counting what repeats.

A green steam locomotive and red carriage emerge from a snow-covered wooden shed.
FIG. 01 THE NORTH POLE BACKUP PLAN

01 THE PUZZLE

The inventory problem.

Storms have grounded the North Pole's supply planes. The Elves bring an old train out of retirement so they can restock by December 12. Six types of supplies are still missing, and the labels on the containers are just numbers: the records that say what those numbers mean are gone.

The Elves remember three items being abundant and three being scarce. Count each distinct ID, sort those counts, and multiply the three selected IDs, not their counts. Once sorted, nothing outside the first three can outrank a selected ID. For ties, the solver puts the lower numeric ID first.

Read the original puzzle on Advent of Code

Part One

Most common IDs

Puzzle answer
281,965,740
Sample result
186,276

Part Two

Least common IDs

Puzzle answer
143,638,748
Sample result
193,050

02 THE INTERACTIVE LAB

Walk through the sample.

Start with the puzzle's example or bring your own IDs. Choose a part and see which solver code takes the data from input to answer.

LIVE WORKBENCH

Separate whole-number IDs with spaces or new lines.

PERFORMANCE

How long did it take?

Measure both parts on the current input. Try a larger input to see how runtime changes.

03 THE IMPLEMENTATION

How the code works.

The workbench runs the same TypeScript calculation as the two command-line solutions. Each block below pairs the real source with an explanation of what it does and why.

base.tsShared solver
  1. LINE 1

    Bring in the counting tools

    Remeda provides three operations we need: count repeated items, turn that count object into pairs, and sort the pairs by more than one key.

    import { countBy, entries, sortBy } from "remeda";
  2. LINES 3–11

    Read and validate the labels

    Split at whitespace, so a space works just as well as a new line. Check each token is a decimal integer that JavaScript can represent exactly; otherwise stop and name the bad token. Keep duplicates because every label still needs to be counted.

    export function parseIds(input: string): readonly number[] {
      return input.trim().split(/\s+/).map((token) => {
        const id = Number(token);
        if (!/^[+-]?\d+$/.test(token) || !Number.isSafeInteger(id)) {
          throw new Error(`Invalid ID: ${JSON.stringify(token)}`);
        }
        return id;
      });
    }
  3. LINES 13–22

    Count the IDs, then rank them

    Use each ID as the grouping key, then turn the resulting counts into [ID, count] pairs. Sort by count in the direction the caller requests. If counts tie, compare IDs as numbers so 2 comes before 10, not after.

    export function analyzeFrequencies(
      ids: readonly number[],
      order: "asc" | "desc",
    ) {
      const counts = countBy(ids, (id) => id);
      const ranked = sortBy(
        entries(counts),
        [([, count]) => count, order],
        ([id]) => Number(id),
      );
  4. LINES 24–26

    Check there are three distinct IDs

    Three labels are not necessarily three IDs: 57, 57, 43 would give only two ranked entries. Reject that input rather than silently multiplying fewer than three IDs.

      if (ranked.length < 3) {
        throw new Error("Expected at least three distinct IDs");
      }
  5. LINES 28–31

    Take three and multiply their labels

    The first three entries are already the ones we want. Multiply their IDs, not the counts, using 1 as the starting value. Return the ranking and selection as well as the product so the workbench can show all three.

      const selected = ranked.slice(0, 3);
      const product = selected.reduce((total, [id]) => total * Number(id), 1);
      return { ranked, selected, product };
    }
  6. LINES 33–39

    Choose a direction for each part

    Both wrappers use the same calculation. Part One puts larger counts first; Part Two puts smaller counts first. The command-line solutions only need the resulting number.

    export function topThreeProduct(ids: readonly number[]): number {
      return analyzeFrequencies(ids, "desc").product;
    }
    
    export function leastThreeProduct(ids: readonly number[]): number {
      return analyzeFrequencies(ids, "asc").product;
    }
challenge-01.tsPart One entry point
  1. LINES 1–3

    Load the private input

    Import the shared parser and Part One solver, then use Bun to read the input file next to the script. The website does not load this file.

    import { parseIds, topThreeProduct } from "./base";
    
    const input = await Bun.file(`${import.meta.dir}/input.txt`).text();
  2. LINE 4

    Print the most-common product

    Parse the labels, run the descending-count calculation, and print the product of the three most frequent IDs.

    console.log(topThreeProduct(parseIds(input)));
challenge-02.tsPart Two entry point
  1. LINES 1–3

    Load the same input

    Use the shared parser and the same private file as Part One, but import the least-common solver.

    import { leastThreeProduct, parseIds } from "./base";
    
    const input = await Bun.file(`${import.meta.dir}/input.txt`).text();
  2. LINE 4

    Print the least-common product

    Parse the labels, run the ascending-count calculation, and print the product of the three least frequent IDs.

    console.log(leastThreeProduct(parseIds(input)));

04 THE PUZZLE LOG

December 2026.

Published proofs, in order. New days will be added as they are solved.