Created
December 2, 2022 16:39
-
-
Save shaleh/a13367221e8c16f52aea97ca16e8ed96 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let input = read_input(); | |
let sum: u64 = input | |
.iter() | |
.map(|(shape, outcome)| { | |
let action = match outcome { | |
Outcome::Lose => loses_against, | |
Outcome::Draw => draws_against, | |
Outcome::Win => wins_against, | |
}; | |
(action(*shape) as u32 + (*outcome as u32 * 3)) as u64 | |
}) | |
.sum(); | |
println!("Score: {}", sum); | |
} | |
#[cfg(test)] | |
mod tests { | |
use super::*; | |
use quickcheck::{Arbitrary, Gen}; | |
impl Arbitrary for Shape { | |
fn arbitrary(g: &mut Gen) -> Self { | |
let vals = &[ | |
Shape::Rock, | |
Shape::Paper, | |
Shape::Scissors, | |
]; | |
g.choose(vals).expect("choose value").clone() | |
} | |
} | |
quickcheck! { | |
fn prop_inverse(shape: Shape) -> bool { | |
let winner = wins_against(shape); | |
loses_against(winner) == shape | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment