mirror of
https://github.com/Noratrieb/advent-of-code.git
synced 2026-01-14 17:45:02 +01:00
day02p1
This commit is contained in:
parent
2bacc67280
commit
ba8c793c18
7 changed files with 1104 additions and 0 deletions
15
2024/day02/Cargo.toml
Normal file
15
2024/day02/Cargo.toml
Normal 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
|
||||
3
2024/day02/benches/benches.rs
Normal file
3
2024/day02/benches/benches.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fn main() {
|
||||
day02::bench();
|
||||
}
|
||||
1000
2024/day02/input.txt
Normal file
1000
2024/day02/input.txt
Normal file
File diff suppressed because it is too large
Load diff
6
2024/day02/input_small.txt
Normal file
6
2024/day02/input_small.txt
Normal 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
68
2024/day02/src/lib.rs
Normal 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
3
2024/day02/src/main.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fn main() {
|
||||
day02::main();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue