1
0
This commit is contained in:
Jack Bond-Preston 2022-12-23 18:09:40 +00:00
parent 39525852e5
commit c5d6c5142d
Signed by: jack
GPG Key ID: 010071F1482BA852
4 changed files with 2288 additions and 0 deletions

8
day1/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "day1"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

2242
day1/input.txt Normal file

File diff suppressed because it is too large Load Diff

14
day1/sample_input.txt Normal file
View File

@ -0,0 +1,14 @@
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000

24
day1/src/main.rs Normal file
View File

@ -0,0 +1,24 @@
fn main() {
const INPUT: &str = include_str!("../input.txt");
let split = INPUT.split("\n");
let mut calories: Vec<u64> = Vec::new();
let mut running_total: u64 = 0;
for s in split {
if s == "" {
calories.push(running_total);
running_total = 0;
} else {
running_total += s.trim().parse::<u64>().expect("Invalid input line: {s}!");
}
}
let max_calories = calories.iter().max().unwrap();
println!("Max calories: {max_calories}");
calories.sort_by(|a, b| b.cmp(a));
let top_three = calories[0] + calories[1] + calories[2];
println!("Sum of top 3: {top_three}");
}