-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRomuCycleChecker.rs
71 lines (60 loc) · 1.6 KB
/
RomuCycleChecker.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use std::num::Wrapping;
#[inline]
fn rotate_left(d: u64, left_rotate: u64) -> u64 {
let a = d << left_rotate;
let b = d >> (64 - left_rotate);
a | b
}
#[inline]
fn rand_next(state: u64) -> (u64, i32) {
let result = state as i32;
let next_state = Wrapping(15241094284759029579 as u64)
.0
.overflowing_mul(rotate_left(state, 32));
(next_state.0, result)
}
fn check_sequences(numbers: &[i32]) {
let a = numbers[0];
let b = numbers[1];
let c = numbers[2];
let d = numbers[3];
let positions = numbers
.iter()
.enumerate()
.position(|x| x.1 == &a)
.filter(|x| x != &0)
.into_iter()
.collect::<Vec<usize>>();
positions
.into_iter()
.map(|i| {
let aa = numbers[i.clone()];
let bb = numbers[i + 1];
let cc = numbers[i + 2];
let dd = numbers[i + 3];
(
i,
(aa, bb, cc, dd),
aa == a && bb == b && cc == c && dd == d,
)
})
.filter(|x| x.2)
.for_each(|x| println!("Index at {}: {:?} vs {:?}", x.0, x.1, (a, b, c, d)));
}
fn main() {
let seed = 731971696;
let mut state = seed;
let rands = (0..seed)
.into_iter()
.map(|_| {
let (next_state, result) = rand_next(state);
state = next_state;
result
})
.collect::<Vec<i32>>();
let cloned_rands = rands.clone();
let slice = cloned_rands.as_slice();
println!("Checking...");
check_sequences(slice.clone());
println!("Done!");
}