This commit is contained in:
nora 2024-12-02 18:56:45 +01:00
parent 2bacc67280
commit ba8c793c18
7 changed files with 1104 additions and 0 deletions

9
2024/Cargo.lock generated
View file

@ -122,6 +122,15 @@ dependencies = [
"rustc-hash", "rustc-hash",
] ]
[[package]]
name = "day02"
version = "0.1.0"
dependencies = [
"divan",
"helper",
"nom",
]
[[package]] [[package]]
name = "divan" name = "divan"
version = "0.1.16" version = "0.1.16"

15
2024/day02/Cargo.toml Normal file
View file

@ -0,0 +1,15 @@
[package]
name = "day02"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
nom.workspace = true
helper.workspace = true
divan.workspace = true
[[bench]]
name = "benches"
harness = false

View file

@ -0,0 +1,3 @@
fn main() {
day02::bench();
}

1000
2024/day02/input.txt Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,6 @@
7 6 4 2 1
1 2 7 8 9
9 7 6 2 1
1 3 2 4 5
8 6 4 4 1
1 3 6 7 9

68
2024/day02/src/lib.rs Normal file
View file

@ -0,0 +1,68 @@
use helper::{parse_unwrap, Day, Variants};
pub fn main() {
helper::main::<Day02>(include_str!("../input.txt"));
}
struct Day02;
helper::define_variants! {
day => crate::Day02;
part1 {
basic => crate::part1;
}
part2 {
basic => crate::part2;
}
}
impl Day for Day02 {
fn part1() -> Variants {
part1_variants!(construct_variants)
}
fn part2() -> Variants {
part2_variants!(construct_variants)
}
}
fn part1(input: &str) -> u64 {
input
.lines()
.filter(|report| {
let levels = report
.split_ascii_whitespace()
.map(parse_unwrap)
.collect::<Vec<_>>();
let increasing = levels
.windows(2)
.all(|ab| ab[0] < ab[1] && ab[0] + 3 >= ab[1]);
if increasing {
return true;
}
let decreasing = levels
.windows(2)
.all(|ab| ab[1] < ab[0] && ab[1] + 3 >= ab[0]);
decreasing
})
.count() as u64
}
fn part2(_input: &str) -> u64 {
0
}
helper::tests! {
day02 Day02;
part1 {
small => 2;
default => 287;
}
part2 {
small => 0;
default => 0;
}
}
helper::benchmarks! {}

3
2024/day02/src/main.rs Normal file
View file

@ -0,0 +1,3 @@
fn main() {
day02::main();
}