Talk:Hofstadter Figure-Figure sequences: Difference between revisions

m
m (→‎timings for the REXX solutions: included the Regina version used.)
m (→‎timings for the REXX solutions: changed verb tense.)
 
(12 intermediate revisions by 3 users not shown)
Line 18:
:::Not really, this aspect of the definition is present in the references too. I suspect that it may be a part of the original description cited as: D. Hofstadter, "Gödel, Escher, Bach", p. 73, but I don't have it to hand at the moment to check. When I first saw their definition I found it confusing at first too, but that is what made it interesting when trying to code it.
 
::: When I had finished the Python version I checked it with tables of the first 1000 values refered to from Sloane: [http://oeis.org/A005228/b005228.txt here] for R and [http://oeis.org/A005228A030124/b005228b030124.txt here] for S, although the table for S has an off-by-one error. --[[User:Paddy3118|Paddy3118]] 18:31, 22 October 2011 (UTC)
 
::: Another ref. with a similar definition: [http://books.google.co.uk/books?id=aFDWuZZslUUC&pg=PA1385&dq=%22Figure-Figure+sequences%22+Hofstadter,+%22G%C3%B6del,+Escher,+Bach%22,+p.+73&hl=en&ei=cw2jTt7OBMiA8gOD78zYBQ&sa=X&oi=book_result&ct=result&resnum=1&ved=0CDEQ6AEwAA#v=onepage&q&f=false CRC concise encyclopedia of mathematics By Eric W. Weisstein pp 1385]. --[[User:Paddy3118|Paddy3118]] 18:40, 22 October 2011 (UTC)
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 several orders of magnitude.
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,
<lang rexx>/*REXX pgmprogram calculates &and verifies the Hofstadter Figure-FigureFigure─Figure sequences. */
 
call time 'Reset████████████████████████████████████████████████████████████████████████████████'
I decided to go back and include the timings here as the 2<sup>nd</sup> example's timings seemed a bit high.
exit parse arg x top bot . /*stickobtain aoptional forkarguments infrom it,the we're done.CL*/
 
if x=='' | x=="," then x= 10 /*Not specified? Then use the default.*/
<br>I didn't expect a difference of magnitude.
if top=='' | top=="," then top=1000 /* " " " " " " */
<lang rexx>/*REXX pgm calculates & verifies the Hofstadter Figure-Figure sequences.*/
if bot=='' | bot=="," then bot= 40 /* " " " " " " */
call time 'Reset'
parselow=1; arg x high bot . if x<0 then low=abs(x) /*obtainonly display a single │X│ any C.L.value? specifications.*/
if xr.==''0; then xr.1=101; ifrr.=r.; high rr.1==''1; then highs.=1000 r.; s.1=2 /*useinitialize the defaults? R, RR, and S arrays.*/
if bot=errs=''0 then bot=40 /* " " "/*the number of errors found (so far).*/
low=1; if x<0 then low do i=low to abs(x) /*onlydisplay the 1st X show avalues singleof │X│R & valueS.*/
say right('R('i") =",20) right(FFR(i),7) right('S('i") =",20) right(FFS(i),7)
r.=0; r.1=1; rr.=r.; rr.1=1 /*initialize the R & RR arrays.*/
s.=0; s.1=2 end /* " " S array. i*/
/* [] verifylist the 1st allX 1≤#≤1kFig─Fig presentnumbers.*/
errs=0; $.=0
if x<1 then exit do i=low to abs(x) /*show first X values of R & S /*if X isn't positive, then we're done.*/
$.=0 say right('R('i") =",20) right(ffr(i),7), /*showinitialize the memoization ($) nicearray.*/
do m=1 for bot; right('S('i") r=",20) rightFFR(ffs(i),7m); $.r=1 /*calculate the Rfirst &forty S R values.*/
end /*m*/ end /*i [↑] ($.) is used for memoization. */
if x<1 then exit /*if [↓] check xfor duplicate 0,#s thenin we'reR all& done.S*/
do n=1 for top-bot; s=FFS(n) /*calculate the value of FFS(n). */
 
do m=1 for bot; r=ffr(m); if $.r=1;s end then call ser /*calculate'duplicate 1stnumber 40in R valuesand S lists:' s; $.*/s=1
end /*n*/ /* [↑] calculate the 1st 960 S values.*/
 
/* [↓] check for missing values in R│S*/
@='duplicate number in R and S lists:' /* [↓] calc. 1st 960 S values.*/
do nv=1 for high-bottop; s=ffs(n); if \$.sv then call sErrser @ s; $.s=1; end'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
if errs==0 then say 'verification completed for all numbers from 1 ──►' hightop " [inclusive]."
else say 'verification failed with' errs "errors."
say 'and took' format(time('Elapsed█████████████████████████████████████████████████████████████████'),,2) "seconds."
exit /*stick a fork in it, we're done.*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────FFR subroutine──────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
ffr: procedure expose r. s. rr.; parse arg n
ifFFR: r.n\==0 thenprocedure returnexpose r.n rr. s.; parse arg n /*Defined?obtain the Thennumber returnfrom the valuearguments.*/
_=ffr(n-1) + ffs(n-1) if r.n\==0 then return r.n /*calculate the FFR value /*R.n defined? Then return the value.*/
r.n=_; rr._=FFR(n-1;) + FFS(n-1) return _ /*assigncalculate the FFR value toand R &FFS RR; returnvalues.*/
r.=0; r.1n=1_; rr._=r.1; rr.1=1 return _ /*initializeassign the value to R & RR; arraysreturn.*/
/*──────────────────────────────────FFS subroutine──────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
ffs: procedure expose r. s. rr.; parse arg n /*search for ¬null R│S #.*/
ifFFS: s.n==0procedure thenexpose r. dos. k=1rr.; parse forarg n /*search for not null /*R [↓]or S 1st IF is a shortnumber. circuit*/
if s.n==0 then do k=1 for n if s.k\==0 then if ffr(k)\==0 then iterate /* [↓] 1st IF is a SHORT CIRCUIT. */
km=k-1; _=if s.km+1k\==0 then /*theif nextr.k\==0 SSthen iterate number, possibly. /*are both defined?*/
_=_+rr._; s. call FFR k=_ /*define an elementR.k of via Sthe array.FFR subroutine*/
end km=k-1; _=s.km+1 /*kcalc. the next S number, possibly.*/
return s.n _=_+rr._; s.k=_ /*returndefine thean valueelement of to the invoker S array. */
end /*k*/
/*──────────────────────────────────SERR subroutine─────────────────────*/
sErr: errs=errs+1; return says.n '***error***!' arg(1); /*return< S.n value to the invoker. */lang>
/*──────────────────────────────────────────────────────────────────────────────────────*/
'''output''' when using the defaults:
ser: errs=errs+1; say '***error***' arg(1); return</lang>
'''output''' &nbsp; when using the defaultsdefault inputs:
<pre>
R(1) = 1 S(1) = 2
Line 92 ⟶ 93:
R(9) = 56 S(9) = 13
R(10) = 69 S(10) = 14
took 0.00 seconds.
 
verification completed for all numbers from 1 ──► 1000 [inclusive].
 
took 1.52 seconds.
and took 0.0022 seconds.
</pre>
The (above) example was run under Windows 7 on aan HPair-gap 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)