Day 2, puzzle 2
This commit is contained in:
@ -1,9 +1,32 @@
|
||||
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(day2::Round::score).sum::<u32>();
|
||||
let score = rounds
|
||||
.iter()
|
||||
.map(parse_round)
|
||||
.map(|round| round.score())
|
||||
.sum::<u32>();
|
||||
println!("Total score is {}", score);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user