I am being flooded with uninitialized value warnings for lines 52 ...

Let's start with this one: your previous loop (which I visualize as "looking to the left") is working ok. In that case, you are testing visibility of $row[$current][$i], and looking at the tree $counter to the left of it as $counter ranges from 1 to $i. So you check from $row[$current][$i - 1] down to $row[$current][0].

In this loop (which I visualize as "looking to the right") you want to check each tree $counter to the right, so you should end up ranging from row[$current][$i + 1] to $row[$current][99] $row[$current][98]. But you are letting $counter run from 1 to $i again, so you actually check from row[$current][$i + 1] to $row[$current][$i + $i].

If you fix that error, it should then be obvious what you need to do to fix the remaining two loops, and I think it is possible you'll even get the correct answer.

When you do, I would love for you to come back with your finished code - I'd like to give you tips on how to improve the code, but I don't want to spoil the fun and learning experience of solving the problem first. :)

Update 2022-12-13 19:06: correct index from 99 to 98


In reply to Re: Uninitialized warnings trouble by hv
in thread Uninitialized warnings trouble by Anonymous Monk

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.