fn main() { let input = lib::read_input(2); part1(&input); part2(&input); } fn part1(input: &str) { let mut score = 0; for line in input.split("\n") { let mut split = line.split(" ").flat_map(|s| s.chars().next()); let Some(opp) = split.next() else { continue }; let me = split.next().unwrap(); let outcome_score = match (opp, me) { ('A', 'Z') | ('B', 'X') | ('C', 'Y') => 0, ('A', 'X') | ('B', 'Y') | ('C', 'Z') => 3, ('A', 'Y') | ('B', 'Z') | ('C', 'X') => 6, _ => unreachable!(), }; let choice_score = match me { 'X' => 1, 'Y' => 2, 'Z' => 3, _ => unreachable!(), }; score += outcome_score + choice_score; } println!("{}", score); } fn part2(input: &str) { let mut score = 0; for line in input.split("\n") { let mut split = line.split(" ").flat_map(|s| s.chars().next()); let Some(opp) = split.next() else { continue }; let outcome = split.next().unwrap(); let opp = match opp { 'A' => 0, 'B' => 1, 'C' => 2, _ => unreachable!(), }; let (me, outcome_score) = match outcome { 'X' => ((opp - 1 + 3) % 3, 0), 'Y' => (opp, 3), 'Z' => ((opp + 1 + 3) % 3, 6), _ => unreachable!(), }; let choice_score = me + 1; score += outcome_score + choice_score; } println!("{}", score); }