-
Notifications
You must be signed in to change notification settings - Fork 0
/
day15.rs
40 lines (35 loc) · 909 Bytes
/
day15.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
fn task1(mut astate: i64, mut bstate: i64) -> i32 {
let mut sum = 0;
for __i in 0..40_000_000 {
astate = astate * 16807 % 2147483647;
bstate = bstate * 48271 % 2147483647;
if astate & 0xFFFF == bstate & 0xFFFF {
sum += 1;
}
}
sum
}
fn task2(mut astate: i64, mut bstate: i64) -> i32 {
let mut sum = 0;
for __i in 0..5_000_000 {
loop {
astate = astate * 16807 % 2147483647;
if astate & 3 == 0 {
break;
}
}
loop {
bstate = bstate * 48271 % 2147483647;
if bstate & 7 == 0 {
break;
}
}
if astate & 0xFFFF == bstate & 0xFFFF {
sum += 1;
}
}
sum
}
fn main() {
println!("{} {}", task1(277i64, 349i64), task2(277i64, 349i64));
}