Hofstadter Figure-Figure sequences: Difference between revisions
Content deleted Content added
Added EchoLisp |
m →version 1: added/changed whitespace and comments and the link, changed a variable's name. |
||
Line 1,672:
Over a third of the program was for verification of the first thousand numbers in the Hofstadter Figure-Figure sequences.
<lang rexx>/*REXX
parse arg x
if x==''
if
errs=0; $.=0
do i=low to abs(x) /*
say right('R('i") =", 20) right(ffr(i), 7),
right('S('i") =", 20) right(ffs(i), 7)
end /*i*/
if x<1 then exit
do m=1 for bot; r=ffr(m); $.r=1
do
if $.s then call ser 'duplicate number in R and S lists:' s; $.s=1
end /*n*/ /* [↑] calculate the 1st 960 S values.*/
do v=1 for top
end /*v*/ /* [↑] are all 1≤ numbers ≤1k present?*/
▲ /* [↓] verify all 1≤#≤1k present*/
say
if errs==0 then say 'verification completed for all numbers from 1 ──►'
else say 'verification failed with' errs "errors."
exit /*stick a fork in it, we're done.*/
/*────────────────────────────────────────────────────────────────────────────*/
ffr: procedure expose r. s. rr.; parse arg n /*obtain the number
if r.n\==0 then return r.n /*Defined? Then return the value.*/
_=ffr(n-1) + ffs(n-1) /*calculate the FFR & FFS values.*/
r.n=_; rr._=1; return _ /*assign value to R & RR; return.*/
/*────────────────────────────────────────────────────────────────────────────*/
ffs: procedure expose r. s. rr.; parse arg n
if s.n==0 then
if s.k\==0 then if r.k\==0 then iterate
call ffr k /*define R.k via FFR subroutine*/
km=k-1; _=s.km+1 /*the next S number, possibly.
_=_+rr._; s.k=_ /*define an element of S array.*/
return s.n /*return
/*────────────────────────────────────────────────────────────────────────────*/
To see the talk section about this REXX program's timings, click here: [http://rosettacode.org/wiki/Talk:Hofstadter_Figure-Figure_sequences#timings_for_the_REXX_solutions timings for the REXX solutions]. <br>
'''output''' when using the
<pre>
R(1) = 1 S(1) = 2
|