rust(day25): woo day 25

This commit is contained in:
Sijmen 2020-12-25 21:11:48 +01:00
parent 5fdba801f7
commit fc9cfec98d
Signed by: vijfhoek
GPG Key ID: DAF7821E067D9C48
2 changed files with 36 additions and 1 deletions

35
rust/src/day25.rs Normal file
View File

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

View File

@ -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 = [