Nime
Metadata
Table of contents

Advent of Code 2026 Day 1

Day 1: Dusty Shed

https://adventofcode.com/2026/day/1

And we’re back! This year, you need to help the elves (no? again? really?).

The latest emergency is getting an old train working. This train will be used to gather supplies the elves need.

The elves need to load 6 more types of things on the train. All the containers in the trainyard are labeled with the id of the thing it contains.

Todays input is a list of those IDs for every container in the yard.

An example input looks like this:

input.txt
57
57
55
57
76
78
57
45
43
78
43
76
43
78
57
45
57
76
43
43
76

Part 1

You need to find the contraptions, gizmos, and apparatuses. Those are the 3 most common things.

The question asks for the the product of the 3 most common IDs.

I first counted the occurrences of every thing in the yard, then picked the 3 with the largest count, and multiplied their IDs.

day_01.rs
use itertools::Itertools;
use std::collections::HashMap;
fn get_counts(input: &str) -> HashMap<i32, usize> {
input.lines().map(|s| s.parse().unwrap()).counts()
}
pub fn part_1(input: &str) -> i32 {
get_counts(input)
.iter()
.k_largest_by_key(3, |&(_, n)| n)
.map(|(id, _)| id)
.product()
}

Part 2

Time for the thingamabobs, thingamajigs, and screws. Those are the 3 least common IDs.

I used the same mini-helper from part 1 that gets the occurrences.

day_01.rs
pub fn part_2(input: &str) -> i32 {
get_counts(input)
.iter()
.k_smallest_by_key(3, |&(_, n)| n)
.map(|(id, _)| id)
.product()
}

Final code

day_01.rs
use itertools::Itertools;
use std::collections::HashMap;
fn get_counts(input: &str) -> HashMap<i32, usize> {
input.lines().map(|s| s.parse().unwrap()).counts()
}
pub fn part_1(input: &str) -> i32 {
get_counts(input)
.iter()
.k_largest_by_key(3, |&(_, n)| n)
.map(|(id, _)| id)
.product()
}
pub fn part_2(input: &str) -> i32 {
get_counts(input)
.iter()
.k_smallest_by_key(3, |&(_, n)| n)
.map(|(id, _)| id)
.product()
}