From f8f24658a0f64bf0e5cc71b7916776a6bcbf4989 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gr=C3=A9gory=20Burri?= Date: Fri, 20 Dec 2019 08:58:30 +0100 Subject: [PATCH] Replace an 'if' by a 'match' --- src/day13.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/day13.rs b/src/day13.rs index 169f4d8..edf2132 100644 --- a/src/day13.rs +++ b/src/day13.rs @@ -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(); -- 2.45.2