use std::fs; use std::io::{self, BufRead}; #[derive(Debug, PartialEq)] enum Hand { Rock, Paper, Scissors, } fn translate(play: &str) -> Hand { match play { "A" | "X" => Hand::Rock, "B" | "Y" => Hand::Paper, "C" | "Z" => Hand::Scissors, &_ => panic!(), } } fn weight(play: Hand) -> u32 { match play { Hand::Rock => 1, Hand::Paper => 2, Hand::Scissors => 3, } } fn fight(my: Hand, other: Hand) -> u32 { match (my, other) { (a, b) if a == b => 3, (Hand::Rock, Hand::Scissors) | (Hand::Scissors, Hand::Paper) | (Hand::Paper, Hand::Rock) => 6, _ => 0, } } fn main() -> std::io::Result<()> { let file = fs::File::open("input").unwrap(); let lines = io::BufReader::new(file).lines(); let mut score = 0; for line in lines { if let [ot, my] = line?.split_whitespace().collect::>()[..] { score += fight(translate(my), translate(ot)) + weight(translate(my)); } else { todo!() }; } println!("{}", score); Ok(()) }