Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
15 lines (11 sloc) 319 Bytes
sub collatz-length(Int $n) {
return 1 if $n == 1;
state %lengths;
return %lengths{$n} if %lengths.exists($n);
%lengths{$n} = 1 + ($n %% 2 ?? collatz-length($n div 2) !! collatz-length(3 * $n + 1));
}
sub MAIN(*@numbers) {
for @numbers -> $n {
say "$n: " ~ collatz-length($n.Int);
}
}
Something went wrong with that request. Please try again.