Yellowstone sequence: Difference between revisions
Content added Content deleted
m (→{{header|Julia}}: added zkl header) |
(→{{header|zkl}}: added code) |
||
Line 71: | Line 71: | ||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
{{trans|Julia}} |
|||
⚫ | |||
This sequence is limited to the max size of a Dictionary, 64k |
|||
<lang zkl></lang> |
|||
<lang zkl>fcn yellowstoneW{ |
|||
Walker.zero().tweak(fcn(a,b){ |
|||
foreach i in ([1..]){ |
|||
if(not b.holds(i) and i.gcd(a[-1])==1 and i.gcd(a[-2]) >1){ |
|||
a.del(0).append(i); // only keep last two terms |
|||
b[i]=True; |
|||
return(i); |
|||
} |
|||
} |
|||
}.fp(List(2,3), Dictionary(1,True, 2,True, 3,True))).push(1,2,3); |
|||
⚫ | |||
<lang zkl>println("The first 30 entries of the Yellowstone permutation:"); |
|||
yellowstoneW().walk(30).concat(", ").println();</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
The first 30 entries of the Yellowstone permutation: |
|||
1, 2, 3, 4, 9, 8, 15, 14, 5, 6, 25, 12, 35, 16, 7, 10, 21, 20, 27, 22, 39, 11, 13, 33, 26, 45, 28, 51, 32, 17 |
|||
</pre> |
</pre> |
||
Plot using Gnuplot |
|||
<lang zkl>gnuplot:=System.popen("gnuplot","w"); |
|||
gnuplot.writeln("plot '-'"); |
|||
yellowstoneW().pump(100,gnuplot.writeln,fcn(n){ String(" ",n) }); |
|||
gnuplot.writeln("e"); |
|||
gnuplot.flush(); |
|||
ask("Hit return to finish"); gnuplot.close();</lang> |