start AOC 2022

This commit is contained in:
2022-12-01 16:48:58 -05:00
parent fd45c3bfb1
commit c58ac4586a
12 changed files with 4676 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
advent_of_code_macro::solve_problem!(
day 1,
Input Vec<Vec<i32>>,
parse |input: &str| {
let lines = input.split('\n');
let mut output = vec![];
let mut curr_elf = vec![];
for line in lines {
if line.is_empty() {
output.push(curr_elf);
curr_elf = vec![];
} else {
curr_elf.push(line.parse().unwrap())
}
}
output
},
part one |data: Input| {
data.iter().map(|cals| cals.iter().sum()).max().unwrap()
},
part two |data: Input| {
use std::mem::swap;
let cals = data.iter().map(|cals| cals.iter().sum()).fold(
(-1, -1, -1),
|(mut first, mut second, mut third), mut curr: i32| {
if curr > first {
swap(&mut first, &mut curr);
}
if curr > second {
swap(&mut second, &mut curr);
}
if curr > third {
swap(&mut third, &mut curr);
}
(first, second, third)
},
);
cals.0 + cals.1 + cals.2
},
sample tests [24_000, 45_000],
star tests [68_923, 200_044]
);
+15
View File
@@ -0,0 +1,15 @@
advent_of_code_macro::solve_problem!(
day 2,
Input i32,
parse |_input: &str| {
1 + 1
},
part one |data: Input| {
data + 5
},
part two |data: Input| {
data + 10
},
sample tests [7, 12],
star tests [7, 12]
);
+3
View File
@@ -0,0 +1,3 @@
#[allow(dead_code)]
mod day_1;
mod day_2;