Anonymous user
Talk:Hofstadter Figure-Figure sequences: Difference between revisions
Talk:Hofstadter Figure-Figure sequences (view source)
Revision as of 19:07, 28 August 2016
, 7 years ago→timings for the REXX solutions: included the latest (re-worked) version of the REXX program.
(→timings for the REXX solutions: added/changed whitespace and comments, change a variable's name.) |
m (→timings for the REXX solutions: included the latest (re-worked) version of the REXX program.) |
||
Line 36:
<br>I didn't expect a difference of three orders of magnitude.
<lang rexx>/*REXX program calculates and verifies the Hofstadter Figure─Figure sequences. */
call time 'Reset████████████████████████████████████████████████████████████████████████████████'
parse arg x top bot . /*obtain optional arguments from the CL*/
if x=='' | x==
if top=='' | top==
if bot=='' | bot==
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
end
end /*m*/ /* [↑] calculate the 1st 40 R values.*/▼
if x<1 then exit
$.=0
do m=1 for
end /*m*/ /* [↑] ($.) is used for memoization. */
do n=1 for top-bot;
if $.s then call
/* [↓] check for missing values in R│S*/
do v=1 for top; if \$.v then call ser 'missing R │ S:' v
end /*v*/ /* [↑] are all 1≤ numbers ≤1k present?*/
say
if errs==0 then say 'verification completed for all numbers from 1 ──►' top " [inclusive]."
else say 'verification failed with' errs "errors."
say 'took' format(time('Elapsed█████████████████████████████████████████████████████████████████'),,2) "seconds."
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
ffr: procedure expose r.
if r.n\==0 then return r.n /*
_=ffr(n-1) + ffs(n-1) /*calculate the FFR
r.n=_; rr._=1; return _ /*assign the value to R & RR; return.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
ffs: procedure expose r. s. rr.; parse arg n /*search for
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 ffr 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. */
end /*k*/
return s.n /*return S.n value to the invoker. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
ser: errs=errs+1; say '***error***
'''output''' when using the default inputs:
<pre>
|