Hofstadter Q sequence: Difference between revisions
Content added Content deleted
imported>Maxima enthusiast No edit summary |
|||
Line 2,661: | Line 2,661: | ||
<pre>>> sum(diff(Qsequence(100000))<0) |
<pre>>> sum(diff(Qsequence(100000))<0) |
||
ans = 49798 |
ans = 49798 |
||
</pre> |
|||
=={{header|Maxima}}== |
|||
<syntaxhighlight lang="maxima"> |
|||
/* 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)); |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
[1,1,2,3,3,4,5,5,6,6] |
|||
502 |
|||
</pre> |
</pre> |
||