Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
thanks a lot, that's exactly the problem I was facing. fixed it now with the use of clone-any. here my final version:
#8. attempt Game of Life 79x39 #Needs Clone-Any use strict; use Clone::Any qw(clone); my @wholepattern = ( ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','0','0','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','0','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','0','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','0','0','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','0','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','0','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','0','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','0','0','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','0','0','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'], ['.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' +.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','. +','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' +,'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', +'.','.','.','.','.','.','.','.','.'] ); #new wholepattern2 my @neighbours2; my @wholepattern2 = @{ clone(\@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] = '.'; } if ($neighbours == 2) { if ($wholepattern[$a2][$b2] eq '.') { $wholepattern2[$a2][$b2] = '.'; } if ($wholepattern[$a2][$b2] eq '0') { $wholepattern2[$a2][$b2] = '0'; } } 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 $wholepattern2[$k][$l]; print "*"; } else { print "."; } $l++; if ($l == 78) { print "\n"; } } $k++; } print "\n"; $t++; select(undef, undef, undef, 0.2); @wholepattern = (); @wholepattern = @{ clone(\@wholepattern2) }; }

In reply to Re^2: My Conway's Game Of Life Attempt by Anonymous Monk
in thread My Conway's Game Of Life Attempt 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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-18 05:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found