#!/usr/bin/perl
use 5.016;
use warnings;
no warnings
qw(recursion
);
# Golomb sequence
# http://e...content-available-to-author-only...a.org/wiki/Golomb_sequence
# thanx: http://t...content-available-to-author-only...h.net/test/read.cgi/tech/1390525149/329-330
my @memo;
sub f { $memo[$_[0]] //= ($_[0] < 2) ? 1 : 1 + f($_[0] - f(f($_[0] - 1))) }
say f(1);
say f(10);
say f(100);
say f(1000);
IyEvdXNyL2Jpbi9wZXJsCnVzZSA1LjAxNjsKdXNlIHdhcm5pbmdzOwpubyB3YXJuaW5ncyBxdyhyZWN1cnNpb24pOwoKIyBHb2xvbWIgc2VxdWVuY2UKIyBodHRwOi8vZS4uLmNvbnRlbnQtYXZhaWxhYmxlLXRvLWF1dGhvci1vbmx5Li4uYS5vcmcvd2lraS9Hb2xvbWJfc2VxdWVuY2UKIyB0aGFueDogaHR0cDovL3QuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLmgubmV0L3Rlc3QvcmVhZC5jZ2kvdGVjaC8xMzkwNTI1MTQ5LzMyOS0zMzAKCm15IEBtZW1vOwpzdWIgZiB7ICRtZW1vWyRfWzBdXSAvLz0gKCRfWzBdIDwgMikgPyAxIDogMSArIGYoJF9bMF0gLSBmKGYoJF9bMF0gLSAxKSkpIH0KCnNheSBmKDEpOwpzYXkgZigxMCk7CnNheSBmKDEwMCk7CnNheSBmKDEwMDApOwo=