File tree 1 file changed +9
-20
lines changed
1 file changed +9
-20
lines changed Original file line number Diff line number Diff line change 14
14
//! we combine the two times into a single time mod 10403 that is the answer.
15
15
use crate :: util:: iter:: * ;
16
16
use crate :: util:: parse:: * ;
17
+ use std:: cmp:: Ordering :: * ;
17
18
18
19
type Robot = [ usize ; 4 ] ;
19
20
@@ -28,34 +29,22 @@ pub fn parse(input: &str) -> Vec<Robot> {
28
29
}
29
30
30
31
pub fn part1 ( input : & [ Robot ] ) -> i32 {
31
- let mut q1 = 0 ;
32
- let mut q2 = 0 ;
33
- let mut q3 = 0 ;
34
- let mut q4 = 0 ;
32
+ let mut quadrants = [ 0 ; 4 ] ;
35
33
36
34
for [ x, y, dx, dy] in input {
37
35
let x = ( x + 100 * dx) % 101 ;
38
36
let y = ( y + 100 * dy) % 103 ;
39
37
40
- if x < 50 {
41
- if y < 51 {
42
- q1 += 1 ;
43
- }
44
- if y > 51 {
45
- q2 += 1 ;
46
- }
47
- }
48
- if x > 50 {
49
- if y < 51 {
50
- q3 += 1 ;
51
- }
52
- if y > 51 {
53
- q4 += 1 ;
54
- }
38
+ match ( x. cmp ( & 50 ) , y. cmp ( & 51 ) ) {
39
+ ( Less , Less ) => quadrants[ 0 ] += 1 ,
40
+ ( Less , Greater ) => quadrants[ 1 ] += 1 ,
41
+ ( Greater , Less ) => quadrants[ 2 ] += 1 ,
42
+ ( Greater , Greater ) => quadrants[ 3 ] += 1 ,
43
+ _ => ( ) ,
55
44
}
56
45
}
57
46
58
- q1 * q2 * q3 * q4
47
+ quadrants . iter ( ) . product ( )
59
48
}
60
49
61
50
pub fn part2 ( robots : & [ Robot ] ) -> usize {
You can’t perform that action at this time.
0 commit comments