update shorter code

This commit is contained in:
Dory 2024-03-07 09:03:04 -08:00
parent b61d9951a6
commit 8ea82daa5c
2 changed files with 6 additions and 9 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
target/

View File

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