diff --git a/rust/src/day25.rs b/rust/src/day25.rs new file mode 100644 index 0000000..7a4858f --- /dev/null +++ b/rust/src/day25.rs @@ -0,0 +1,35 @@ +use std::{time::Duration, time::Instant}; + +const CONSTANT: usize = 20201227; + +pub fn brute_force(card_pubkey: usize) -> usize { + let mut card_loop_size = 0; + let mut value = 1; + while value != card_pubkey { + value = value * 7 % CONSTANT; + card_loop_size += 1; + } + card_loop_size +} + +pub fn run(print: bool) -> Duration { + let file_string = std::fs::read_to_string("../inputs/25").unwrap(); + let instant = Instant::now(); + + let mut lines = file_string.lines(); + let card_pubkey: usize = lines.next().unwrap().trim().parse().unwrap(); + let door_pubkey: usize = lines.next().unwrap().trim().parse().unwrap(); + + let card_loop_size = brute_force(card_pubkey); + + let mut part1 = 1; + for _ in 0..card_loop_size { + part1 = part1 * door_pubkey % CONSTANT; + } + + if print { + dbg!(part1); + } + + instant.elapsed() +} diff --git a/rust/src/main.rs b/rust/src/main.rs index bce626f..9e3e6fc 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -26,7 +26,7 @@ use nop as day21; use nop as day22; mod day23; use nop as day24; -use nop as day25; +mod day25; fn main() { let days = [