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::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);
|
||||
|
Loading…
Reference in New Issue
Block a user