AoC 2022, day 8

Run Settings
LanguageRaku
Language Version
Run Command
my @trees = $*IN.lines.map({ .comb».Int.Array }).Array; my \rows = +@trees; my \cols = +@trees[0]; put 'part 1: ', 2 * (rows + cols) - 4 + (1..^rows-1 X 1..^cols-1).grep(-> ($r,$c) { @trees[$r;$c] > ( @trees[$r;^$c ].all | @trees[$r;$c^..cols-1].all | @trees[^$r; $c].all | @trees[$r^..rows-1;$c].all ) }); my method viewing-distance(@A : UInt:D $height --> UInt:D) { (@A.first(* ≥ $height, :k) // (+@A - 1)) + 1 } put 'part 2: ', (1..^rows-1 X 1..^cols-1).map(-> ($r,$c) { [*] (@trees[$r;$c^...0], @trees[$r;$c^..cols-1], @trees[$r^...0;$c], @trees[$r^..rows-1;$c] ).map({ .&viewing-distance(@trees[$r;$c]) }) }).max;
Editor Settings
Theme
Key bindings
Full width
Lines