This commit is contained in:
Jonathan Flueren 2022-12-01 17:42:04 +01:00
commit fa59ed6875
6 changed files with 2296 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

7
Cargo.lock generated Normal file
View file

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "AdventOfCode2022"
version = "0.1.0"

8
Cargo.toml Normal file
View file

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

2237
res/01/input.txt Normal file

File diff suppressed because it is too large Load diff

38
src/d01.rs Normal file
View file

@ -0,0 +1,38 @@
use std::fs;
pub fn d01() {
let path = "res/01/input.txt";
let contents = fs::read_to_string(path)
.expect("Should have been able to read the file");
let cont_arr = contents.split("\n");
let mut calories = Vec::<i32>::new();
calories.push(0);
let mut index = 0;
cont_arr.into_iter().for_each(|i| {
if i == "" {
index+=1;
calories.push(0);
} else {
calories[index] += i.parse::<i32>().unwrap();
}
});
let mut max = 0;
calories.clone().into_iter().for_each(|i| {
if i > max {
max = i;
}
});
println!("Result 1: {}", max);
calories.sort();
let res3: i32 = calories.clone().into_iter().rev().take(3).sum();
println!("Result 2: {}", res3);
}

5
src/main.rs Normal file
View file

@ -0,0 +1,5 @@
mod d01;
fn main() {
d01::d01();
}