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 } }