Anonymous user
Talk:Hofstadter Figure-Figure sequences: Difference between revisions
Talk:Hofstadter Figure-Figure sequences (view source)
Revision as of 21:32, 24 September 2015
, 8 years ago→timings for the REXX solutions: added/changed whitespace and comments, change a variable's name.
m (→timings for the REXX solutions: edited the source.) |
(→timings for the REXX solutions: added/changed whitespace and comments, change a variable's name.) |
||
Line 32:
==timings for the REXX solutions==
I normally don't including timings for the REXX solutions that I post, but when I saw the 2<sup>nd</sup> REXX example's timings, <br>
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 three orders of magnitude.
<lang rexx>/*REXX
call time 'Reset████████████████████████████████████████████████████████████████████████████████'
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."
say
say 'took' format(time('Elapsed█████████████████████████████████████████████████████████████████'),,2) "seconds."
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
/*────────────────────────────────────────────────────────────────────────────*/
'''output''' when using the
<pre>
R(1) = 1 S(1) = 2
Line 92 ⟶ 94:
R(9) = 56 S(9) = 13
R(10) = 69 S(10) = 14
took 0.22 seconds.▼
verification completed for all numbers from 1 ──► 1000 [inclusive].
▲took 0.22 seconds.
</pre>
The (above) example was run under Windows 7 on
<br><br>
|