Files
aoc22/src/bin/d2p1.rs
2022-12-13 14:20:19 +01:00

33 lines
798 B
Rust

use aoc22::day2;
use aoc22::util;
fn parse_choice(choice_char: char) -> day2::Choice {
match choice_char {
'A' => day2::Choice::Rock,
'B' => day2::Choice::Paper,
'C' => day2::Choice::Scissors,
'X' => day2::Choice::Rock,
'Y' => day2::Choice::Paper,
'Z' => day2::Choice::Scissors,
_ => panic!("Unknown choice {}", choice_char),
}
}
fn parse_round(round: &(char, char)) -> day2::Round {
day2::Round {
opponent: parse_choice(round.0),
own: parse_choice(round.1),
}
}
pub fn main() {
let rounds = day2::parse_rounds(&util::parse_input());
let score = rounds
.iter()
.map(parse_round)
.map(|round| round.score())
.sum::<u32>();
println!("Total score is {}", score);
}