advent_of_code/2022/1/1.rs

16 lines
416 B
Rust
Raw Normal View History

2024-12-02 19:29:02 +01:00
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);
}