start AOC 2022
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "advent-of-code-2022"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
advent_of_code_macro = { path = "../advent_of_code_macro" }
|
||||
paste = "1.0.9"
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,14 @@
|
||||
1000
|
||||
2000
|
||||
3000
|
||||
|
||||
4000
|
||||
|
||||
5000
|
||||
6000
|
||||
|
||||
7000
|
||||
8000
|
||||
9000
|
||||
|
||||
10000
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,14 @@
|
||||
1000
|
||||
2000
|
||||
3000
|
||||
|
||||
4000
|
||||
|
||||
5000
|
||||
6000
|
||||
|
||||
7000
|
||||
8000
|
||||
9000
|
||||
|
||||
10000
|
||||
@@ -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]
|
||||
);
|
||||
@@ -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]
|
||||
);
|
||||
@@ -0,0 +1,3 @@
|
||||
#[allow(dead_code)]
|
||||
mod day_1;
|
||||
mod day_2;
|
||||
Reference in New Issue
Block a user