File tree 2 files changed +36
-0
lines changed
2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ pub fn part1 ( door_public_key : u64 , card_public_key : u64 ) -> u64 {
2
+ let mut loop_size = 0 ;
3
+ let mut public_key = 1 ;
4
+
5
+ while public_key != door_public_key && public_key != card_public_key {
6
+ public_key = ( public_key * 7 ) % 20201227 ;
7
+ loop_size += 1 ;
8
+ }
9
+
10
+ let subject_number = if public_key == door_public_key {
11
+ card_public_key
12
+ } else {
13
+ door_public_key
14
+ } ;
15
+
16
+ let mut encryption_key = 1 ;
17
+
18
+ while loop_size != 0 {
19
+ encryption_key = ( encryption_key * subject_number) % 20201227 ;
20
+ loop_size -= 1 ;
21
+ }
22
+
23
+ encryption_key
24
+ }
25
+
26
+ #[ cfg( test) ]
27
+ mod tests {
28
+ use super :: * ;
29
+
30
+ #[ test]
31
+ fn part1_works ( ) {
32
+ assert_eq ! ( part1( 5764801 , 17807724 ) , 14897079 ) ;
33
+ assert_eq ! ( part1( 1614360 , 7734663 ) , 5414549 ) ;
34
+ }
35
+ }
Original file line number Diff line number Diff line change @@ -22,3 +22,4 @@ pub mod day21;
22
22
pub mod day22;
23
23
pub mod day23;
24
24
pub mod day24;
25
+ pub mod day25;
You can’t perform that action at this time.
0 commit comments