File tree Expand file tree Collapse file tree 1 file changed +9
-20
lines changed Expand file tree Collapse file tree 1 file changed +9
-20
lines changed Original file line number Diff line number Diff line change 1414//! we combine the two times into a single time mod 10403 that is the answer.
1515use crate :: util:: iter:: * ;
1616use crate :: util:: parse:: * ;
17+ use std:: cmp:: Ordering :: * ;
1718
1819type Robot = [ usize ; 4 ] ;
1920
@@ -28,34 +29,22 @@ pub fn parse(input: &str) -> Vec<Robot> {
2829}
2930
3031pub 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 ] ;
3533
3634 for [ x, y, dx, dy] in input {
3735 let x = ( x + 100 * dx) % 101 ;
3836 let y = ( y + 100 * dy) % 103 ;
3937
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+ _ => ( ) ,
5544 }
5645 }
5746
58- q1 * q2 * q3 * q4
47+ quadrants . iter ( ) . product ( )
5948}
6049
6150pub fn part2 ( robots : & [ Robot ] ) -> usize {
You can’t perform that action at this time.
0 commit comments