Skip to content

Commit

Permalink
FINALLY fix day 16
Browse files Browse the repository at this point in the history
  • Loading branch information
ephemient committed Dec 22, 2022
1 parent 6ab1d2d commit aab3aa2
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 36 deletions.
127 changes: 105 additions & 22 deletions rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ static_init = "1.0.3"

[dev-dependencies]
criterion = "0.4.0"
pretty_assertions = "1"
gag = "1.0.0"
pretty_assertions = "1.3.0"

[[bench]]
name = "criterion"
Expand Down
3 changes: 3 additions & 0 deletions rs/benches/criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use aoc2022::{
day20, day21, day3, day4, day5, day6, day7, day8, day9,
};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use gag::Gag;

build_const!("aoc2022");

Expand Down Expand Up @@ -80,10 +81,12 @@ fn aoc2022_bench(c: &mut Criterion) {
b.iter(|| day15::part2(4000000, black_box(DAY15)))
});
g.finish();
let gag = Gag::stderr();
let mut g = c.benchmark_group("day 16");
g.bench_function("part 1", |b| b.iter(|| day16::part1(black_box(DAY16))));
g.bench_function("part 2", |b| b.iter(|| day16::part2(black_box(DAY16))));
g.finish();
drop(gag);
let mut g = c.benchmark_group("day 17");
g.bench_function("part 1", |b| b.iter(|| day17::part1(black_box(DAY17))));
g.bench_function("part 2", |b| b.iter(|| day17::part2(black_box(DAY17))));
Expand Down
16 changes: 3 additions & 13 deletions rs/src/day16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,8 @@ where
}
self.best_estimate = max(self.best_estimate, Some(r));
let (potential, nexts) = (self.next)(&t);
if let Some(potential) = potential {
if let Some(best_estimate) = self.best_estimate {
if potential < best_estimate {
continue;
}
}
if potential.is_some() && potential < self.best_estimate {
continue;
}
for next in nexts {
if !self.seen.contains(&next.1) {
Expand Down Expand Up @@ -147,7 +143,7 @@ where
.get(&(room, valve))
.and_then(|d| d.checked_sub(age))
.filter(|&d| d < state.time)
.map(|d| graph[room].0 * (state.time - d - 1))
.map(|d| graph[valve].0 * (state.time - d - 1))
})
.max()
})
Expand All @@ -162,12 +158,6 @@ where
moves.entry(d).or_insert_with(|| [(); N].map(|_| vec![]))[i].push(valve);
}
}
// if moves
// .iter()
// .all(|(_, moves)| moves.iter().all(|moves| moves.is_empty()))
// {
// return (None, vec![]);
// }
let mut options = vec![];
for (d, moves) in moves {
let mut indices = [None; N];
Expand Down

0 comments on commit aab3aa2

Please sign in to comment.