Talk:Hofstadter Figure-Figure sequences: Difference between revisions
Content added Content deleted
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: | 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, |
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, |
||
I decided to go back and include the timings here as the 2<sup>nd</sup> example's timings seemed a bit high. |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
call time 'Reset' |
call time 'Reset' |
||
parse arg x |
parse arg x high bot . /*obtain any C.L. specifications.*/ |
||
if x=='' then x=10; if |
if x=='' then x=10; if high=='' then high=1000 /*use the defaults?*/ |
||
if bot=='' then bot=40 /* " " " */ |
|||
if x<0 |
low=1; if x<0 then low=abs(x) /*only show a single │X│ value.*/ |
||
r.=0; r.1=1; rr.=r.; rr.1=1 /*initialize the R |
r.=0; r.1=1; rr.=r.; rr.1=1 /*initialize the R & RR arrays.*/ |
||
s.=0; s.1=2 |
s.=0; s.1=2 /* " " S array. */ |
||
errs=0 |
errs=0; $.=0 |
||
do i=low to abs(x) /*show first X values of R & S */ |
do i=low to abs(x) /*show first 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), /*show nice*/ |
||
right('S('i") =",20) right(ffs(i),7) /* R & S */ |
right('S('i") =",20) right(ffs(i),7) /* R & S */ |
||
end /*i*/ |
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." |
say 'took' format(time('Elapsed'),,2) "seconds." |
||
⚫ | |||
/*═══════════════════════════════════════verify 1st 1k: unique & present*/ |
|||
both.=0 /*initialize the BOTH array. */ |
|||
/*build list of 1st 40 R values.*/ |
|||
⚫ | |||
both.r=1 /*build the BOTH array. */ |
|||
end /*m*/ |
|||
/*build list of 1st 960 S values.*/ |
|||
do n=1 for 960; s=ffs(n) /*calculate 1st 960 S values.*/ |
|||
if both.s then call sayErr 'duplicate number in R and S lists:' s |
|||
both.s=1 /*add to the BOTH array. */ |
|||
end /*n*/ |
|||
⚫ | |||
do v=1 for highV /*verify all 1 ≤ # ≤ 1k present.*/ |
|||
⚫ | |||
end /*v*/ |
|||
say |
say |
||
if errs==0 then say 'verification completed for all numbers from 1 ──►' high " [inclusive]." |
|||
⚫ | |||
if errs==0 then say @v 'completed for all numbers from 1 ──►' highV @i |
|||
⚫ | |||
say 'took' format(time('E'),,2) "seconds." |
|||
exit /*stick a fork in it, we're done.*/ |
exit /*stick a fork in it, we're done.*/ |
||
/*──────────────────────────────────FFR subroutine──────────────────────*/ |
/*──────────────────────────────────FFR subroutine──────────────────────*/ |
||
ffr: procedure expose r. s. rr |
ffr: procedure expose r. s. rr.; parse arg n |
||
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 value. */ |
_=ffr(n-1) + ffs(n-1) /*calculate the FFR value. */ |
||
r.n=_; rr._=1 |
r.n=_; rr._=1; return _ /*assign value to R & RR; return.*/ |
||
return _ /*return the value to the invoker*/ |
|||
/*──────────────────────────────────FFS subroutine──────────────────────*/ |
/*──────────────────────────────────FFS subroutine──────────────────────*/ |
||
ffs: procedure expose r. s. rr |
ffs: procedure expose r. s. rr.; parse arg n /*search for ¬null R│S #.*/ |
||
if s.n==0 then do k=1 for n /* [↓] 1st IF is a short circuit*/ |
|||
if s.k\==0 then if ffr(k)\==0 then iterate |
if s.k\==0 then if ffr(k)\==0 then iterate |
||
km=k-1; _=s.km+1 |
km=k-1; _=s.km+1 /*the next SS number, possibly.*/ |
||
_=_+rr._ |
_=_+rr._; s.k=_ /*define an element of S array.*/ |
||
end /*k*/ |
|||
return s.n /*return the value to the invoker*/ |
|||
/*──────────────────────────────────SERR subroutine─────────────────────*/ |
|||
return s.n /*return the value to the invoker*/ |
|||
⚫ | |||
/*──────────────────────────────────SAYERR subroutine───────────────────*/ |
|||
⚫ | |||
'''output''' when using the defaults: |
'''output''' when using the defaults: |
||
<pre> |
<pre> |
||
Line 104: | Line 95: | ||
verification completed for all numbers from 1 ──► 1000 [inclusive]. |
verification completed for all numbers from 1 ──► 1000 [inclusive]. |
||
took 1. |
took 1.52 seconds. |
||
</pre> |
</pre> |
||
The (above) example was run under Windows 7 on a HP box (3.2GHz) using Regina. |
The (above) example was run under Windows 7 on a HP box (3.2GHz) using Regina. |