Anonymous user
Talk:Hofstadter Figure-Figure sequences: Difference between revisions
Talk:Hofstadter Figure-Figure sequences (view source)
Revision as of 20:49, 21 May 2015
, 9 years ago→timings for the REXX solutions: replaced the REXX program, updated the timings.
m (→timings for the REXX solutions: removed STYLE from the PRE html tag.) |
m (→timings for the REXX solutions: replaced the REXX program, updated the timings.) |
||
Line 34:
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><br>I didn't expect a difference of magnitude.▼
<lang rexx>/*REXX pgm to calculate & verify the Hofstadter Figure-Figure sequences.*/▼
▲<lang rexx>/*REXX pgm
call time 'Reset'
parse arg x
if x=='' then x=10; if
low=1; if x<0
r.=0; r.1=1; rr.=r.; rr.1=1 /*initialize the R
s.=0; s.1=2
errs=0; $.=0
do i=low to abs(x) /*show first X values of R & S */
say right('R('i") =",20) right(ffr(i),7), /*show nice*/
right('S('i") =",20) right(ffs(i),7) /* R & S */
end /*i*/
@='duplicate number in R and S lists:' /* [↓] calc. 1st 960 S values.*/
do n=1 for high-bot; s=ffs(n); if $.s then call sErr @ s; $.s=1; end
say 'took' format(time('Elapsed'),,2) "seconds."
▲if x<1 then exit /*stick a fork in it, we're done.*/
▲ do m=1 for 40; r=ffr(m) /*calculate 1st 40 R values.*/
▲ /*verify presence and uniqueness.*/
▲ if \both.v then call sayErr 'missing R │ S:' v
say
▲ else say @v 'failed with' errs "errors."
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────FFR subroutine──────────────────────*/
ffr: procedure expose r. s. rr
if r.n\==0 then return r.n /*Defined? Then return the value.*/
_=ffr(n-1) + ffs(n-1) /*calculate the FFR value. */
r.n=_; rr._=1; return
/*──────────────────────────────────FFS subroutine──────────────────────*/
ffs: procedure expose r. s. rr
if s.n==0 then do k=1 for n
if s.k\==0 then if ffr(k)\==0 then iterate
km=k-1; _=s.km+1
_=_+rr._;
return s.n
/*──────────────────────────────────SERR subroutine─────────────────────*/
▲sayErr: errs=errs+1; say; say '***error***!'; say; say arg(1); say; return</lang>
'''output''' when using the defaults:
<pre>
Line 104 ⟶ 95:
verification completed for all numbers from 1 ──► 1000 [inclusive].
took 1.
</pre>
The (above) example was run under Windows 7 on a HP box (3.2GHz) using Regina.
|