Van Eck sequence: Difference between revisions
→{{header|REXX}}: reformat and make it ooRexx compatible
m (→{{header|Uiua}}: Reformat) |
Walterpachl (talk | contribs) (→{{header|REXX}}: reformat and make it ooRexx compatible) |
||
Line 3,361:
=={{header|REXX}}==
===using a list===
This REXX version allows the specification of the ''start'' and ''end'' of the ''Van Eck'' sequence (to be displayed) as
<br>well as the initial starting element (the default is zero).
<syntaxhighlight lang="rexx">/*REXX pgm generates/displays the
dd=''
$$=; z= $ /*$$: old seq: $: initial value of seq*/▼
z=d
Do i=1 To hi-1
end /*HI-1*/ /*REVERSE allows backwards search in $.*/▼
za=wordpos(reverse(z),reverse(dd))
/*stick a fork in it, we're all done. */▼
zb=0
say 'terms ' LO " through " HI ' of the Van Eck sequence are: ' subword($,LO,HI-LO+1)</syntaxhighlight>▼
wdd=words(dd)
Do zz=wdd To 1 By -1
If z=word(dd,zz) Then Do
zb=wdd-zz+1
Leave
End
End
z=za
dd=d
d=d z
▲
Exit
/*stick a fork in it, we're all done. */</syntaxhighlight>
{{out|output|text= when using the default inputs:}}
<pre>
Line 3,387 ⟶ 3,401:
===using a dictionary===
This REXX version (which uses a dictionary) is about '''20,000''' times faster (when using larger numbers) than
<br>using a list (in finding the previous location of an "old" number (term).
<syntaxhighlight lang="rexx">/*REXX pgm generates/displays the
x=sta
do #=1 for HI-1 /*X: is the last term being examined. */▼
a.=.
out='0'
Do n=1 For
If a.x==. Then Do
a.x=n
d.n=0
▲ end /*j*/ /*stick a fork in it, we're all done. */
x=0
say 'terms ' LO " through " HI ' of the Van Eck sequence are: ' out</syntaxhighlight>▼
End
Else Do /* old term. */
z=n-a.x
d.n=z
a.x=n
x=z
End
out=out d.n
low=lo-1
out=d.low /* initialize the output list */
Do j=lo To hi-1
End /*j*/
{{out|output|text= is identical to the 1<sup>st</sup> REXX version.}} <br><br>
|