/// Rock : 1 /// Paper : 2 /// Scissors : 3 /// opponent /// R P S /// me A B C /// _ L X 3 1 2 /// _ D Y 4 5 6 /// _ W Z 8 9 7 /// /// idx = 3 * op_idx + my_idx const RPS_RESULTS: [usize; 9] = [3, 1, 2, 4, 5, 6, 8, 9, 7]; fn main() { let score = include_str!("../../input").lines().fold(0, parse_line); println!("{}", score); } fn parse_line(score: usize, line: &str) -> usize { let mut moves = line.split(' '); let opponent_move = moves.next().unwrap(); let my_move = moves.next().unwrap(); let my_idx = match opponent_move { "A" => 0, "B" => 1, "C" => 2, _ => unreachable!(), }; let op_idx = match my_move { "X" => 0, "Y" => 1, "Z" => 2, _ => unreachable!(), }; RPS_RESULTS[3 * op_idx + my_idx] + score }