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