Inspired by the previous question.
Golomb's self-describing sequence g(n) is a sequence where any natural number n is repeated within the sequence g(n) times.
The first few numbers in the sequence are:
n 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
g(n) 1 2 2 3 3 4 4 4 5 5 5 6 6 6 6 7 7 7 7 8
You can see that g(4)=3, and that "4" is repeated 3 times in the sequence.
Limitations: n<100000.
Smallest code wins.
nrather than2 - n % 1. Do you have any reason to expect answers to be significantly different? – Peter Taylor Sep 18 '12 at 9:41golomb=1:2:2:concat(zipWith replicate(drop 2 golomb)[3..])– FUZxxl Sep 18 '12 at 10:01