This repository has been archived on 2026-12-02. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
aoc2026/src/day1.rs
T
2026-11-30 22:23:42 -07:00

59 lines
878 B
Rust

use aoc_runner_derive::aoc;
use itertools::Itertools;
#[aoc(day1, part1)]
pub fn part1(input: &str) -> u64 {
let ids = input.lines().map(|l| l.parse::<u64>().unwrap()).counts();
ids.iter()
.sorted_by_key(|(_k, v)| *v)
.rev()
.take(3)
.fold(1, |acc, (k, _v)| acc * k)
}
#[aoc(day1, part2)]
pub fn part2(input: &str) -> u64 {
let ids = input.lines().map(|l| l.parse::<u64>().unwrap()).counts();
ids.iter()
.sorted_by_key(|(_k, v)| *v)
.take(3)
.fold(1, |acc, (k, _v)| acc * k)
}
#[cfg(test)]
mod tests {
use crate::day1::*;
const EXAMPLE: &str = "57
57
55
57
76
78
57
45
43
78
43
76
43
78
57
45
57
76
43
43
76";
#[test]
fn problem1_example() {
assert_eq!(part1(EXAMPLE), 186276);
}
#[test]
fn problem2_example() {
assert_eq!(part2(EXAMPLE), 193050);
}
}