adventofcode

git clone https://git.ce9e.org/adventofcode.git

commit
9cb36ef0237c27124ed87577e72271249aacf9d5
parent
1e3e6a67ed346ca58e2a001e4126bcd6ae8a86f2
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2026-12-01 06:04
2026-12-01

Diffstat

A 2026/01/solution.rs 23 +++++++++++++++++++++++
A 2026/01/test.txt 21 +++++++++++++++++++++
A 2026/lib.rs 20 ++++++++++++++++++++

3 files changed, 64 insertions, 0 deletions


diff --git a/2026/01/solution.rs b/2026/01/solution.rs

@@ -0,0 +1,23 @@
   -1     1 use std::collections::HashMap;
   -1     2 
   -1     3 #[path = "../lib.rs"]
   -1     4 mod lib;
   -1     5 
   -1     6 fn main() {
   -1     7     let mut counts = HashMap::new();
   -1     8 
   -1     9     for line in lib::iter_input() {
   -1    10         let value = line.parse::<u32>().unwrap();
   -1    11         let count = counts.entry(value).or_insert(0);
   -1    12         *count += 1;
   -1    13     }
   -1    14 
   -1    15     let mut counts_vec: Vec<(usize, u32)> = counts.into_iter().map(|(v, c)| (c, v)).collect();
   -1    16     counts_vec.sort();
   -1    17 
   -1    18     let values: Vec<u32> = counts_vec.into_iter().map(|(_, v)| v).collect();
   -1    19     let n = values.len();
   -1    20 
   -1    21     println!("part1: {}", values[n - 1] * values[n - 2] * values[n - 3]);
   -1    22     println!("part2: {}", values[0] * values[1] * values[2]);
   -1    23 }

diff --git a/2026/01/test.txt b/2026/01/test.txt

@@ -0,0 +1,21 @@
   -1     1 57
   -1     2 57
   -1     3 55
   -1     4 57
   -1     5 76
   -1     6 78
   -1     7 57
   -1     8 45
   -1     9 43
   -1    10 78
   -1    11 43
   -1    12 76
   -1    13 43
   -1    14 78
   -1    15 57
   -1    16 45
   -1    17 57
   -1    18 76
   -1    19 43
   -1    20 43
   -1    21 76

diff --git a/2026/lib.rs b/2026/lib.rs

@@ -0,0 +1,20 @@
   -1     1 use std::env::args;
   -1     2 use std::fs::File;
   -1     3 use std::io::BufRead;
   -1     4 use std::io::BufReader;
   -1     5 
   -1     6 pub fn iter_input() -> impl Iterator<Item = String> {
   -1     7     let path = args().nth(1).unwrap();
   -1     8     let file = File::open(path).unwrap();
   -1     9     return BufReader::new(file).lines().map(|l| l.unwrap());
   -1    10 }
   -1    11 
   -1    12 #[allow(dead_code)]
   -1    13 pub fn div_floor(a: i64, b: i64) -> i64 {
   -1    14     let x = a / b;
   -1    15     if (b > 0 && x * b > a) || (b < 0 && x * b < a) {
   -1    16         return x - 1;
   -1    17     } else {
   -1    18         return x;
   -1    19     }
   -1    20 }