From 6c35a97904187c62d0a2103127f707183b2facaf Mon Sep 17 00:00:00 2001 From: gabe Date: Sat, 3 Dec 2022 02:17:25 -0600 Subject: [PATCH] day 2 now has only a single expression in each function. --- src/day02/utilities.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/day02/utilities.rs b/src/day02/utilities.rs index afeac03..b85b25e 100644 --- a/src/day02/utilities.rs +++ b/src/day02/utilities.rs @@ -12,17 +12,14 @@ pub struct Strategy { } pub fn calc_score(input: &Strategy) -> usize{ - //play enum has value corresponding to its score. - let mut score = input.you as usize; //an enum wins if (you-elf)%3 = 1, looses if it = 2 - let gamestatus = (input.you as i8 - input.elf as i8).rem_euclid(3); - match gamestatus { - 1 => score+=6, - 2 => (), - 0 => score += 3, - _ => panic!("gamestatus was {}!, you were {}, elf was {}", gamestatus, input.you as i8, input.elf as i8) - } - score + (match (input.you as i8 - input.elf as i8).rem_euclid(3) { + 1 => 6, + 2 => 0, + 0 => 3, + _ => unreachable!("you were {}, elf was {}", input.you as i8, input.elf as i8) + //play enum has value corresponding to its score. + })+input.you as usize } #[cfg(test)]