Skip to content

Commit 6cd0d28

Browse files
committed
Day 16
1 parent 704f03a commit 6cd0d28

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

Cargo.lock

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ memoize = "0.4.2"
3232
mygrid = { version = "0.0.1", path = "mygrid" }
3333
nalgebra = "0.33.2"
3434
num = "0.4.3"
35+
object-pool = "0.6.0"
3536
pico-args = "0.5.0"
3637
rayon = "1.10.0"
3738
regex = "1.11.1"

src/bin/16.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use mygrid::{
99
advent_of_code::solution!(16);
1010

1111
pub fn part_one(input: &str) -> Option<u64> {
12+
return None;
13+
1214
let (grid, start) = Grid::new_from_str_capture_start(input, &|c| c, &|c| c == 'S');
1315
let target_pos = grid
1416
.iter_item_and_position()
@@ -83,17 +85,20 @@ pub fn part_two(input: &str) -> Option<u64> {
8385
.next()
8486
.unwrap();
8587

86-
#[derive(Debug, PartialEq, Eq)]
87-
struct State {
88-
path: Vec<Point>,
88+
use object_pool::{Pool, Reusable};
89+
90+
struct State<'a> {
91+
path: Reusable<'a, Vec<Point>>,
8992
pos: Point,
9093
dir: Direction,
9194
cost: u64,
9295
}
9396

94-
let mut q = VecDeque::new();
95-
let mut path = Vec::with_capacity(1024);
97+
let path_pool = Pool::new(32, || Vec::with_capacity(1024));
98+
let mut path = path_pool.pull(|| Vec::with_capacity(1024));
9699
path.push(start);
100+
101+
let mut q = VecDeque::new();
97102
q.push_back(State {
98103
path,
99104
pos: start,
@@ -155,7 +160,9 @@ pub fn part_two(input: &str) -> Option<u64> {
155160
continue;
156161
}
157162

158-
let mut new_path = s.path.clone();
163+
let mut new_path = path_pool.pull(|| Vec::with_capacity(1024));
164+
new_path.clear();
165+
new_path.extend(s.path.iter());
159166
new_path.push(pos);
160167
let new_state = State {
161168
path: new_path,

0 commit comments

Comments
 (0)