Introduction

This post is part of my Advent of Code 2026 series. Before committing to this article, I hope you, the reader, have solved or attempted the puzzle and are using this article as additional learning material to see how I went about solving mine. Whatever the case, Happy New Month 🎉

I can't help but express how much child-like excitement I got reading the prose for the first puzzle. The writing style and choice of words do a lot towards setting the tone for the season and the puzzle's setting. Thingamabobs and Thingamajobs were new words for me!

The puzzle - In plain words

The goal of the puzzle is to find the 3 most common numbers (IDs) in a list of numbers and multiply them together for part 1, then do the same thing for the 3 least common numbers for part 2.

Example:

1
5
4
3
1
7
2
5
1
3

From the list of numbers above, the most common numbers are 1, 5 and 3, appearing 3, 2 and 2 times respectively, so their product is 1 × 5 × 3 = 15. The least common numbers are 4, 7 and 2, appearing once each, so their product is 4 × 7 × 2 = 56. The puzzle provides a very long list of numbers, and the goal is the same, but now with programming logic.

What if two numbers are tied for 3rd place? The puzzle doesn't say how to break a tie, because its answer only makes sense when the top 3 is clear-cut. In the puzzle's own example, the counts are 6, 5, 4 and then 3, so there's a clear gap after 3rd place. My example works the same way: 1, 5 and 3 are the only numbers that appear more than once, and exactly three numbers appear only once.

The solution: In pseudocode

I structure my solution scripts so that they read from a file that contains the input and then perform the analysis on that input.

Step 1: Read input from a file

Here is a cut section of the input for the puzzle:

213
317
772
444
...more lines of IDs

For step one, I read that input into a list of numbers. Notice that by default, values from a file are read as strings in most programming languages, so this is the step to do data cleaning and convert the IDs to integer values.

Step 2: Implement a function that returns the 3 most common items from a collection

Built-in utility

Most programming languages provide some utility that takes in a collection of items and returns a data structure that describes the count of each element in the original collection. For Python, there is the Counter class from the collections module, which does exactly this for you. It even has a most_common() method that returns the elements sorted by count, which covers Step 3 as well:

from collections import Counter

counts = Counter(ids)
top_three = counts.most_common(3)            # [(1, 3), (5, 2), (3, 2)]
bottom_three = counts.most_common()[:-4:-1]  # the 3 least common

For the programming languages that do not have a ready-made utility, it is straightforward to implement this logic yourself, which is the route I took for my solution in Rust.

Custom implementation

Given a collection of numbers, the most straightforward way to count the number of times each number appears is to loop over the collection and use a hashmap or dictionary to keep track of the count, with the number as the key and the count as the value. On the first encounter of a number, you add it to the hashmap, set its value to 0, and then increment by 1.

Pseudocode implementation:

collection = collection_from_step_one()
hashmap = new empty_HashMap()
for each_element in collection
    if each_element is not a key in hashmap already:
       add each_element to the hashmap and set its value to 0

    increment the count (value) for each_element key in the hashmap

At the end of this process, the hashmap should contain all the elements from the input collection as keys, and their values would be the number of times each element appeared in the collection.

Our example list would produce this table:

KeyCount
13
52
41
32
71
21

Step 3: Sort the entries and return the top or bottom 3

A hashmap has no order of its own, so take its key/count pairs, sort them by count, and return the top 3 or bottom 3 keys for the next and final step.

One gotcha in Rust: HashMap iterates in a random order that changes from run to run. If two numbers ever did tie at the cutoff and you sorted by count alone, your answer could change between runs. Adding a tie-breaker on the key makes the sort deterministic:

let mut entries: Vec<(u64, u64)> = counts.into_iter().collect();
// highest count first; equal counts fall back to the smaller ID
entries.sort_by(|a, b| b.1.cmp(&a.1).then(a.0.cmp(&b.0)));

Step 4: Compute the product

For the final step, calculate and return the product of the elements from the previous step. In my own implementation, I avoided a loop at this stage and went with a functional programming approach, reducing the list of the top or bottom 3 elements to a single value. In Python that is math.prod(n for n, _ in top_three), and in Rust it is top_three.iter().product::<u64>().

Conclusion

It's another Advent of Code season and it's the Christmas season, so I am excited. The puzzle for the first day is, unsurprisingly, very easy and straightforward. I look forward to solving those of the coming days with the same excitement and passion. I did revisit a few concepts I had not used in a while. If you want to see my actual code implementation, it is available here on GitHub.

Happy New Month once again 🎉✨

Advent of Code Day One - 2026
https://brianobot.tech/blog/advent-of-code-2026-day-one/
Author Brian Obot
Published December 1, 2026