This commit is contained in:
martijn gerritsen 2025-12-07 22:10:38 +01:00
parent eb4d08968b
commit fad32426b9
7 changed files with 123 additions and 3 deletions

View File

@ -29,6 +29,10 @@ harness = false
name = "bench_aoc_6"
harness = false
[[bench]]
name = "bench_aoc_7"
harness = false
[dependencies]
[profile.bench]
opt-level = 3

View File

@ -3,13 +3,13 @@ use criterion::{criterion_group, criterion_main, Criterion};
use aoc2025::aoc::aoc_6;
fn bench_aoc_6_part1(c: &mut Criterion) {
let input = black_box(include_str!("../src/aoc/input/full_input_aoc5.txt"));
let input = black_box(include_str!("../src/aoc/input/full_input_aoc6.txt"));
c.bench_function("bench_aoc6 part 1", |b| b.iter(|| aoc_6::solve_p1(input)));
}
fn bench_aoc_6_part2(c: &mut Criterion) {
let input = black_box(include_str!("../src/aoc/input/full_input_aoc5.txt"));
c.bench_function("bench_aoc6 part 2", |b| b.iter(|| aoc_6::solve_p2(input)));
let input = black_box(include_str!("../src/aoc/input/full_input_aoc6.txt"));
c.bench_function("bench_aoc6 part 2", |b| b.iter(|| aoc_6::solve_p2_f(input)));
}

17
benches/bench_aoc_7.rs Normal file
View File

@ -0,0 +1,17 @@
use std::hint::black_box;
use criterion::{criterion_group, criterion_main, Criterion};
use aoc2025::aoc::aoc_7;
fn bench_aoc_7_part1(c: &mut Criterion) {
let input = black_box(include_str!("../src/aoc/input/full_input_aoc7.txt"));
c.bench_function("bench_aoc7 part 1", |b| b.iter(|| aoc_7::solve_p1(input)));
}
criterion_group!(
benches_p7,
bench_aoc_7_part1
);
criterion_main!(benches_p7);

View File

@ -4,3 +4,4 @@ pub mod aoc_3;
pub mod aoc_4;
pub mod aoc_5;
pub mod aoc_6;
pub mod aoc_7;

71
src/aoc/aoc_7.rs Normal file
View File

@ -0,0 +1,71 @@
pub fn solve_p1(input: &str) -> u64 {
let mut answer = 0;
let lines = input.lines().count();
let mut data = Vec::new();
for line in input.lines() {
let chars = line.chars().collect::<Vec<char>>();
data.push(chars);
}
let start_idx = data[0].iter().len() / 2 ;
data[1][start_idx] = '|';
for (i,line) in data.clone().iter().enumerate() {
//println!("{:?}", data[i]);
for (j,char) in line.iter().enumerate() {
//println!("{}", data[i][j]);
if data[i][j] == '^' {
if data[i-1][j] == '|' {
answer += 1;
data[i][j+1] = '|';
data[i][j-1] = '|';
data[i+1][j-1] = '|';
data[i+1][j+1] = '|';
}
}
else if data[i][j] == '|' {
if i+1 < data.len() {
if data[i+1][j] != '^' {
data[i+1][j] = '|';
}
}
}
}
}
answer
}
pub fn solve_p2(input: &str) -> u128 {
let mut answer = 0;
let mut data = Vec::new();
for line in input.lines() {
let chars = line.chars().collect::<Vec<char>>();
data.push(chars);
}
let start_idx = data[0].iter().len() / 2 ;
data[1][start_idx] = '|';
answer = traverse(&(1, start_idx), &data);
answer
}
fn traverse(idx : &(usize, usize), data_in: &Vec<Vec<char>>) -> u128 {
let mut count = 0;
if idx.0 +1 >= data_in.len() -6 {
1
}else {
if data_in[idx.0 + 1][idx.1] == '^' {
count += traverse(&(idx.0+2, idx.1 -1), &data_in);
count += traverse(&(idx.0+2, idx.1 +1), &data_in);
return count;
}
count += traverse(&(idx.0+1, idx.1), &data_in);
count
}
}

View File

@ -0,0 +1,16 @@
.......S.......
...............
.......^.......
...............
......^.^......
...............
.....^.^.^.....
...............
....^.^...^....
...............
...^.^...^.^...
...............
..^...^.....^..
...............
.^.^.^.^.^...^.
...............

View File

@ -30,6 +30,7 @@ fn main() {
println!("{}", answer);
*/
/*
let input = include_str!("aoc/input/full_input_aoc6.txt");
let answer = aoc_6::solve_p1(input);
println!("answer: {}", answer);
@ -37,6 +38,16 @@ fn main() {
let input = include_str!("aoc/input/full_input_aoc6.txt");
let answer = aoc_6::solve_p2(input);
println!("answer: {}", answer);
*/
let input = include_str!("aoc/input/full_input_aoc7.txt");
let answer = aoc_7::solve_p1(input);
println!("answer: {}", answer);
let input = include_str!("aoc/input/test_input_aoc7.txt");
let answer = aoc_7::solve_p2(input);
println!("answer: {}", answer);
}
#[test]