aboutsummaryrefslogtreecommitdiff
path: root/2021
diff options
context:
space:
mode:
Diffstat (limited to '2021')
-rw-r--r--2021/05/puzzles.awk16
1 files changed, 8 insertions, 8 deletions
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 {