From a818d6a1c132c943966d5ee60547cc1630f13a0d Mon Sep 17 00:00:00 2001 From: Andinus Date: Tue, 26 Jan 2021 17:17:30 +0530 Subject: When computing neighbors, set it to an empty array If we don't find any neighbors then we shouldn't have to recompute this result. --- lib/Octans/Neighbors.rakumod | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/Octans/Neighbors.rakumod b/lib/Octans/Neighbors.rakumod index c6f1c00..33dd834 100644 --- a/lib/Octans/Neighbors.rakumod +++ b/lib/Octans/Neighbors.rakumod @@ -20,10 +20,13 @@ sub neighbors ( state Array @neighbors; if @puzzle[$y][$x] { - - # If we've already computed the neighbors then no need to do - # it again. + # Don't re-compute neighbors. unless @neighbors[$y][$x] { + # Set it to an empty array because otherwise if it has no + # neighbors then it would've be recomputed everytime + # neighbors() was called. + @neighbors[$y][$x] = []; + my Int $pos-x; my Int $pos-y; -- cgit 1.4.1-2-gfad0