aboutsummaryrefslogtreecommitdiff
path: root/2022/rust/day01/src
diff options
context:
space:
mode:
authorj-james2022-12-05 07:17:33 +0000
committerj-james2022-12-05 07:17:33 +0000
commitc278475cbbb71cbe182adcb1bc5776fa1f492655 (patch)
tree42689543d86f027da49fa147d0c4516af2b470b8 /2022/rust/day01/src
parentfb2dd0f45fa8f8a1045ee9c76c1bca3cc71cb0ef (diff)
Clean up Day One
Diffstat (limited to '2022/rust/day01/src')
-rw-r--r--2022/rust/day01/src/main.rs15
1 files changed, 9 insertions, 6 deletions
diff --git a/2022/rust/day01/src/main.rs b/2022/rust/day01/src/main.rs
index d8a6b9c..2b5a773 100644
--- a/2022/rust/day01/src/main.rs
+++ b/2022/rust/day01/src/main.rs
@@ -3,12 +3,15 @@ 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::<i32>().unwrap()).collect()).collect::<Vec<Vec<i32>>>().iter()
- .map(|x| x.iter().fold(0, |x,y| x + y)).collect::<Vec<i32>>();
+ let input = fs::read_to_string(args).unwrap().trim().split("\n\n")
+ .map(|x| x.trim().split("\n").map(|x| x.parse::<i32>().unwrap())
+ .collect()).collect::<Vec<Vec<i32>>>();
// 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]);
+ let mut elves = input.iter().map(|x| x.iter().fold(0, |x,y| x + y))
+ .collect::<Vec<i32>>();
+ println!("{}", elves.iter().fold(0, |x,y| x.max(*y)));
+
+ elves.sort_by(|x,y| y.cmp(x));
+ println!("{}", elves[0] + elves[1] + elves[2]);
}