2022 - Day 1 part 1 - rust

This commit is contained in:
kleph 2024-12-02 19:29:02 +01:00
parent 940d738c4f
commit 7247e1438b

15
2022/1/1.rs Normal file
View 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);
}