RosettaCodeData/Task/Hofstadter-Q-sequence/Maxima/hofstadter-q-sequence.maxima
2023-09-01 09:35:06 -07:00

11 lines
301 B
Text

/* Function that return the terms of the Hofstadter Q sequence */
hofstadter(n):=block(
if member(n,[1,2]) then L[n]:1 else L[n]:L[n-L[n-1]]+L[n-L[n-2]],
L[n])$
/* Test cases */
/* First ten terms */
makelist(hofstadter(i),i,1,10);
/* 1000th term */
last(makelist(hofstadter(i),i,1,1000));