From a202faa7b5f507125fd5846a3392bab07d61bfc1 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Sat, 22 Dec 2018 08:29:39 +0100 Subject: [PATCH] Add more intelligent limits to the playing field. --- 2018/inputs/22.txt | 2 ++ 2018/src/day22.rs | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 2018/inputs/22.txt diff --git a/2018/inputs/22.txt b/2018/inputs/22.txt new file mode 100644 index 0000000..485426c --- /dev/null +++ b/2018/inputs/22.txt @@ -0,0 +1,2 @@ +depth: 8103 +target: 9,758 diff --git a/2018/src/day22.rs b/2018/src/day22.rs index 9aae16e..5cfab02 100644 --- a/2018/src/day22.rs +++ b/2018/src/day22.rs @@ -99,7 +99,7 @@ impl Solution for Day22 { fn part2(&mut self, input: &mut Read) -> String { let (depth, target) = read_input(input); - let mut table = compute_table((1000, 1000), depth); + let mut table = compute_table((target.0 + 100, target.1 + 100), depth); table[target.1][target.0] = 0; let mut todo = BinaryHeap::new(); @@ -137,8 +137,8 @@ impl Solution for Day22 { let xmin = if x == 0 { 0 } else { x - 1 }; let ymin = if y == 0 { 0 } else { y - 1 }; - for xn in xmin..=(x + 1) { - for yn in ymin..=(y + 1) { + for xn in xmin..=(x + 1).min(target.0 + 100) { + for yn in ymin..=(y + 1).min(target.1 + 100) { let new_state = State { pos: (xn, yn), torch: state.torch,