Dear ones,

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*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to first stumbling steps in PDL by Discipulus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.