This commit is contained in:
Fabian Schmidt 2024-12-04 14:33:50 +01:00
parent 5a17373244
commit b429585457
4 changed files with 55 additions and 12 deletions

View File

@ -0,0 +1 @@
To continue, please consult the code grid in the manual. Enter the code at row 2981, column 3075.

9
y2015/src/bin/d25.rs Normal file
View File

@ -0,0 +1,9 @@
use y2015::days::d25;
fn main() {
part1();
}
fn part1() {
println!("{}", d25::process_part1(3075, 2981));
}

38
y2015/src/days/d25.rs Normal file
View File

@ -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());
}
}

View File

@ -8,7 +8,14 @@ pub mod d15;
pub mod d16; pub mod d16;
pub mod d17; pub mod d17;
pub mod d18; pub mod d18;
pub mod d19;
pub mod d2; 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 d3;
pub mod d4; pub mod d4;
pub mod d5; pub mod d5;
@ -16,15 +23,3 @@ pub mod d6;
pub mod d7; pub mod d7;
pub mod d8; pub mod d8;
pub mod d9; pub mod d9;
pub mod d19;
pub mod d20;
pub mod d21;
pub mod d22;
pub mod d23;
pub mod d24;