Skip to content
Newer
Older
100644 15 lines (11 sloc) 319 Bytes
c6bf273 @colomon Two new scripts, fixed thinko in existing script.
authored
1 sub collatz-length(Int $n) {
2 return 1 if $n == 1;
3 state %lengths;
4 return %lengths{$n} if %lengths.exists($n);
5 %lengths{$n} = 1 + ($n %% 2 ?? collatz-length($n div 2) !! collatz-length(3 * $n + 1));
6 }
7
8 sub MAIN(*@numbers) {
9 for @numbers -> $n {
10 say "$n: " ~ collatz-length($n.Int);
11 }
12 }
13
14
Something went wrong with that request. Please try again.