Metadata
Date
Tagged
Part of series
Older post
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:
575755577678574543784376437857455776434376Part 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.
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.
pub fn part_2(input: &str) -> i32 { get_counts(input) .iter() .k_smallest_by_key(3, |&(_, n)| n) .map(|(id, _)| id) .product()}Final code
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()}