|
|
|
@ -6,11 +6,11 @@ fn main() {
|
|
|
|
|
let turns: Vec<(&str, &str)> = lines
|
|
|
|
|
.map(|x| (x.get(0..1).unwrap(), x.get(2..3).unwrap()))
|
|
|
|
|
.collect();
|
|
|
|
|
let scores: Vec<usize> = turns.iter().map(|&x| score_part1(x)).collect();
|
|
|
|
|
let scores: Vec<usize> = turns.iter().map(score_part1).collect();
|
|
|
|
|
let final_score_part1: usize = scores.iter().sum();
|
|
|
|
|
println!("Game 1 score: {final_score_part1}");
|
|
|
|
|
|
|
|
|
|
let scores2: Vec<usize> = turns.iter().map(|&x| score_part2(x)).collect();
|
|
|
|
|
let scores2: Vec<usize> = turns.iter().map(score_part2).collect();
|
|
|
|
|
let final_score_part2: usize = scores2.iter().sum();
|
|
|
|
|
println!("Game 2 score: {:?}", final_score_part2);
|
|
|
|
|
}
|
|
|
|
@ -31,11 +31,11 @@ fn win_points(turn: (&str, &str)) -> usize {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn score_part1(turn: (&str, &str)) -> usize {
|
|
|
|
|
win_points(turn) + type_points(turn.1)
|
|
|
|
|
fn score_part1(turn: &(&str, &str)) -> usize {
|
|
|
|
|
win_points(*turn) + type_points(turn.1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn score_part2(turn: (&str, &str)) -> usize {
|
|
|
|
|
fn score_part2(turn: &(&str, &str)) -> usize {
|
|
|
|
|
let my_move: &str = match turn {
|
|
|
|
|
("A", "X") | ("B", "Z") | ("C", "Y") => "Z", // lose to rock, win to paper, or draw with scissors -> I play scissors
|
|
|
|
|
("A", "Y") | ("B", "X") | ("C", "Z") => "X", // draw with rock, lose to paper, win to scissors -> I play rock
|
|
|
|
|