From 32c8ac4d91ae26f07c54203886fbf9c7a2bb221a Mon Sep 17 00:00:00 2001
From: Thomas Voss <thomasvoss@live.com>
Date: Sun, 5 Dec 2021 06:54:15 +0100
Subject: Minor code cleanup

---
 2021/05/puzzles.awk | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

(limited to '2021')

diff --git a/2021/05/puzzles.awk b/2021/05/puzzles.awk
index 976b6aa..5710a92 100644
--- a/2021/05/puzzles.awk
+++ b/2021/05/puzzles.awk
@@ -2,16 +2,16 @@
 
 BEGIN { FS = ",| -> " }
 
-$1 == $3 && $2 <= $4 { for (i = $2; i <= $4; i++) grid[i][$1]++; next }
-$1 == $3             { for (i = $4; i <= $2; i++) grid[i][$1]++; next }
-$2 == $4 && $1 <= $3 { for (i = $1; i <= $3; i++) grid[$2][i]++; next }
-$2 == $4             { for (i = $3; i <= $1; i++) grid[$2][i]++; next }
+$1 == $3 && $2 <= $4 { while ($2 <= $4) grid[$2++][$1]++; next }
+$1 == $3             { while ($4 <= $2) grid[$4++][$1]++; next }
+$2 == $4 && $1 <= $3 { while ($1 <= $3) grid[$2][$1++]++; next }
+$2 == $4             { while ($3 <= $1) grid[$2][$3++]++; next }
 
 # START PART 2
-$1 <= $3 && $2 <= $4 { while (!($1 > $3)) { grid[$2][$1]++; $1++; $2++ } next }
-$1 <= $3             { while (!($1 > $3)) { grid[$2][$1]++; $1++; $2-- } next }
-$2 <= $4             { while (!($1 < $3)) { grid[$2][$1]++; $1--; $2++ } next }
-                     { while (!($1 < $3)) { grid[$2][$1]++; $1--; $2-- } next }
+$1 <= $3 && $2 <= $4 { while (!($1 > $3)) grid[$2++][$1++]++; next }
+$1 <= $3             { while (!($1 > $3)) grid[$2--][$1++]++; next }
+$2 <= $4             { while (!($1 < $3)) grid[$2++][$1--]++; next }
+                     { while (!($1 < $3)) grid[$2--][$1--]++; next }
 # END PART 2
 
 END {
-- 
cgit v1.2.3