Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: My Conway's Game Of Life Attempt

by Anonymous Monk
on Jan 03, 2010 at 10:15 UTC ( [id://815409]=note: print w/replies, xml ) Need Help??


in reply to Re: My Conway's Game Of Life Attempt
in thread My Conway's Game Of Life Attempt

Well I've used warnings and strict as well and I don't think the listed errors are part of the problem. Nonetheless I tried the modifiy the code but it still gives me the error message: "Use of uninitialized value in string eq at gol/3.pl line 171, <stdin> line 1." This only affects some of the "if-neighbour" statements: notably lines 171, 183, 187, 191, 195; Marked with an # at the end. It cant really make any sense out of this...
#First attempt Game of Life 39x39 use strict; use warnings; my @wholepattern = ( [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ','0','0',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ','0',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ','0',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ','0','0',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ','0','0','0',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ','0'], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ','0'], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0','0' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0','0',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ','0',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ','0',' ','0',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0','0',' ',' ',' + ',' ',' ',' ','0','0',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +','0','0',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0',' ',' ',' ','0',' + ',' ',' ',' ','0','0',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +','0','0',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ','0','0',' ',' ',' ',' ',' ',' ',' ',' ','0',' ',' ',' ',' ',' ',' +0',' ',' ',' ','0','0',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ','0','0',' ',' ',' ',' ',' ',' ',' ',' ','0',' ',' ',' ','0',' ',' +0','0',' ',' ',' ',' ','0',' ','0',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0',' ',' ',' ',' ',' ',' +0',' ',' ',' ',' ',' ',' ',' ','0',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0',' ',' ',' ','0',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0','0',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ',' ','0'], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' +,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', +' ',' ',' ',' ',' ',' ',' ','0','0'] ); #new wholepattern2 my @wholepattern2 = @wholepattern; print "iterations: "; my $z = <stdin>; $z--; my $t = 0; my $row = (); my $one = (); my @neighbours = (); print "t:$t"; print "\n"; $t++; my $i=0; foreach $row (@wholepattern) { my $j=0; foreach $one (@$row) { if ($wholepattern[$i][$j] eq '0') { print "0"; } else { print " "; } $j++; if ($j == 78) { print "\n"; } } $i++; } print "\n"; select(undef, undef, undef, 1); while ($t <= $z) { my $i=0; foreach $row (@wholepattern) { my $j=0; foreach $one (@$row) { my $a1 = $i - 1; my $a2 = $i; my $a3 = $i + 1; my $b1 = $j - 1; my $b2 = $j; my $b3 = $j + 1; if ($a1 == -1) { my $a1 = 78; } if ($a3 == 79) { my $a3 = 0; } if ($b1 == -1) { my $b1 = 78; } if ($b3 == 79) { my $b3 = 0; } my $e11 = $wholepattern[$a1][$b1]; my $e12 = $wholepattern[$a1][$b2]; my $e13 = $wholepattern[$a1][$b3]; my $e21 = $wholepattern[$a2][$b1]; my $e22 = $wholepattern[$a2][$b2]; my $e23 = $wholepattern[$a2][$b3]; my $e31 = $wholepattern[$a3][$b1]; my $e32 = $wholepattern[$a3][$b2]; my $e33 = $wholepattern[$a3][$b3]; my $cell = "0"; if ($e11 eq "0") { push (@neighbours, '0'); } if ($e12 eq "0") { push (@neighbours, '0'); } if ($e13 eq "0") # { push (@neighbours, '0'); } if ($e21 eq '0') { push (@neighbours, '0'); } #if ($e22 eq '0') # { # push (@neighbours, '0'); # } if ($e23 eq '0') # { push (@neighbours, '0'); } if ($e31 eq '0') # { push (@neighbours, '0'); } if ($e32 eq '0') # { push (@neighbours, '0'); } if ($e33 eq '0') # { push (@neighbours, '0'); } my $neighbours = @neighbours; if ($neighbours < 2) { $wholepattern2[$a2][$b2] = ' '; } if ($neighbours == 2) { } if ($neighbours == 3) { $wholepattern2[$a2][$b2] = '0'; } if ($neighbours > 3) { $wholepattern2[$a2][$b2] = ' '; } @neighbours = (); $neighbours = (); $j++; } $i++; } #displaying print "t:$t"; print "\n"; my $k=0; foreach $row (@wholepattern2) { my $l=0; foreach $one (@$row) { if ($wholepattern2[$k][$l] eq '0') { print "0"; } else { print " "; } $l++; if ($l == 78) { print "\n"; } } $k++; } print "\n"; $t++; select(undef, undef, undef, 0.3); @wholepattern = @wholepattern2; }

Replies are listed 'Best First'.
Re^3: My Conway's Game Of Life Attempt
by BrowserUk (Patriarch) on Jan 03, 2010 at 11:54 UTC

    It is so hard to see the flow of your code given its horribly spaced verbosity. Try this version which simply uses perl's inate abilty to be concise and see if it doesn't ring some bells:

    #! perl -slw use strict; my @wholepattern = ( [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ','0','0',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ','0',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ','0',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ','0','0',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ','0','0','0',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' + ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' +',' ',' ',' ',' '] ); my @wholepattern2 = @wholepattern; printf "iterations: "; my $z = <stdin>; $z--; my $t = 0; print "t:$t"; $t++; my $i=0; for my $row (@wholepattern) { my $j=0; for my $one (@$row) { if( $wholepattern[$i][$j] eq '0' ) { printf "0|"; } else { printf " |"; } if( ++$j == 39) { print ""; } } $i++; } select(undef, undef, undef, 1); while( $t <= $z ) { my @neighbours; my $i = 0; for my $row ( @wholepattern ) { my $j = 0; for my $one ( @$row ) { push @neighbours, '0' if $wholepattern[$i-1][$j-1] eq '0'; push @neighbours, '0' if $wholepattern[$i-1][$j ] eq '0'; push @neighbours, '0' if $wholepattern[$i-1][$j+1] eq '0'; push @neighbours, '0' if $wholepattern[$i ][$j-1] eq '0'; push @neighbours, '0' if $wholepattern[$i ][$j ] eq '0'; push @neighbours, '0' if $wholepattern[$i ][$j+1] eq '0'; push @neighbours, '0' if $wholepattern[$i+1][$j-1] eq '0'; push @neighbours, '0' if $wholepattern[$i+1][$j ] eq '0'; push @neighbours, '0' if $wholepattern[$i+1][$j+1] eq '0'; my $neighbours = @neighbours; $wholepattern2[$i][$j] = ' ' if $neighbours < 2; do{} if $neighbours == 2; $wholepattern2[$i][$j] = '0' if $neighbours == 3; $wholepattern2[$i][$j] = ' ' if $neighbours > 3; @neighbours = (); $j++; } $i++; } print "t:$t"; my $k=0; for my $row (@wholepattern2) { my $l = 0; for my $one (@$row) { if( $wholepattern2[$k][$l] eq '0') { printf "0|"; } else { printf " |"; } $l++; if( $l == 39 ) { print ""; } } $k++; } printf "\n"; $t++; select(undef, undef, undef, 0.4); @wholepattern = @wholepattern2; }

    Hint: (assuming you bothered to read down this far), What happens if you try to address element $wholepattern[ -1 ][ -1 ]>?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Thank you for you input, I hope this version is more readable, with improved spacing. I think I've tracked down the problem: Inexplicably for me, the array @wholepattern gets changed, albeit it shouldn't in the following code. In the line #@wholepattern = @wholepattern2; It would usually copy the edited @wholepattern2 array to @wholepattern, but I've specifically canceled it out. If I'm running 2 iterations, why does @wholepattern still change? What am I missing here?!
      #5. attempt Game of Life 79x39 use strict; my @wholepattern = ( ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','0','0','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','0','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','0','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','0','0','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','0','0','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','0','0','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'] ); #new wholepattern2 my @neighbours2; my @wholepattern2 = @wholepattern; print "iterations: "; my $z = <stdin>; $z--; my $t = 0; my $row = (); my $one = (); my @neighbours = (); print "t:$t"; print "\n"; $t++; my $i=0; foreach $row (@wholepattern) { my $j=0; foreach $one (@$row) { if ($wholepattern[$i][$j] eq '0') { print "*"; } else { print "."; } $j++; if ($j == 78) { print "\n"; } } $i++; } print "\n"; select(undef, undef, undef, 1); while ($t <= $z) { my $i=0; foreach $row (@wholepattern) { my $j=0; foreach $one (@$row) { my $a1 = $i - 1; my $a2 = $i; my $a3 = $i + 1; my $b1 = $j - 1; my $b2 = $j; my $b3 = $j + 1; if ($a1 == -1) { my $a1 = 78; } if ($a3 == 79) { my $a3 = 0; } if ($b1 == -1) { my $b1 = 78; } if ($b3 == 79) { my $b3 = 0; } if ($wholepattern[$a1][$b1] eq '0') { push (@neighbours, '0'); } if ($wholepattern[$a1][$b2] eq '0') { push (@neighbours, '0'); } if ($wholepattern[$a1][$b3] eq '0') # { push (@neighbours, '0'); } if ($wholepattern[$a2][$b1] eq '0') { push (@neighbours, '0'); } #if ($wholepattern[$a2][$b2] eq '0') # { # push (@neighbours, '0'); # } if ($wholepattern[$a2][$b3] eq '0') # { push (@neighbours, '0'); } if ($wholepattern[$a3][$b1] eq '0') # { push (@neighbours, '0'); } if ($wholepattern[$a3][$b2] eq '0') # { push (@neighbours, '0'); } if ($wholepattern[$a3][$b3] eq '0') # { push (@neighbours, '0'); } my $neighbours = @neighbours; if ($neighbours < 2) { $wholepattern2[$a2][$b2] = 'A'; } if ($neighbours == 2) { $wholepattern2[$a2][$b2] = '2'; } if ($neighbours == 3) { $wholepattern2[$a2][$b2] = '3'; } if ($neighbours > 3) { $wholepattern2[$a2][$b2] = 'B'; } @neighbours = (); $neighbours = (); $j++; } $i++; } #displaying print "t:$t"; print "\n"; my $k=0; foreach $row (@wholepattern2) { my $l=0; foreach $one (@$row){ if ($wholepattern2[$k][$l] ne ' ') { print $wholepattern2[$k][$l]; } else { print "."; } $l++; if ($l == 78) { print "\n"; } } $k++; } print "\n"; $t++; select(undef, undef, undef, 0.2); #@wholepattern = @wholepattern2; } print $wholepattern[2][2];
      Hint: (assuming you bothered to read down this far), What happens if you try to address element $wholepattern [ -1 ] [ -1 ]>?
      P.S. $wholepattern [ -1 ] [ -1 ] doesnt return anything. therefore I assume that "$wholepattern [$i-1] [$j-1] eq '0'" or "$wholepattern [-1] [-1] eq '0'" for that matter is false.

        Sticking as close as possible to your methodology, but just a more compact representation, this version works.

        Working out what small change in your logic was required is left as an exercise :)

        #! perl -slw use strict; $|++; my @board = map [ (' ') x 39 ], 1.. 39; $board[ $_->[ 0 ] ][ $_->[ 1 ] ] = '0' for [1,1],[1,2],[2,1],[3,4],[4,3],[4,4], [9,8],[9,9],[9,10]; #my @board2 = @board; printf "iterations: "; my $z = <stdin>; $z--; my $t = 0; print "t:$t"; $t++; print join '|', @$_ for @board; select(undef, undef, undef, 1); while( $t <= $z ) { my @neighbours; my $i = 0; my @board2; for my $row ( @board ) { my $j = 0; for ( @$row ) { local $^W; my $neighbours = 0; ++$neighbours if $board[$i-1][$j-1] eq '0'; ++$neighbours if $board[$i-1][$j ] eq '0'; ++$neighbours if $board[$i-1][$j+1] eq '0'; ++$neighbours if $board[$i ][$j-1] eq '0'; # ++$neighbours if $board[$i ][$j ] eq '0'; ++$neighbours if $board[$i ][$j+1] eq '0'; ++$neighbours if $board[$i+1][$j-1] eq '0'; ++$neighbours if $board[$i+1][$j ] eq '0'; ++$neighbours if $board[$i+1][$j+1] eq '0'; $board2[$i][$j] = ' '; $board2[$i][$j] = ' ' if $board[$i][$j] eq '0' and $neighb +ours < 2; $board2[$i][$j] = '0' if $board[$i][$j] eq '0' and $neighb +ours == 2; $board2[$i][$j] = '0' if $neighbours == 3; $board2[$i][$j] = ' ' if $board[$i][$j] eq '0' and $neighb +ours > 3; $j++; } $i++; } print "t:$t"; print join '|', @$_ for @board2; $t++; select(undef, undef, undef, 0.1); @board = @board2; }

        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://815409]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-16 08:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found