diff options
author | Thomas Voss <thomasvoss@live.com> | 2021-12-05 06:54:15 +0100 |
---|---|---|
committer | Thomas Voss <thomasvoss@live.com> | 2021-12-05 06:54:15 +0100 |
commit | 32c8ac4d91ae26f07c54203886fbf9c7a2bb221a (patch) | |
tree | a761b6245301dee4b381408b788f461d3efae321 /2021 | |
parent | 5cf278d358e0b267b70d63bc72ae1effdb85a882 (diff) |
Minor code cleanup
Diffstat (limited to '2021')
-rw-r--r-- | 2021/05/puzzles.awk | 16 |
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 { |