# see for the actual problem to solve: https://adventofcode.com/2022/day/8 use strict; use warnings; use PDL; use PDL::NiceSlice; my $debug = 1; my $x = rcols( *DATA, {COLSEP => qr//}, []); is_visible( $x ); # piddle rotated 90° counterclockwise is_visible( $x->transpose()->slice( ':', '-1:0' ) ); sub is_visible{ my $pdl = shift; print "Working on the piddle: $pdl(skipping first and last rows)\n" if $debug; # # the idea is to consider only rows from second one to last but one foreach my $nrow ( 1 .. nelem($pdl->slice('0,'))-2 ){ # # now the idea is to consider only from second element to last but one print "in ROW $nrow considering only: ", $pdl->slice("1:-2,($nrow)"),"\n" if $debug; # # ..and now checking these elements.. foreach my $to_check ( $pdl->slice("1:-2,($nrow)")->dog ){ print "\tchecking $to_check\n" if $debug; # # ...against all other members of the rows # like in (PSEUDOCODE) assuming @array being the current row # foreach my $idx_to_check ( 1 .. $#array-1 ){ # my $res = map{ my_check( $array[$idx_to_check], $array[$_]) }grep{ $idx_to_check != $_ } 0..$#array; # } } } } __DATA__ 30373 25512 65332 33549 35390