This commit is contained in:
Martijn Gerritsen 2025-12-08 16:42:42 +01:00
parent b0bde44ff4
commit 6465a1597a
2 changed files with 9 additions and 7 deletions

View File

@ -8,7 +8,7 @@ fn bench_aoc_7_part1(c: &mut Criterion) {
}
fn bench_aoc_7_part2(c: &mut Criterion) {
let input = black_box(include_str!("../src/aoc/input/full_input_aoc7.txt"));
let input = black_box(include_bytes!("../src/aoc/input/full_input_aoc7.txt"));
c.bench_function("bench_aoc7 part 2", |b| b.iter(|| aoc_7::solve_p2(input)));
}

View File

@ -39,28 +39,30 @@ pub fn solve_p1(input: &str) -> u64 {
answer
}
pub fn solve_p2(input: &str) -> u64 {
pub fn solve_p2(input: &[u8]) -> u64 {
let mut answer = 0;
let mut data = Vec::with_capacity(256);
for line in input.lines() {
let chars = line.bytes().map(|mut x| {if x == b'.' {x = 0; x as u64} else {x as u64}}).collect::<Vec<u64>>();
for line in input.split(|x1| {*x1 == b'\n'}).step_by(1) {
let chars = line.into_iter().map(|mut x| {if x == &b'.' {x = &0; *x as u64} else {*x as u64}}).collect::<Vec<u64>>();
data.push(chars);
}
let start_idx = data[0].iter().len() / 2 ;
data[0][start_idx] = 1;
for (i,line) in data.clone().iter().enumerate() {
for i in 0..data.len() {
//println!("{:?}", data[i]);
for (j,char) in line.iter().enumerate() {
for j in 0..data[0].len(){
//println!("{}", data[i][j]);
if data[i][j] == 94 {
data[i][j] = 0;
//println!("{}", data[i][j]);
if data[i-1][j] != 0 {
if data[i-1][j] != 0 || data[i][j-1] == 49 {
//println!("{}", data[i-1][j]);
let power = data[i-1][j];
data[i][j-1] += power;
data[i][j+1] += power;
data[i+1][j-1] = data[i][j-1];
data[i+1][j+1] = data[i][j+1];