Quick actions

cmd+k|ctrl+k

Navigation

Languages

Untitled

Snippet info

Language

Raku

Visibility

unlisted

Author

legacy-anonymous

Created

2017-02-18T14:35:33Z

Updated

2017-02-18T14:35:33Z

#!/usr/bin/env perl6

my constant RabbitPair = Int;

my RabbitPair @pairs.push: 0;

sub MAIN(
  Int :$months      where $_ < 40 = 15,
  Int :$growth-rate where $_ < 5  = 3
) {
  for 1..$months -> $month {    
    say "** month {$month} **\ntotal: @pairs.elems()";

    # Adults have babies. Place the newborns in incubation.
    my RabbitPair @newborns;

    for @pairs -> $pair {
        if $pair > 0 {
    	    @newborns.push(0) for ^$growth-rate;
        }
    }

    # Age the rabbits
    @pairs.=map: { $_ + 1 };

    # Add the newborns to the rest
    @pairs.append: @newborns;
  }
}
INFO