From bbf8ad85e45bfa5846ba0d7a2f74a4e9fb81d3de Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Tue, 19 Dec 2017 10:16:24 +0100 Subject: [PATCH] Slightly simpler bounds check. --- 2017/day-19/solution.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/2017/day-19/solution.php b/2017/day-19/solution.php index 3f19dea..4207e56 100755 --- a/2017/day-19/solution.php +++ b/2017/day-19/solution.php @@ -16,11 +16,11 @@ while ($maze[$y][$x] != ' ') { $path .= $maze[$y][$x]; } elseif ($maze[$y][$x] == '+') { if ($dir[0] == 0) { - $dir[0] = ($x + 1 >= strlen($maze[$y]) || $maze[$y][$x + 1] == ' ') ? -1 : 1; + $dir[0] = ($x == 0 || $maze[$y][$x - 1] == ' ') ? 1 : -1; $dir[1] = 0; } else { $dir[0] = 0; - $dir[1] = ($y + 1 >= count($maze) || $maze[$y + 1][$x] == ' ') ? -1 : 1; + $dir[1] = ($y == 0 || $maze[$y - 1][$x] == ' ') ? 1 : -1; } }