/// opponent /// R P S /// me A B C /// 1 R X 4 1 7 /// 2 P Y 8 5 2 /// 3 S Z 3 9 6 /// /// idx = 3 * op_idx + my_idx const RPS_RESULTS: [usize; 9] = [4, 1, 7, 8, 5, 2, 3, 9, 6]; 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 }