git-subtree-dir: 2018 git-subtree-mainline:5ccd921b23
git-subtree-split:4f35fa8515
31 lines
727 B
Rust
31 lines
727 B
Rust
use std::error::Error;
|
|
use std::fs::File;
|
|
use std::io::BufReader;
|
|
use std::io::prelude::*;
|
|
|
|
fn main() -> std::io::Result<()> {
|
|
let file = match File::open("input") {
|
|
// The `description` method of `io::Error` returns a string that describes the error
|
|
Err(why) => panic!("couldn't open input: {}", Error::description(&why)),
|
|
Ok(file) => file,
|
|
};
|
|
|
|
let reader = BufReader::new(file);
|
|
let lines = reader.lines();
|
|
|
|
let mut total: i128 = 0;
|
|
|
|
for result in lines {
|
|
let l = result.unwrap();
|
|
let offset:i128 = i128::from_str_radix(&l, 10).unwrap();
|
|
|
|
println!("{} => {}", l, offset);
|
|
|
|
total = total + offset;
|
|
}
|
|
|
|
println!("{}", total);
|
|
|
|
Ok(())
|
|
}
|