use std::fs; pub fn d02() { let path = "res/02/input.txt"; let contents = fs::read_to_string(path).expect("Should have been able to read the file"); let cont_arr = contents.split("\n"); let mut scores = Vec::::new(); cont_arr.clone().into_iter().for_each(|line| { match line { // A/X: Rock 1 // B/Y: Paper 2 // C/Z: Scissors 3 // LOSE 0 // DRAW 3 // WIN 6 "A X" => scores.push(1 + 3), "A Y" => scores.push(2 + 6), "A Z" => scores.push(3 + 0), "B X" => scores.push(1 + 0), "B Y" => scores.push(2 + 3), "B Z" => scores.push(3 + 6), "C X" => scores.push(1 + 6), "C Y" => scores.push(2 + 0), "C Z" => scores.push(3 + 3), _ => {} } }); let sum: i32 = scores.clone().into_iter().sum(); println!("Result 1: {}", sum); // Task 2 scores.clear(); cont_arr.clone().into_iter().for_each(|line| { match line { // A: Rock 1 // B: Paper 2 // C: Scissors 3 // LOSE 0 // DRAW 3 // WIN 6 "A X" => scores.push(3 + 0), "A Y" => scores.push(1 + 3), "A Z" => scores.push(2 + 6), "B X" => scores.push(1 + 0), "B Y" => scores.push(2 + 3), "B Z" => scores.push(3 + 6), "C X" => scores.push(2 + 0), "C Y" => scores.push(3 + 3), "C Z" => scores.push(1 + 6), _ => {} } }); let sum: i32 = scores.clone().into_iter().sum(); println!("Result 2: {}", sum); }