From 926b0949d12588641f29836a6e41712b3237b1b9 Mon Sep 17 00:00:00 2001 From: j-james Date: Wed, 30 Nov 2022 22:48:57 -0800 Subject: Day One --- 2022/rust/day01/src/main.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 2022/rust/day01/src/main.rs (limited to '2022/rust/day01/src') diff --git a/2022/rust/day01/src/main.rs b/2022/rust/day01/src/main.rs new file mode 100644 index 0000000..d8a6b9c --- /dev/null +++ b/2022/rust/day01/src/main.rs @@ -0,0 +1,14 @@ +use std::env; +use std::fs; + +fn main() { + let args = env::args().nth(1).unwrap(); + let mut input = fs::read_to_string(args).unwrap().trim().split("\n\n").map(|x| x.trim().split("\n") + .map(|x| x.parse::().unwrap()).collect()).collect::>>().iter() + .map(|x| x.iter().fold(0, |x,y| x + y)).collect::>(); + // println!("{:?}", input); + println!("{}", input.iter().fold(0, |x,y| x.max(*y))); + + input.sort_by(|x,y| y.cmp(x)); + println!("{}", input[0] + input[1] + input[2]); +} -- cgit v1.2.3-70-g09d2