Advertisement
Guest User

Untitled

a guest
Sep 6th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 0.24 KB | None | 0 0
  1. use experimental :cached;
  2.  
  3. sub collatz-len(Int $n) is cached
  4. {
  5.     return $n == 1
  6.         ?? 1
  7.         !! 1 + collatz-len $n %% 2
  8.             ?? $n div 2
  9.             !! 3 * $n + 1;
  10. }
  11.  
  12. say max (1..^1_000_000).race.map(&collatz-len);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement