solution: day25 part1

This commit is contained in:
Matej Janezic 2022-12-13 23:48:23 +01:00
parent 00000400a9
commit 0000041006
Signed by: janezicmatej
GPG Key ID: 4298E230ED37B2C0
2 changed files with 41 additions and 0 deletions

40
src/bin/25.rs Normal file
View File

@ -0,0 +1,40 @@
const ONE: u64 = 20151125;
pub fn part_one(input: &str) -> Option<u64> {
let l = input.len();
let (row, column): (u32, u32) = input[80..l - 1]
.split_once(", column ")
.map(|(x, y)| (x.parse().unwrap(), y.parse().unwrap()))
.unwrap();
let n = (row + column) * (row + column - 1) / 2 - row + 1;
let mut c = 1;
let mut code = ONE;
while c < n {
code = (code * 252533) % 33554393;
c += 1;
}
Some(code)
}
pub fn part_two(input: &str) -> Option<u32> {
None
}
fn main() {
let input = &aoc::read_file("inputs", 25);
aoc::solve!(1, part_one, input);
aoc::solve!(2, part_two, input);
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_part_one() {
let input = aoc::read_file("test_inputs", 25);
assert_eq!(part_one(&input.trim()), Some(7726640));
}
#[test]
fn test_part_two() {
let input = aoc::read_file("test_inputs", 25);
assert_eq!(part_two(&input.trim()), None);
}
}

1
src/test_inputs/25.txt Normal file
View File

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