day 2 now has only a single expression in each function.

This commit is contained in:
gabe 2022-12-03 02:17:25 -06:00
parent d6c9de4f71
commit 6c35a97904

View file

@ -12,17 +12,14 @@ pub struct Strategy {
} }
pub fn calc_score(input: &Strategy) -> usize{ 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 //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 (input.you as i8 - input.elf as i8).rem_euclid(3) {
match gamestatus { 1 => 6,
1 => score+=6, 2 => 0,
2 => (), 0 => 3,
0 => score += 3, _ => unreachable!("you were {}, elf was {}", input.you as i8, input.elf as i8)
_ => panic!("gamestatus was {}!, you were {}, elf was {}", gamestatus, input.you as i8, input.elf as i8) //play enum has value corresponding to its score.
} })+input.you as usize
score
} }
#[cfg(test)] #[cfg(test)]