in reply to Re: Uninitialized warnings trouble
in thread Uninitialized warnings trouble

Thanks! I fixed my while loops and am not getting any warnings. I haven't got the answer yet, though.

$counter = $i + 1; while ($forest[$current][$counter] < $forest[$current][$i] and $fo +und == 0) { $counter += 1; if ($counter == 99) { $visible += 1; $found = 1; $counter = 1; } }

Replies are listed 'Best First'.
Re^3: Uninitialized warnings trouble
by hv (Prior) on Dec 13, 2022 at 23:18 UTC

    Oh, I had a typo/thinko in my previous response - you were correctly counting from 0 to 98, but I wrongly suggested you should go up to $row[$counter][99] when I should have said 98. (So I think you should still be getting a few warnings.)

    My output is: 1673

    That's not what I get, but it isn't very far out. Maybe you could show the rest of the changes you made?

    It would probably be more practical to start with a smaller grid, so that you can more easily see what the correct answer is - which would mean generalizing your code to discover the size when you read the input file, but that's a useful thing to do in any case. Then you could test your code against some simple cases, like:

    222 222 (8 visible) 222 222 122 (9 visible) 222 222 221 (9 visible) 222 212 222 (9 visible) 222 222 222 (9 visible) 212 222 212 (8 visible) 222 22222 21112 (12 visible, test horizontal bounds) 22222 222 212 212 (12 visible, test vertical bounds) 212 222 etc.

      "99" did work. I think it did because I increment my counter before I start my if loop.