Talk:Hofstadter Figure-Figure sequences: Difference between revisions

m
(→‎timings for the REXX solutions: added/changed whitespace and comments, change a variable's name.)
m (→‎timings for the REXX solutions: changed verb tense.)
 
(5 intermediate revisions by 2 users not shown)
Line 32:
 
==timings for the REXX solutions==
I normally don't includinginclude 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 threeseveral 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=='",'" then x= 10 /*Not specified? Then use the default.*/
if top=='' | top=='",'" then top=1000 /* " " " " " " */
if bot=='' | bot=='",'" then bot= 40 /* " " " " " " */
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.*/
exiterrs=0 /*stickthe number aof forkerrors infound it, we're(so donefar).*/
errs=0; $.=0
do i=low to abs(x) /*display the 1st X values of R & S.*/
say right('R('i") =", 20) right(FFR(i),7) right('S('i") =",20) right(ffrFFS(i), 7),
end right('S('/*i") =", 20) right(ffs(i), 7)*/
end /*i [↑] list the 1st X Fig─Fig numbers.*/
if x<1 then exit /*if X isn't positive, then we're done.*/
if x<1 then exit
$.=0 do m=1 for bot; r=ffr(m); /*initialize the memoization ($) array.r=1*/
do m=1 for endbot; /*r=FFR(m*/ ); $.r=1 /* [↑] calculate the 1stfirst 40forty R values.*/
end /*m*/ /* [↑] ($.) is used for memoization. */
 
do n=1 for top-bot; /* [↓] check for duplicate #s=ffs(n) in R & S*/
do n=1 for top-bot; if $.s then calls=FFS(n) ser 'duplicate number/*calculate inthe Rvalue andof S lists:'FFS(n). s; $.s=1 */
if $.s then call endser 'duplicate number /*n*/in R and S lists:' s; /* [↑] calculate the 1st 960 S values$.*/s=1
end /*n*/ /* [↑] calculate the 1st 960 S values.*/
 
do v=1 /* [↓] check for topmissing 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 'and took' format(time('Elapsed█████████████████████████████████████████████████████████████████'),,2) "seconds."
say
exit /*stick a fork in it, we're all done. */
say 'took' format(time('Elapsed█████████████████████████████████████████████████████████████████'),,2) "seconds."
/*──────────────────────────────────────────────────────────────────────────────────────*/
exit /*stick a fork in it, we're done.*/
ffsFFR: procedure expose r. srr. rrs.; parse arg n /*search for ¬null R or/*obtain Sthe number from the arguments.*/
/*────────────────────────────────────────────────────────────────────────────*/
ffr: procedure expose if r.n\==0 s. rrthen return r.;n parse arg n /*obtainR.n defined? the numberThen fromreturn the argvalue.*/
if_=FFR(n-1) r.+ FFS(n\==0-1) then return r.n /*Defined?calculate Thenthe return theFFR and FFS valuevalues.*/
r.n=_=ffr(n-1); + ffs(n-1) rr._=1; return _ /*calculateassign the FFRvalue to R & FFSRR; valuesreturn.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
r.n=_; rr._=1; return _ /*assign value to R & RR; return.*/
FFS: procedure expose r. s. rr.; parse arg n /*search for not null R or S number. */
/*────────────────────────────────────────────────────────────────────────────*/
if s.n==0 then do k=1 for n /* [↓] 1st IF is a SHORT CIRCUIT. */
ffs: procedure expose r. s. rr.; parse arg n /*search for ¬null R or S number.*/
if s.nk\==0 then doif r.k\=1 for n =0 then iterate /*are [↓] 1st IF is a SHORTboth CIRCUITdefined?*/
ifcall FFR s.k\==0 then if r /*define R.k\==0 thenvia the FFR iteratesubroutine*/
call ffr km=k-1; _=s.km+1 /*definecalc. the R.knext viaS FFR subroutinenumber, possibly.*/
km_=k-1_+rr._; _=s.km+1k=_ /*thedefine nextan element Sof number,the possiblyS array. */
_=_+rr._; s.k=_ /*define an element of S array.*/
end /*k*/
return s.n /*return S.n value to the invoker. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*────────────────────────────────────────────────────────────────────────────*/
ser: errs=errs+1; say '***error***!' arg(1); return</lang>
'''output''' &nbsp; when using the default inputs:
<pre>
Line 97 ⟶ 96:
verification completed for all numbers from 1 ──► 1000 [inclusive].
 
and took 0.22 seconds.
</pre>
The (above) example was run under Windows 7 on an air-gap HP boxPC (3.2GHz2 GHz) using Regina REXX version 3.9.1.
<br><br>
 
==Formulae hidden to most browsers by under-tested cosmetic edits at 18:19, 28 August 2016 ==
 
Under-tested cosmetic edits made to the task page at 18:19, 28 August 2016, including the injection of spaces around expressions in &lt;math&gt; tags, have left some or all of the task description formulae completely invisible to all browsers which display the graphic file version of formulae rather than processing the MathML (this is, in fact, the majority of browsers). The MediaWiki processor does not currently expect such spaces, and generates syntactically ill-formed HTML if they are introduced. Other aspects of these cosmetic edits may further compound the problem. [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 19:50, 22 September 2016 (UTC)
 
: Visibility of formulae now restored for mainstream browsers like Chrome, IE Edge, Safari, Opera etc [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 12:59, 21 November 2016 (UTC)