Anonymous user
Hofstadter Q sequence: Difference between revisions
m
→{{header|REXX}}: implemented better output formats.
(→{{header|REXX}}: simplified the code, added/changed whitespace and comments, added commas to larger numbers.) |
m (→{{header|REXX}}: implemented better output formats.) |
||
Line 2,322:
if d=='' | d=="," then d= -1000000 /* " " " " " " */
@.= 1; ac= abs(c) /* [↑] negative #'s don't show values.*/
call HofstadterQ a; say
call HofstadterQ b; say
call HofstadterQ c; say
downs= 0; do j=2 for ac-1; jm= j - 1
downs= downs + (@.j<@.jm)
end /*j*/
say commas(downs) ' HofstatdterQ terms are less then the previous term,' ,
'
call HofstadterQ d; ad= abs(d); say
say 'The ' commas(ad) || th(ad) ' HofstatdterQ term is: ' commas(@.ad)
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
HofstadterQ: procedure expose @.; parse arg x 1 ox /*get number to generate through.*/
/* [↑] OX is the same as X. */
x=
if ox>0 then say 'HofstadterQ('right(j, w)"): "
end
end /*j*/▼
return @.x /*return the │X│th term to caller*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 2,352 ⟶ 2,351:
{{out|output|text= when using the internal default inputs:}}
<pre>
HofstadterQ( 1): 1
HofstadterQ( 2): 1
HofstadterQ( 3): 2
HofstadterQ( 4): 3
HofstadterQ( 5): 3
HofstadterQ( 6): 4
HofstadterQ( 7): 5
HofstadterQ( 8): 5
HofstadterQ( 9): 6
HofstadterQ(10): 6
HofstadterQ 1,000th
49,798 HofstatdterQ terms are less then the previous term, HofstatdterQ(100,000th) term is: 48,157
The 1,000,000th HofstatdterQ term is: 512,066
</pre>
Line 2,380 ⟶ 2,379:
if d=='' | d=="," then d= -1000000 /* " " " " " " */
@.= 1; ac= abs(c) /* [↑] negative #'s don't show values.*/
call HofstadterQ a; say
call HofstadterQ b; say
call HofstadterQ c; say
downs= 0; do j=2 for ac-1; jm= j - 1
downs= downs + (@.j<@.jm)
end /*j*/
say commas(downs) ' HofstatdterQ terms are less then the previous term,' ,
'
call HofstadterQ d; ad= abs(d); say
say 'The ' commas(ad) || th(ad) ' HofstatdterQ term is: ' commas(@.ad)
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
HofstadterQ: procedure expose @.; parse arg x 1 ox /*get number to generate through.*/
/* [↑] OX is the same as X. */
x=
if j>2
end /*j*/▼
return @.x /*return the │X│th term to caller*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 2,418 ⟶ 2,416:
if d=='' | d=="," then d= -1000000 /* " " " " " " */
@.= 0; @.1= 1; @.2= 1; ac= abs(c) /* [↑] negative #'s don't show values.*/
call HofstadterQ a; say
call HofstadterQ b; say
call HofstadterQ c; say
downs= 0; do j=2 for ac-1; jm= j - 1
downs= downs + (@.j<@.jm)
end /*j*/
say commas(downs) ' HofstatdterQ terms are less then the previous term,' ,
'
call HofstadterQ d; ad= abs(d); say
say 'The ' commas(ad) || th(ad) ' HofstatdterQ term is: ' commas(@.ad)
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
HofstadterQ: procedure expose @.; parse arg x 1 ox /*get number to generate through.*/
/* [↑] OX is the same as X. */
x=
if @.j==0 then @.j= QR(j) /*Not defined? Then define it.*/
end
return @.x /*return the │X│th term to caller*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
|