File tree Expand file tree Collapse file tree 1 file changed +7
-11
lines changed Expand file tree Collapse file tree 1 file changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -27,23 +27,19 @@ impl Day22 {
27
27
let mut next_secrets = Vec :: new ( ) ;
28
28
29
29
for _ in 0 ..number_of_secrets {
30
- let tmp = secret * 64 ;
31
- secret ^= tmp;
32
- secret %= 16777216 ;
33
-
34
- let tmp = secret / 32 ;
35
- secret ^= tmp;
36
- secret %= 16777216 ;
37
-
38
- let tmp = secret * 2048 ;
39
- secret ^= tmp;
40
- secret %= 16777216 ;
30
+ secret = self . mix_and_prune ( secret, |s| s * 64 ) ;
31
+ secret = self . mix_and_prune ( secret, |s| s / 32 ) ;
32
+ secret = self . mix_and_prune ( secret, |s| s * 2048 ) ;
41
33
42
34
next_secrets. push ( secret) ;
43
35
}
44
36
45
37
next_secrets
46
38
}
39
+
40
+ fn mix_and_prune ( & self , current : usize , calculations : fn ( usize ) -> usize ) -> usize {
41
+ ( current ^ calculations ( current) ) % 16777216
42
+ }
47
43
}
48
44
49
45
#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments