This commit is contained in:
Dory 2024-03-06 22:39:35 -08:00
parent 79ff128e33
commit b61d9951a6
2 changed files with 39 additions and 6 deletions

View File

@ -5,15 +5,15 @@ use std::io::BufRead;
fn score(line: String) -> i64 { fn score(line: String) -> i64 {
match line.trim() { match line.trim() {
"A X" => 1 + 3, "A X" => 3 + 0,
"A Y" => 2 + 6, "A Y" => 1 + 3,
"A Z" => 3 + 0, "A Z" => 2 + 6,
"B X" => 1 + 0, "B X" => 1 + 0,
"B Y" => 2 + 3, "B Y" => 2 + 3,
"B Z" => 3 + 6, "B Z" => 3 + 6,
"C X" => 1 + 6, "C X" => 2 + 0,
"C Y" => 2 + 0, "C Y" => 3 + 3,
"C Z" => 3 + 3, "C Z" => 1 + 6,
_other => 0, _other => 0,
} }
} }

33
day2/src/main1.rs Normal file
View File

@ -0,0 +1,33 @@
use std::env;
use std::fs::File;
use std::io::BufReader;
use std::io::BufRead;
fn score(line: String) -> i64 {
match line.trim() {
"A X" => 1 + 3,
"A Y" => 2 + 6,
"A Z" => 3 + 0,
"B X" => 1 + 0,
"B Y" => 2 + 3,
"B Z" => 3 + 6,
"C X" => 1 + 6,
"C Y" => 2 + 0,
"C Z" => 3 + 3,
_other => 0,
}
}
fn main() {
let args: Vec<String> = env::args().collect();
let input = &args[1];
let reader = BufReader::new(File::open(input).expect("where file?"));
let mut sum = 0;
for line in reader.lines() {
sum += score(line.unwrap());
}
println!("Sum: {}", sum);
}