Anonymous user
Hofstadter Q sequence: Difference between revisions
m
→{{header|REXX}}: changed the var _ to jm, corrected right jagged edge. -- ~~~~
(→{{header|REXX}}: One r in Hofstadter :-)) |
m (→{{header|REXX}}: changed the var _ to jm, corrected right jagged edge. -- ~~~~) |
||
Line 1,074:
=={{header|REXX}}==
<lang rexx>/*REXX program to generate Hofstadter Q sequence for any N. */
q.=1 /*negative #s won't have values displayed.*/
call HofstadterQ 10
call HofstadterQ -1000; say; say '1000th value='result; say
call HofstadterQ -100000
downs=0
do j=2 to 100000;
downs=downs+(q.j<q.
end
say downs 'terms are less then the previous term.'
exit
/*─────────────────────────────────────HofstadterQ
HofstadterQ: procedure expose q.; arg x 1 ox /*get the # to gen through*/
/*(above) OX is the same as X.*/
x=abs(x) /*use the absolute value for X. */
Line 1,096 ⟶ 1,095:
temp1=j-q.jm1
temp2=j-q.jm2
if j>2 then if q.j==1 then q.j=q.temp1+q.temp2
if ox>0 then say right(j,L) right(q.j,L) /*if X is positive, tell.*/
end
|