From b429585457ab94c8b967079566c9cf092b058035 Mon Sep 17 00:00:00 2001 From: Fabian Schmidt Date: Wed, 4 Dec 2024 14:33:50 +0100 Subject: [PATCH] y2015d25 --- y2015/resources/25_input.txt | 1 + y2015/src/bin/d25.rs | 9 +++++++++ y2015/src/days/d25.rs | 38 ++++++++++++++++++++++++++++++++++++ y2015/src/days/mod.rs | 19 +++++++----------- 4 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 y2015/resources/25_input.txt create mode 100644 y2015/src/bin/d25.rs create mode 100644 y2015/src/days/d25.rs diff --git a/y2015/resources/25_input.txt b/y2015/resources/25_input.txt new file mode 100644 index 0000000..e050407 --- /dev/null +++ b/y2015/resources/25_input.txt @@ -0,0 +1 @@ +To continue, please consult the code grid in the manual. Enter the code at row 2981, column 3075. diff --git a/y2015/src/bin/d25.rs b/y2015/src/bin/d25.rs new file mode 100644 index 0000000..1079835 --- /dev/null +++ b/y2015/src/bin/d25.rs @@ -0,0 +1,9 @@ +use y2015::days::d25; + +fn main() { + part1(); +} + +fn part1() { + println!("{}", d25::process_part1(3075, 2981)); +} diff --git a/y2015/src/days/d25.rs b/y2015/src/days/d25.rs new file mode 100644 index 0000000..de737fc --- /dev/null +++ b/y2015/src/days/d25.rs @@ -0,0 +1,38 @@ +use utils::number::Number; + +// 31562160 too high +pub fn process_part1(x: u32, y: u32) -> Number { + // the grid is actually a pyramid + // 1 + // 2 3 + // 4 5 6 + // etc + // Num on top == 20151125 + let mut current = Number::from(20151125); + let mut starting_y_idx = 2; + loop { + let mut x_idx = 1; + for y_idx in (1..=starting_y_idx).rev() { + current *= Number::from(252533); + current %= Number::from(33554393); + if x_idx == x && y_idx == y { + return current; + } + x_idx += 1; + } + starting_y_idx += 1; + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn part1() { + let result = process_part1(6, 6); + assert_eq!(result, 27995004.into()); + let result = process_part1(1, 2); + assert_eq!(result, 31916031.into()); + } +} diff --git a/y2015/src/days/mod.rs b/y2015/src/days/mod.rs index 164706c..b666fb3 100644 --- a/y2015/src/days/mod.rs +++ b/y2015/src/days/mod.rs @@ -8,7 +8,14 @@ pub mod d15; pub mod d16; pub mod d17; pub mod d18; +pub mod d19; pub mod d2; +pub mod d20; +pub mod d21; +pub mod d22; +pub mod d23; +pub mod d24; +pub mod d25; pub mod d3; pub mod d4; pub mod d5; @@ -16,15 +23,3 @@ pub mod d6; pub mod d7; pub mod d8; pub mod d9; - -pub mod d19; - -pub mod d20; - -pub mod d21; - -pub mod d22; - -pub mod d23; - -pub mod d24;