From 8b407fe5e037a3ab3d7b8e720dfd20bf3dd25172 Mon Sep 17 00:00:00 2001 From: dolphinau Date: Tue, 2 Dec 2025 13:44:59 +0100 Subject: [PATCH] Add day1 part 2 --- AoC_2025/src/days/day01.rs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/AoC_2025/src/days/day01.rs b/AoC_2025/src/days/day01.rs index 932bd4c..8fe6e36 100644 --- a/AoC_2025/src/days/day01.rs +++ b/AoC_2025/src/days/day01.rs @@ -7,15 +7,15 @@ impl Solution for Day01 { fn parse(&self, data: &str) -> Self::Input { data.split("\n") - .map(|l| { + .filter_map(|l| { let mut chars = l.chars(); let first = chars.next(); let num = chars.collect::().parse::(); match (first, num) { - (Some('L'), Ok(n)) => -1 * n, - (Some('R'), Ok(n)) => n, - _ => 0, + (Some('L'), Ok(n)) => Some(-1 * n), + (Some('R'), Ok(n)) => Some(n), + _ => None, } }) .collect() @@ -32,6 +32,23 @@ impl Solution for Day01 { } fn part2(&self, input: &Self::Input) -> usize { - 0 + input + .iter() + .fold((50, 0), |(pointer, res), x| { + let new_pointer = (pointer + x).rem_euclid(100); + let rem_x = x % 100; + ( + (pointer + x).rem_euclid(100), + res + (x / 100).abs() + + if (pointer != 0 && pointer + rem_x != new_pointer) + || pointer + rem_x == 0 + { + 1 + } else { + 0 + }, + ) + }) + .1 as usize } }