Skip to content

Commit 988373c

Browse files
committed
Add day 25
1 parent dd64f72 commit 988373c

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

Day25_input.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
15733400
2+
6408062

day25a/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "day25a"
3+
version = "0.1.0"
4+
authors = ["Linus Kardell <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]

day25a/src/main.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use std::io::Read;
2+
3+
fn main() {
4+
const MOD: u32 = 20201227;
5+
const PUB_SUB: u32 = 7;
6+
7+
let mut input = String::new();
8+
std::io::stdin().read_to_string(&mut input).unwrap();
9+
10+
let pub_keys: Vec<u32> = input.lines().map(|line| line.parse().unwrap()).collect();
11+
12+
let loop_size = (1..).try_fold(1, |acc, i| {
13+
let val = acc * PUB_SUB % MOD;
14+
if val == pub_keys[0] {
15+
Err(i)
16+
} else {
17+
Ok(val)
18+
}
19+
}).err().unwrap();
20+
21+
println!("{}", (0..loop_size).fold(1, |acc, _| acc * pub_keys[1] as u64 % MOD as u64));
22+
}

0 commit comments

Comments
 (0)