diff options
author | j-james | 2022-12-01 06:48:57 +0000 |
---|---|---|
committer | j-james | 2022-12-01 06:48:57 +0000 |
commit | 926b0949d12588641f29836a6e41712b3237b1b9 (patch) | |
tree | 94131d556f67f847de3ad64ae4fdae37ae4888be /2022/rust | |
parent | 6a3c52602974d411c99b312d9ae709e53ef0e29c (diff) |
Day One
Diffstat (limited to '2022/rust')
-rw-r--r-- | 2022/rust/day01/Cargo.lock | 7 | ||||
-rw-r--r-- | 2022/rust/day01/Cargo.toml | 8 | ||||
-rw-r--r-- | 2022/rust/day01/src/main.rs | 14 |
3 files changed, 29 insertions, 0 deletions
diff --git a/2022/rust/day01/Cargo.lock b/2022/rust/day01/Cargo.lock new file mode 100644 index 0000000..683c0b9 --- /dev/null +++ b/2022/rust/day01/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "day01" +version = "0.1.0" diff --git a/2022/rust/day01/Cargo.toml b/2022/rust/day01/Cargo.toml new file mode 100644 index 0000000..5a61072 --- /dev/null +++ b/2022/rust/day01/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "day01" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] 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::<i32>().unwrap()).collect()).collect::<Vec<Vec<i32>>>().iter() + .map(|x| x.iter().fold(0, |x,y| x + y)).collect::<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]); +} |