diff options
Diffstat (limited to '2022/day1/part1')
-rw-r--r-- | 2022/day1/part1/Cargo.toml | 9 | ||||
-rw-r--r-- | 2022/day1/part1/example | 14 | ||||
-rw-r--r-- | 2022/day1/part1/src/main.rs | 14 |
3 files changed, 37 insertions, 0 deletions
diff --git a/2022/day1/part1/Cargo.toml b/2022/day1/part1/Cargo.toml new file mode 100644 index 0000000..f14fe90 --- /dev/null +++ b/2022/day1/part1/Cargo.toml | |||
@@ -0,0 +1,9 @@ | |||
1 | [package] | ||
2 | name = "part1" | ||
3 | version = "0.1.0" | ||
4 | edition = "2021" | ||
5 | |||
6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
7 | |||
8 | [dependencies] | ||
9 | itertools = "0.10.5" | ||
diff --git a/2022/day1/part1/example b/2022/day1/part1/example new file mode 100644 index 0000000..2094f91 --- /dev/null +++ b/2022/day1/part1/example | |||
@@ -0,0 +1,14 @@ | |||
1 | 1000 | ||
2 | 2000 | ||
3 | 3000 | ||
4 | |||
5 | 4000 | ||
6 | |||
7 | 5000 | ||
8 | 6000 | ||
9 | |||
10 | 7000 | ||
11 | 8000 | ||
12 | 9000 | ||
13 | |||
14 | 10000 | ||
diff --git a/2022/day1/part1/src/main.rs b/2022/day1/part1/src/main.rs new file mode 100644 index 0000000..637b4e3 --- /dev/null +++ b/2022/day1/part1/src/main.rs | |||
@@ -0,0 +1,14 @@ | |||
1 | use itertools::Itertools; | ||
2 | |||
3 | fn main() { | ||
4 | let input: String = include_str!("../../input").to_string(); | ||
5 | let mut calories: Vec<usize> = Vec::new(); | ||
6 | |||
7 | for (key, group) in &input.lines().group_by(|line| *line != "") { | ||
8 | if key { | ||
9 | calories.push(group.into_iter().map(|i| i.parse::<usize>().unwrap()).sum()); | ||
10 | } | ||
11 | } | ||
12 | |||
13 | println!("{}", calories.iter().max().unwrap()); | ||
14 | } | ||