Talk:Hofstadter Figure-Figure sequences: Difference between revisions

Content added Content deleted
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: Line 32:


==timings for the REXX solutions==
==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 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.
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.
<br>I didn't expect a difference of three orders of magnitude.
<lang rexx>/*REXX pgm calculates & verifies the Hofstadter Figure-Figure sequences.*/
<lang rexx>/*REXX program calculates and verifies the Hofstadter Figure─Figure sequences.*/
call time 'Reset████████████████████████████████████████████████████████████████████████████████'
call time 'Reset'
parse arg x high bot . /*obtain any C.L. specifications.*/
parse arg x top bot . /*obtain optional arguments from the CL*/
if x=='' then x=10; if high=='' then high=1000 /*use the defaults?*/
if x=='' | x==',' then x= 10 /*Not specified? Then use the default.*/
if bot=='' then bot=40 /* " " " */
if top=='' | top==',' then top=1000 /* " " " " " " */
low=1; if x<0 then low=abs(x) /*only show a single │X│ value.*/
if bot=='' | bot==',' then bot= 40 /* " " " " " " */
r.=0; r.1=1; rr.=r.; rr.1=1 /*initialize the R & RR arrays.*/
low=1; if x<0 then low=abs(x) /*only display a single │X│ value? */
s.=0; s.1=2 /* " " S array. */
r.=0; r.1=1; rr.=r.; rr.1=1; s.=r.; s.1=2 /*initialize the R RR S arrays.*/
errs=0; $.=0
errs=0; $.=0
do i=low to abs(x) /*show first X values of R & S */
do i=low to abs(x) /*display the 1st X values of R & S.*/
say right('R('i") =",20) right(ffr(i),7), /*show nice*/
say right('R('i") =", 20) right(ffr(i), 7),
right('S('i") =",20) right(ffs(i),7) /* R & S */
right('S('i") =", 20) right(ffs(i), 7)
end /*i*/
end /*i*/
if x<1 then exit /*if x ≤ 0, then we're all done.*/
if x<1 then exit
do m=1 for bot; r=ffr(m); $.r=1
end /*m*/ /* [] calculate the 1st 40 R values.*/


do m=1 for bot; r=ffr(m); $.r=1; end /*calculate 1st 40 R values.*/
do n=1 for top-bot; s=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.*/


do v=1 for top
@='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
if \$.v then call ser 'missing R │ S:' v
end /*v*/ /* [↑] are all 1≤ numbers ≤1k present?*/

/* [] verify all 1≤#≤1k present*/
do v=1 for high; if \$.v then call sErr 'missing R │ S:' v; end
say 'took' format(time('Elapsed'),,2) "seconds."
say
say
if errs==0 then say 'verification completed for all numbers from 1 ──►' high " [inclusive]."
if errs==0 then say 'verification completed for all numbers from 1 ──►' top " [inclusive]."
else say 'verification failed with' errs "errors."
else say 'verification failed with' errs "errors."
say
say 'took' format(time('Elapsed█████████████████████████████████████████████████████████████████'),,2) "seconds."
exit /*stick a fork in it, we're done.*/
exit /*stick a fork in it, we're done.*/
/*────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────FFR subroutine──────────────────────*/
ffr: procedure expose r. s. rr.; parse arg n
ffr: procedure expose r. s. rr.; parse arg n /*obtain the number from the arg.*/
if r.n\==0 then return r.n /*Defined? Then return the value.*/
if r.n\==0 then return r.n /*Defined? Then return the value.*/
_=ffr(n-1) + ffs(n-1) /*calculate the FFR & FFS values.*/
_=ffr(n-1) + ffs(n-1) /*calculate the FFR & FFS values.*/
r.n=_; rr._=1; return _ /*assign value to R & RR; return.*/
r.n=_; rr._=1; return _ /*assign value to R & RR; return.*/
/*────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────FFS subroutine──────────────────────*/
ffs: procedure expose r. s. rr.; parse arg n /*search for ¬null R│S #.*/
ffs: procedure expose r. s. rr.; parse arg n /*search for ¬null R or S number.*/
if s.n==0 then do k=1 for n /* [↓] 1st IF is a short circuit*/
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
if s.k\==0 then if r.k\==0 then iterate
call ffr k /*define R.k via FFR subroutine*/
call ffr k /*define R.k via FFR subroutine*/
km=k-1; _=s.km+1 /*the next S number, possibly. */
km=k-1; _=s.km+1 /*the next S number, possibly.*/
_=_+rr._; s.k=_ /*define an element of S array.*/
_=_+rr._; s.k=_ /*define an element of S array.*/
end /*k*/
end /*k*/
return s.n /*return the value to the invoker*/
return s.n /*return S.n value to the invoker*/
/*────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────SERR subroutine─────────────────────*/
sErr: errs=errs+1; say '***error***!' arg(1); return</lang>
ser: errs=errs+1; say '***error***!' arg(1); return</lang>
'''output''' when using the defaults:
'''output''' &nbsp; when using the default inputs:
<pre>
<pre>
R(1) = 1 S(1) = 2
R(1) = 1 S(1) = 2
Line 92: Line 94:
R(9) = 56 S(9) = 13
R(9) = 56 S(9) = 13
R(10) = 69 S(10) = 14
R(10) = 69 S(10) = 14
took 0.22 seconds.


verification completed for all numbers from 1 ──► 1000 [inclusive].
verification completed for all numbers from 1 ──► 1000 [inclusive].

took 0.22 seconds.
</pre>
</pre>
The (above) example was run under Windows 7 on a HP box (3.2GHz) using Regina version 3.9.1.
The (above) example was run under Windows 7 on an air-gap HP box (3.2GHz) using Regina REXX version 3.9.1.
<br><br>
<br><br>