Talk:Hofstadter Figure-Figure sequences: Difference between revisions

m
→‎timings for the REXX solutions: updated the REXX program.
m (→‎timings for the REXX solutions: included the latest (re-worked) version of the REXX program.)
m (→‎timings for the REXX solutions: updated the REXX program.)
Line 35:
I decided to go back and include the timings here as the REXX 2<sup>nd</sup> example's timings seemed a bit high.
 
<br>I didn't expect a difference of threeseveral orders of magnitude.
<lang rexx>/*REXX program calculates and verifies the Hofstadter Figure─Figure sequences. */
call time 'Reset████████████████████████████████████████████████████████████████████████████████'
Line 44:
low=1; if x<0 then low=abs(x) /*only display a single │X│ value? */
r.=0; r.1=1; rr.=r.; rr.1=1; s.=r.; s.1=2 /*initialize the R, RR, and S arrays.*/
errs=0 /*the number of errors found (so far).*/
errs=0
do i=low to abs(x) /*display the 1st X values of R & S.*/
say right('R('i") =",20) right(ffrFFR(i),7) right('S('i") =",20) right(ffsFFS(i),7)
end /*i*/
/* [↑] list the 1st X Fig─Fig numbers.*/
 
if x<1 then exit /*if X isn't positive, then we're done.*/
$.=0 /*initialize the memoization ($) array.*/
do m=1 for bot; r=ffrFFR(m); $.r=1 /*calculate the first forty R values.*/
end /*m*/ /* [↑] ($.) is used for memoization. */
/* [↓] check for duplicate #s in R & S*/
do n=1 for top-bot; s=ffsFFS(n) /*calculate the value of FFS(n). */
if $.s then call ser 'duplicate number in R and S lists:' s; $.s=1
end /*n*/ /* [↑] calculate the 1st 960 S values.*/
Line 63:
if errs==0 then say 'verification completed for all numbers from 1 ──►' top " [inclusive]."
else say 'verification failed with' errs "errors."
say 'and took' format(time('Elapsed█████████████████████████████████████████████████████████████████'),,2) "seconds."
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
ffrFFR: procedure expose r. rr. s.; parse arg n /*obtain the number from the arguments.*/
if r.n\==0 then return r.n /*IsR.n defined? Then return the value. */
_=ffrFFR(n-1) + ffsFFS(n-1) /*calculate the FFR and FFS values.*/
r.n=_; rr._=1; return _ /*assign the value to R & RR; return.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
ffsFFS: procedure expose r. s. rr.; parse arg n /*search for not null R or S number. */
if s.n==0 then do k=1 for n /* [↓] 1st IF is a SHORT CIRCUIT. */
if s.k\==0 then if r.k\==0 then iterate /*are both defined?*/
call ffrFFR k /*define R.k via the FFR subroutine*/
km=k-1; _=s.km+1 /*calc. the next S number, possibly.*/
_=_+rr._; s.k=_ /*define an element of the S array. */
Line 96:
verification completed for all numbers from 1 ──► 1000 [inclusive].
 
and took 0.22 seconds.
</pre>
The (above) example was run under Windows 7 on an air-gap HP boxPC (3.2GHz2 GHz) using Regina REXX version 3.9.1.
<br><br>