RosettaCodeData/Task/Hofstadter-Q-sequence/Factor/hofstadter-q-sequence.factor
2023-07-01 13:44:08 -04:00

7 lines
234 B
Factor

( scratchpad ) : next ( seq -- newseq )
dup 2 tail* over length [ swap - ] curry map
[ dupd swap nth ] map 0 [ + ] reduce suffix ;
( scratchpad ) { 1 1 } 1000 [ next ] times dup 10 head . 999 swap nth .
{ 1 1 2 3 3 4 5 5 6 6 }
502