fork download
  1. #!/usr/bin/perl
  2. use 5.016;
  3. use warnings;
  4. no warnings qw(recursion);
  5.  
  6. # Golomb sequence
  7. # http://e...content-available-to-author-only...a.org/wiki/Golomb_sequence
  8. # thanx: http://t...content-available-to-author-only...h.net/test/read.cgi/tech/1390525149/329-330
  9.  
  10. my @memo;
  11. sub f { $memo[$_[0]] //= ($_[0] < 2) ? 1 : 1 + f($_[0] - f(f($_[0] - 1))) }
  12.  
  13. say f(1);
  14. say f(10);
  15. say f(100);
  16. say f(1000);
  17.  
Success #stdin #stdout 0s 4104KB
stdin
Standard input is empty
stdout
1
5
21
86