update shorter code
This commit is contained in:
parent
b61d9951a6
commit
8ea82daa5c
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
target/
|
@ -1,9 +1,7 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::File;
|
use std::fs;
|
||||||
use std::io::BufReader;
|
|
||||||
use std::io::BufRead;
|
|
||||||
|
|
||||||
fn score(line: String) -> i64 {
|
fn score(line: &str) -> i64 {
|
||||||
match line.trim() {
|
match line.trim() {
|
||||||
"A X" => 3 + 0,
|
"A X" => 3 + 0,
|
||||||
"A Y" => 1 + 3,
|
"A Y" => 1 + 3,
|
||||||
@ -19,13 +17,11 @@ fn score(line: String) -> i64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Vec<String> = env::args().collect();
|
let input = &env::args().collect::<Vec<String>>()[1];
|
||||||
let input = &args[1];
|
|
||||||
let reader = BufReader::new(File::open(input).expect("where file?"));
|
|
||||||
|
|
||||||
let mut sum = 0;
|
let mut sum = 0;
|
||||||
for line in reader.lines() {
|
for line in fs::read_to_string(input).unwrap().lines() {
|
||||||
sum += score(line.unwrap());
|
sum += score(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Sum: {}", sum);
|
println!("Sum: {}", sum);
|
||||||
|
Loading…
Reference in New Issue
Block a user