From 7247e1438b2e6bf1d5ef168a2096e63f3213ce44 Mon Sep 17 00:00:00 2001 From: kleph Date: Mon, 2 Dec 2024 19:29:02 +0100 Subject: [PATCH] 2022 - Day 1 part 1 - rust --- 2022/1/1.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 2022/1/1.rs diff --git a/2022/1/1.rs b/2022/1/1.rs new file mode 100644 index 0000000..aaae68d --- /dev/null +++ b/2022/1/1.rs @@ -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); +}