Discipulus has asked for the wisdom of the Perl Monks concerning the following question:
Inspired by this post and by the underlying forest problem I had the genial ( grin ;) idea of just making the check horizontally and then repeat it on a rotated by 90° AoA.
Rotating the AoA lead me to PDL and here troubles and stumbling started.
Firstly because once something is a piddle I cannot anymore use it as a comfortable perl datastrucure: if my piddle is a 2d array and I take a slice of it, a row, then I cannot use it as an array: @{ $x->slice('0,') } gives a nasty not an array reference error.
But I insisted and now I have the following code:
# see for the actual problem to solve: https://adventofcode.com/2022/d +ay/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 on +e 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,($n +row)"),"\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 r +ow # foreach my $idx_to_check ( 1 .. $#array-1 ){ # my $res = map{ my_check( $array[$idx_to_check], $arr +ay[$_]) }grep{ $idx_to_check != $_ } 0..$#array; # } } } } __DATA__ 30373 25512 65332 33549 35390
In the meanwhile his Anonymousness posted a PDL solution to the problem, code I dont understand at all.
Can someone be so kind to guide me expanding my own solution? If such is possible I'd like it explained plainly, just to let me understanding PDL a bit more.
As side note I have found PDL QuickRef but I suspect some syntax has changed in PDL since then (would be nice to have an updated version of this ;) and this tutorial
Thanks for reading
L*
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: first stumbling steps in PDL
by karlgoethebier (Abbot) on Dec 15, 2022 at 13:56 UTC | |
Re: first stumbling steps in PDL (PDL References)
by eyepopslikeamosquito (Archbishop) on Dec 15, 2022 at 20:46 UTC | |
by Bod (Parson) on Feb 02, 2024 at 22:37 UTC | |
Re: first stumbling steps in PDL
by Anonymous Monk on Dec 15, 2022 at 21:43 UTC | |
by etj (Priest) on Feb 02, 2024 at 19:12 UTC | |
by jo37 (Curate) on Feb 02, 2024 at 20:54 UTC | |
by etj (Priest) on Feb 03, 2024 at 03:54 UTC | |
by jo37 (Curate) on Feb 08, 2024 at 14:17 UTC | |
| |
by jo37 (Curate) on Feb 05, 2024 at 20:18 UTC | |
| |
by jo37 (Curate) on Feb 04, 2024 at 09:56 UTC | |
by etj (Priest) on Feb 04, 2024 at 23:07 UTC | |
by jo37 (Curate) on Feb 06, 2024 at 08:30 UTC | |
by etj (Priest) on Feb 06, 2024 at 16:45 UTC |