diff --git a/.gitignore b/.gitignore index 99f32d5..c3d6ed8 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,6 @@ Cargo.lock # MSVC Windows builds of rustc generate these, which store debugging information *.pdb -.vscode/ \ No newline at end of file +.vscode/ + +input \ No newline at end of file diff --git a/day_1/src/main.rs b/day_1/src/main.rs index e7a11a9..cc5fd9c 100644 --- a/day_1/src/main.rs +++ b/day_1/src/main.rs @@ -1,3 +1,20 @@ +use std::fs; + +const PATH: &str = "src/input"; + fn main() { - println!("Hello, world!"); + let data = fs::read_to_string(PATH).expect("Error reading file"); + let mut cals_list: Vec = Vec::new(); + let mut cals: u32 = 0; + for line in data.split("\n") { + if line.len() == 0 { + cals_list.push(cals); + cals = 0; + } else { + cals += line.parse::().unwrap(); + } + } + cals_list.sort_by(|a, b| b.cmp(a)); + println!("PART 1: {}", cals_list[0]); + println!("PART 2: {}", cals_list[0] + cals_list[1] + cals_list[2]); }