Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Prolegemona To A Future Scripting Language: Game Of Life In Perl 6

by jaldhar (Vicar)
on May 01, 2003 at 05:43 UTC ( #254569=note: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
     #!/usr/bin/perl
     use warnings;
     use strict;
    
  2. or download this
     my $life = new life : 20;
    
  3. or download this
     loop { $life.display() }
    
  4. or download this
     class life
     {
    
  5. or download this
      has Int          $.count;
      has Int          $.dimension;
      has Array of Bit @.grid;
    
  6. or download this
      method BUILD(Int $dimension)
      {
        $.count = 0;
        $.max = $dimension - 1;
    
  7. or download this
        my Array of Bit @.grid is dim($dimension,$dimension)
                               is default(0);
    
  8. or download this
        @grid[$dimension / 2 - 1][$dimension / 2] = 1;
        @grid[$dimension / 2 - 1][$dimension / 2 + 1] = 1;
        @grid[$dimension / 2][$dimension / 2] = 1;
        @grid[$dimension / 2][$dimension / 2 - 1] = 1;
        @grid[$dimension / 2 + 1][$dimension / 2] = 1;
    
  9. or download this
        @.grid = @grid;
      }
    
  10. or download this
      sub iterate (&block)
      {
    
  11. or download this
        for 0..$.max -> $x
        {
    ...
        }
      }
    
  12. or download this
      method calculate() is private
      {
        my @newgrid;
        iterate
        {
    
  13. or download this
          my $live = sum(@.grid[$^x-1..$^x+1][$^y-1..$^y+1]);
          @newgrid[$^x][$^y] =  $live==2 && @.grid[$^x][$^y]
    ...
          print "\n" if $^x == $.max;
        }
        print "\n";
    
  14. or download this
        print "Turn $(++$.count), press enter to continue or ctl-c to quit
    +;
    
  15. or download this
        <$*IN>;
    
  16. or download this
       .calculate();
      }
    }
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (14)
As of 2014-07-28 16:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (204 votes), past polls