From 9b0f2cfdb58a9633a0da2427270fbffd768a90df Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Tue, 19 Dec 2017 10:19:37 +0100 Subject: [PATCH] Even simpler bounds check. --- 2017/day-19/solution.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/2017/day-19/solution.php b/2017/day-19/solution.php index 4207e56..969d5f4 100755 --- a/2017/day-19/solution.php +++ b/2017/day-19/solution.php @@ -11,16 +11,16 @@ $dir = [0, 1]; $path = ''; $steps = 0; -while ($maze[$y][$x] != ' ') { +while (($maze[$y][$x] ?? ' ') != ' ') { if (ctype_alpha($maze[$y][$x])) { $path .= $maze[$y][$x]; } elseif ($maze[$y][$x] == '+') { if ($dir[0] == 0) { - $dir[0] = ($x == 0 || $maze[$y][$x - 1] == ' ') ? 1 : -1; + $dir[0] = ($maze[$y][$x + 1] ?? ' ') == ' ' ? -1 : 1; $dir[1] = 0; } else { $dir[0] = 0; - $dir[1] = ($y == 0 || $maze[$y - 1][$x] == ' ') ? 1 : -1; + $dir[1] = ($maze[$y + 1][$x] ?? ' ') == ' ' ? -1 : 1; } }