#!/usr/bin/env perl6
class RabbitPair {
has Int $.age is rw;
method BUILD() {
$.age = 0;
}
method grow-up {
$.age += 1;
}
method of-age {
return $.age > 0
}
method Str {
if $.age > 0 {
"\c[RABBIT]\c[RABBIT]($.age)"
} else {
"\c[RABBIT FACE]\c[RABBIT FACE]($.age)"
}
}
}
sub MAIN() {
my $months = 6;
my $growth-rate = 2;
my @nursery;
my @playpen;
@nursery.push: RabbitPair.new();
for 1..$months -> $month {
say "month $month:\n\tnursery: @nursery[]\n\tplaypen: @playpen[]";
for @playpen {
for ^$growth-rate { @nursery.push: RabbitPair.new() }
}
for @nursery.kv -> $i, $pair {
if $pair.of-age {
@playpen.push: @nursery[$i]:delete;
}
$pair.grow-up;
}
}
say @nursery.elems + @playpen.elems;
}