Skip to content

Instantly share code, notes, and snippets.

@shaleh
Created December 2, 2022 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaleh/a13367221e8c16f52aea97ca16e8ed96 to your computer and use it in GitHub Desktop.
Save shaleh/a13367221e8c16f52aea97ca16e8ed96 to your computer and use it in GitHub Desktop.
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