Skip to content

Commit d21a14b

Browse files
committed
Better filter
1 parent 3b5872c commit d21a14b

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

src/day20.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,32 @@ unsafe fn inner_part2(s: &[u8]) -> u32 {
272272
qy.saturating_sub(QUADS_NEEDED)..qy.wrapping_add(QUADS_NEEDED + 1).min(QUADS_SIZE)
273273
{
274274
if qx != qxo && qy != qyo {
275-
let left = (qx * QUAD_SIZE) as i16;
276-
let right = (qx * QUAD_SIZE + QUAD_SIZE - 1) as i16;
277-
let top = (qy * QUAD_SIZE) as i16;
278-
let bottom = (qy * QUAD_SIZE + QUAD_SIZE - 1) as i16;
279-
if ![(left, top), (left, bottom), (right, top), (right, bottom)]
280-
.iter()
281-
.any(|(px, py)| x.abs_diff(*px) + y.abs_diff(*py) <= 20)
282-
{
283-
continue;
275+
if qx < qxo {
276+
let right = (qx * QUAD_SIZE + QUAD_SIZE - 1) as i16;
277+
if qy < qyo {
278+
let bottom = (qy * QUAD_SIZE + QUAD_SIZE - 1) as i16;
279+
if x.abs_diff(right) + y.abs_diff(bottom) > 20 {
280+
continue;
281+
}
282+
} else {
283+
let top = (qy * QUAD_SIZE) as i16;
284+
if x.abs_diff(right) + y.abs_diff(top) > 20 {
285+
continue;
286+
}
287+
}
288+
} else {
289+
let left = (qx * QUAD_SIZE) as i16;
290+
if qy < qyo {
291+
let bottom = (qy * QUAD_SIZE + QUAD_SIZE - 1) as i16;
292+
if x.abs_diff(left) + y.abs_diff(bottom) > 20 {
293+
continue;
294+
}
295+
} else {
296+
let top = (qy * QUAD_SIZE) as i16;
297+
if x.abs_diff(left) + y.abs_diff(top) > 20 {
298+
continue;
299+
}
300+
}
284301
}
285302
}
286303

0 commit comments

Comments
 (0)