Jump to content

Hofstadter Q sequence: Difference between revisions

Added Bracmat example
m (→‎{{header|REXX}}: added whitespace befor the FOR in a DO statement.)
(Added Bracmat example)
Line 197:
Term is less than preceding term 49798 times
</pre>
 
=={{header|Bracmat}}==
<lang bracmat>( 0:?memocells
& tbl$(memo,!memocells+1) { allocate array }
& ( Q
=
. !arg:(1|2)&1
| !arg:>2
& ( !arg:>!memocells:?memocells { Array is too small. }
& tbl$(memo,!memocells+1) { Let array grow to needed size. }
| { Arry is not too small. }
)
& ( !(!arg$memo):>0 { Set index to !arg. Return value at index if > 0 }
| Q$(!arg+-1*Q$(!arg+-1))+Q$(!arg+-1*Q$(!arg+-2))
: ?(!arg$?memo) { Set index to !arg. Store value just found. }
)
)
& 0:?i
& whl
' (1+!i:~>10:?i&put$(str$(Q$!i " ")))
& put$\n
& whl'(1+!i:~>1000:?i&Q$!i)
& out$(Q$1000)
& 0:?previous:?lessThan:?i
& whl
' ( 1+!i:~>100000:?i
& Q$!i
: ( <!previous&1+!lessThan:?lessThan
| ?
)
: ?previous
)
& out$!lessThan
);</lang>
Output:
<pre>1 1 2 3 3 4 5 5 6 6
502
49798</pre>
 
=={{header|C}}==
483

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.