/* 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));