2022 - Day 1 part 1 - rust
This commit is contained in:
parent
940d738c4f
commit
7247e1438b
1 changed files with 15 additions and 0 deletions
15
2022/1/1.rs
Normal file
15
2022/1/1.rs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
use std::io::{BufRead, BufReader};
|
||||||
|
use std::fs::File;
|
||||||
|
|
||||||
|
fn main (){
|
||||||
|
let filename = "./input_example.txt";
|
||||||
|
let file = BufReader::new(File::open(filename).expect("Unable to open file"));
|
||||||
|
let mut calories = 0;
|
||||||
|
|
||||||
|
for line in file.lines() {
|
||||||
|
let snack_calories : i32 = line.trim().parse().unwrap();
|
||||||
|
calories += snack_calories;
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Total lines are: {}", calories);
|
||||||
|
}
|
Loading…
Reference in a new issue