Replace an 'if' by a 'match'
authorGrégory Burri <gregory.burri@matisa.ch>
Fri, 20 Dec 2019 07:58:30 +0000 (08:58 +0100)
committerGrégory Burri <gregory.burri@matisa.ch>
Fri, 20 Dec 2019 07:58:30 +0000 (08:58 +0100)
src/day13.rs

index 169f4d8..edf2132 100644 (file)
@@ -1,4 +1,5 @@
 use super::intcode;
+use std::cmp::Ordering;
 use std::convert::TryFrom;
 use itertools::Itertools;
 use num_enum::TryFromPrimitive;
@@ -52,12 +53,10 @@ impl intcode::IO for State {
                     self.paddle_position_x = self.buffer[0];
                 }
                 self.joystick =
-                    if self.paddle_position_x > self.ball_position_x {
-                        -1
-                    } else if self.paddle_position_x < self.ball_position_x {
-                        1
-                    } else {
-                        0
+                    match self.paddle_position_x.cmp(&self.ball_position_x) {
+                        Ordering::Greater => -1,
+                        Ordering::Less => 1,
+                        Ordering::Equal => 0
                     };
             }
             self.buffer.clear();