rust(day25): woo day 25
This commit is contained in:
parent
5fdba801f7
commit
fc9cfec98d
|
@ -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()
|
||||
}
|
|
@ -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 = [
|
||||
|
|
Loading…
Reference in New Issue