Help for this page

Select Code to Download


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