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