diff options
author | June McEnroe <june@causal.agency> | 2022-12-08 13:17:33 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2022-12-08 13:17:33 -0500 |
commit | a8ceb21d34bac8227acf7be4dc8c87f404c40555 (patch) | |
tree | 4b79c1fd1a0acf89dadd2c79ef742749b218ef21 /2022 | |
parent | Solve day 8 part 1 (diff) | |
download | aoc-a8ceb21d34bac8227acf7be4dc8c87f404c40555.tar.gz aoc-a8ceb21d34bac8227acf7be4dc8c87f404c40555.zip |
Solve day 8 part 2
Diffstat (limited to '2022')
-rw-r--r-- | 2022/day08.awk | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/2022/day08.awk b/2022/day08.awk index 35505e4..3ce1a50 100644 --- a/2022/day08.awk +++ b/2022/day08.awk @@ -19,6 +19,28 @@ function visible(x, y) { if (yy > bottom) return 1; return 0; } +function view(x, y) { + if (x == 1 || x == right) return 0; + if (y == 1 || y == bottom) return 0; + v = 1; + for (xx = x-1; xx > 1; --xx) { + if (m[xx,y] >= m[x,y]) break; + } + v *= x-xx; + for (xx = x+1; xx < right; ++xx) { + if (m[xx,y] >= m[x,y]) break; + } + v *= xx-x; + for (yy = y-1; yy > 1; --yy) { + if (m[x,yy] >= m[x,y]) break; + } + v *= y-yy; + for (yy = y+1; yy < bottom; ++yy) { + if (m[x,yy] >= m[x,y]) break; + } + v *= yy-y; + return v; +} BEGIN { FS = ""; } @@ -33,7 +55,9 @@ END { for (x = 1; x <= right; ++x) { for (y = 1; y <= bottom; ++y) { if (visible(x, y)) vis++; + if (view(x, y) > max) max = view(x, y); } } print vis; + print max; } |