in reply to Uninitialized warnings trouble
I changed my code pretty radically using " List::Util". I now get the right answer :)
#!/usr/bin/perl use strict; use warnings; use List::Util qw(all); #use Time::HiRes qw(usleep); sub usleep {}; my @forest; my $current = 0; my $visible; my $found = 0; open(my $lines, '<', 'input8.txt'); while (<$lines>) { chomp; push @forest, [ split // ]; } close $lines; foreach my $current (0..@forest-1) { my $row = $forest[$current]; foreach my $i (0..@$row-1) { if ($current == 0 or $current == @forest-1 or $i == 0 or $i == + @$row-1) { $visible++; syswrite STDOUT, $forest[$current][$i] . 'V'; usleep 100000; next; } if (all { $_ < $row->[$i] } @$row[0..$i-1] or all { $_ < $row- +>[$i] } @$row[$i+1..@$row-1]) { $visible++; syswrite STDOUT, $forest[$current][$i] . 'V'; usleep 100000; next; } if (all { $_ < $row->[$i] } map { $forest[$_][$i] } (0..$curre +nt-1)) { $visible++; syswrite STDOUT, $forest[$current][$i] . 'V'; usleep 100000; next; } if (all { $_ < $row->[$i] } map { $forest[$_][$i] } ($current+ +1..@forest-1)) { $visible++; syswrite STDOUT, $forest[$current][$i] . 'V'; usleep 100000; next; } syswrite STDOUT, $forest[$current][$i] . ' '; usleep 100000; } syswrite STDOUT, "\n"; } print "There are $visible visible trees.\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Uninitialized warnings trouble
by hv (Prior) on Dec 14, 2022 at 06:08 UTC | |
Re^2: Uninitialized warnings trouble
by tybalt89 (Monsignor) on Dec 14, 2022 at 05:46 UTC | |
by rsFalse (Chaplain) on Dec 14, 2022 at 22:53 UTC | |
by jwkrahn (Abbot) on Dec 14, 2022 at 07:45 UTC |