Yellowstone sequence: Difference between revisions

m
(Added solution for Action!)
 
(26 intermediate revisions by 16 users not shown)
Line 32:
:*   [https://rosettacode.org/wiki/Greatest_common_divisor Greatest common divisor].
:*   [https://rosettacode.org/wiki/Plot_coordinate_pairs Plot coordinate pairs].
:*   [[EKG sequence convergence]]
 
 
Line 42 ⟶ 43:
{{trans|C++}}
 
<langsyntaxhighlight lang="11l">T YellowstoneGenerator
min_ = 1
n_ = 0
Line 71 ⟶ 72:
L(i) 1 .< 30
print(‘ ’ygen.next(), end' ‘’)
print()</langsyntaxhighlight>
 
{{out}}
Line 81 ⟶ 82:
{{trans|Ruby}}
 
<langsyntaxhighlight lang="11l">F yellow(n)
V a = [1, 2, 3]
V b = Set([1, 2, 3])
Line 93 ⟶ 94:
R a
 
print(yellow(30))</langsyntaxhighlight>
 
{{out}}
Line 101 ⟶ 102:
 
=={{header|Action!}}==
<langsyntaxhighlight Actionlang="action!">BYTE FUNC Gcd(BYTE a,b)
BYTE tmp
 
Line 155 ⟶ 156:
PrintB(seq(i)) Put(32)
OD
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Yellowstone_sequence.png Screenshot from Atari 8-bit computer]
Line 161 ⟶ 162:
First 30 Yellowstone numbers:
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>
 
=={{header|Ada}}==
{{trans|C++}}
<syntaxhighlight lang="ada">with Ada.Text_IO;
with Ada.Containers.Ordered_Sets;
 
procedure Yellowstone_Sequence is
 
generic -- Allow more than one generator, but must be instantiated
package Yellowstones is
function Next return Integer;
function GCD (Left, Right : Integer) return Integer;
end Yellowstones;
 
package body Yellowstones
is
package Sequences is
new Ada.Containers.Ordered_Sets (Integer);
 
-- Internal package state
N_0 : Integer := 0;
N_1 : Integer := 0;
N_2 : Integer := 0;
Seq : Sequences.Set;
Min : Integer := 1;
 
function GCD (Left, Right : Integer) return Integer
is (if Right = 0
then Left
else GCD (Right, Left mod Right));
 
function Next return Integer is
begin
N_2 := N_1;
N_1 := N_0;
if N_0 < 3 then
N_0 := N_0 + 1;
else
N_0 := Min;
while
not (not Seq.Contains (N_0)
and then GCD (N_1, N_0) = 1
and then GCD (N_2, N_0) > 1)
loop
N_0 := N_0 + 1;
end loop;
end if;
Seq.Insert (N_0);
while Seq.Contains (Min) loop
Seq.Delete (Min);
Min := Min + 1;
end loop;
return N_0;
end Next;
 
end Yellowstones;
 
procedure First_30 is
package Yellowstone is new Yellowstones; -- New generator instance
use Ada.Text_IO;
begin
Put_Line ("First 30 Yellowstone numbers:");
for A in 1 .. 30 loop
Put (Yellowstone.Next'Image); Put (" ");
end loop;
New_Line;
end First_30;
 
begin
First_30;
end Yellowstone_Sequence;</syntaxhighlight>
{{out}}
<pre>
First 30 Yellowstone numbers:
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>
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang="algol68">BEGIN # find members of the yellowstone sequence: starting from 1, 2, 3 the #
# subsequent members are the lowest number coprime to the previous one #
# and not coprime to the one before that, that haven't appeared in the #
Line 223 ⟶ 300:
print( ( " ", whole( ys[ i ], 0 ) ) )
OD
END</langsyntaxhighlight>
{{out}}
<pre>
Line 231 ⟶ 308:
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">yellowstone: function [n][
result: new [1 2 3]
present: new [1 2 3]
Line 254 ⟶ 331:
]
 
print yellowstone 30</langsyntaxhighlight>
 
{{out}}
Line 261 ⟶ 338:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">A := [], in_seq := []
loop 30 {
n := A_Index
Line 290 ⟶ 367:
b := Mod(a | 0x0, a := b)
return a
}</langsyntaxhighlight>
{{out}}
<pre>[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>
Line 296 ⟶ 373:
=={{header|C}}==
{{trans|Ruby}}
<langsyntaxhighlight lang="c">#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
Line 540 ⟶ 617:
putc('\n', stdout);
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>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>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <numeric>
#include <set>
Line 588 ⟶ 665:
std::cout << '\n';
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 598 ⟶ 675:
=={{header|D}}==
{{trans|C++}}
<langsyntaxhighlight lang="d">import std.numeric;
import std.range;
import std.stdio;
Line 646 ⟶ 723:
void main() {
new Yellowstone().take(30).writeln();
}</langsyntaxhighlight>
{{out}}
<pre>[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>
Line 655 ⟶ 732:
{{Trans|Go}}
Boost.Generics.Collection and Boost.Process are part of [https://github.com/MaiconSoft/DelphiBoostLib DelphiBoostLib].
<syntaxhighlight lang="delphi">
<lang Delphi>
program Yellowstone_sequence;
 
Line 736 ⟶ 813:
plot.Kill;
plot.Free;
end.</langsyntaxhighlight>
{{out}}
<pre>The first 30 Yellowstone numbers are:
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
Press enter to close</pre>
 
=={{header|EasyLang}}==
{{trans|Lua}}
<syntaxhighlight>
func gcd a b .
if b = 0
return a
.
return gcd b (a mod b)
.
proc remove_at i . a[] .
for j = i + 1 to len a[]
a[j - 1] = a[j]
.
len a[] -1
.
proc yellowstone count . yellow[] .
yellow[] = [ 1 2 3 ]
num = 4
while len yellow[] < count
yell1 = yellow[len yellow[] - 1]
yell2 = yellow[len yellow[]]
for i to len notyellow[]
test = notyellow[i]
if gcd yell1 test > 1 and gcd yell2 test = 1
break 1
.
.
if i <= len notyellow[]
yellow[] &= notyellow[i]
remove_at i notyellow[]
else
while gcd yell1 num <= 1 or gcd yell2 num <> 1
notyellow[] &= num
num += 1
.
yellow[] &= num
num += 1
.
.
.
print "First 30 values in the yellowstone sequence:"
yellowstone 30 yellow[]
print yellow[]
</syntaxhighlight>
 
=={{header|Factor}}==
{{works with|Factor|0.99 2020-01-23}}
<langsyntaxhighlight lang="factor">USING: accessors assocs colors.constants
combinators.short-circuit io kernel math prettyprint sequences
sets ui ui.gadgets ui.gadgets.charts ui.gadgets.charts.lines ;
Line 777 ⟶ 899:
line new COLOR: blue >>color
100 <iota> 100 <yellowstone> zip >>data
add-gadget "Yellowstone numbers" open-window</langsyntaxhighlight>
{{out}}
<pre>
Line 783 ⟶ 905:
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>
 
=={{header|Forth}}==
<syntaxhighlight lang="text">: array create cells allot ;
: th cells + ; \ some helper words
 
30 constant #yellow \ number of yellowstones
 
#yellow array y \ create array
( n1 n2 -- n3)
: gcd dup if tuck mod recurse exit then drop ;
: init 3 0 do i 1+ y i th ! loop ; ( --)
: show cr #yellow 0 do y i th ? loop ; ( --)
: gcd-y[] - cells y + @ over gcd ; ( k i n -- k gcd )
: loop1 begin 1+ over 2 gcd-y[] 1 = >r over 1 gcd-y[] 1 > r> or 0= until ;
: loop2 over true swap 0 ?do over y i th @ = if 0= leave then loop ;
: yellow #yellow 3 do i 3 begin loop1 loop2 until y rot th ! loop ;
: main init yellow show ;
 
main</syntaxhighlight>
{{out}}
<pre>main
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 ok</pre>
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">function gcd(a as uinteger, b as uinteger) as uinteger
if b = 0 then return a
return gcd( b, a mod b )
Line 819 ⟶ 963:
while inkey=""
wend
end</langsyntaxhighlight>
{{out}}
<pre>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>
Line 825 ⟶ 969:
=={{header|Go}}==
This uses Gnuplot-X11 to do the plotting rather than a third party Go plotting library.
<langsyntaxhighlight lang="go">package main
 
import (
Line 888 ⟶ 1,032:
w.Close()
g.Wait()
}</langsyntaxhighlight>
 
{{out}}
Line 897 ⟶ 1,041:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Data.List (unfoldr)
 
yellowstone :: [Integer]
Line 916 ⟶ 1,060:
 
main :: IO ()
main = print $ take 30 yellowstone</langsyntaxhighlight>
 
{{out}}
Line 926 ⟶ 1,070:
and displaying a chart of the first 100 terms:
 
<langsyntaxhighlight lang="haskell">import Codec.Picture
import Data.Bifunctor (second)
import Diagrams.Backend.Rasterific
Line 998 ⟶ 1,142:
FontWeightBold
) -> sansRB
return $ createEnv vectorAlignmentFns 640 400 fontChosen</langsyntaxhighlight>
{{Out}}
<pre>[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>
Line 1,004 ⟶ 1,148:
=={{header|J}}==
===tacit===
<syntaxhighlight lang="j">
<lang J>
Until=: 2 :'u^:(0-:v)^:_'
assert 44 -: >:Until(>&43) 32 NB. increment until exceeding 43
Line 1,016 ⟶ 1,160:
ys=: (append term)@]^:(0 >. _3+[) prepare
assert (ys 30) -: 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
</syntaxhighlight>
</lang>
===explicit===
<syntaxhighlight lang="j">
<lang J>
GCD=: +.
relatively_prime=: 1 = GCD
 
yellowstone=: monad define{{
s=. 1 2 3 NB. initial sequence
start=. #\ i. 4 + y NB. prepare minimal starting values
while. y > # s do.
s=. 3 {. start NB. the sequence vector
z=. <./(1+s)-.s NB. lowest positive inteeger not in sequence
start=. 3 }. start
while. yif. >0 #1 -: z relatively_prime _2{.s do. z e. s end. do.
z=. z+1
z=. {. start NB. z is the lowest number not in the sequence
end. NB. find next value for sequence
while.do.
s=. s, z
if. 0 1 -: (_2 {. s) relatively_prime z do.
if. z -.@e. s do.
break.
end.
end.
z =. >: z
end.
}}
start=. start -. z NB. remove z from the list of starting values
</syntaxhighlight>
s=. s , z
end.
s
)
</lang>
<pre>
yellowstone 30
Line 1,049 ⟶ 1,184:
'marker'plot yellowstone 100
</pre>
 
[https://jsoftware.github.io/j-playground/bin/html2/#code=GCD%3D%3A%20%2B.%0Arelatively_prime%3D%3A%201%20%3D%20GCD%0A%0Ayellowstone%3D%3A%20%7B%7B%0A%20%20s%3D.%201%202%203%20%20%20%20%20%20%20%20%20%20%20%20NB.%20initial%20sequence%0A%20%20while.%20y%20%3E%20%23%20s%20do.%0A%20%20%20%20z%3D.%20%3C.%2F%281%2Bs%29-.s%20%20%20%20NB.%20lowest%20positive%20inteeger%20not%20in%20sequence%0A%20%20%20%20while.%20if.%200%201%20-%3A%20z%20relatively_prime%20_2%7B.s%20do.%20z%20e.%20s%20end.%20do.%0A%20%20%20%20%20%20z%3D.%20z%2B1%0A%20%20%20%20end.%20%20%20NB.%20find%20next%20value%20for%20sequence%0A%20%20%20%20s%3D.%20s%2C%20z%0A%20%20end.%0A%7D%7D%0A%0Arequire'plot'%0A'marker'plot%20yellowstone%20100 try it online]
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">
import java.util.ArrayList;
import java.util.List;
Line 1,106 ⟶ 1,243:
 
}
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,117 ⟶ 1,254:
{{Trans|Python}}
{{Works with|ES6}}
<langsyntaxhighlight lang="javascript">(() => {
'use strict';
 
Line 1,307 ⟶ 1,444:
// MAIN ---
return main();
})();</langsyntaxhighlight>
{{Out}}
<pre>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>
Line 1,313 ⟶ 1,450:
=={{header|jq}}==
{{works with|jq}}
<syntaxhighlight lang="jq">
<lang jq>
# jq optimizes the recursive call of _gcd in the following:
def gcd(a;b):
Line 1,343 ⟶ 1,480:
select(.emit)) );
.emit ));
</syntaxhighlight>
</lang>
'''The task'''
<langsyntaxhighlight lang="jq">"The first 30 entries of the Yellowstone permutation:",
[limit(30;yellowstone)]</langsyntaxhighlight>
{{out}}
<pre>
Line 1,354 ⟶ 1,491:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Plots
 
function yellowstone(N)
Line 1,385 ⟶ 1,522:
y = yellowstone(100)
plot(x, y)
</langsyntaxhighlight>{{out}}
<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>
[[File:Yellowstone-sequence-graph.png]]
 
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">fun main() {
println("First 30 values in the yellowstone sequence:")
println(yellowstoneSequence(30))
Line 1,441 ⟶ 1,579:
a
} else gcd(b, a % b)
}</langsyntaxhighlight>
{{out}}
<pre>First 30 values in the yellowstone sequence:
Line 1,448 ⟶ 1,586:
=={{header|Lua}}==
{{trans|Java}}
<langsyntaxhighlight lang="lua">function gcd(a, b)
if b == 0 then
return a
Line 1,516 ⟶ 1,654:
end
 
main()</langsyntaxhighlight>
{{out}}
<pre>First 30 values in the yellowstone sequence:
Line 1,522 ⟶ 1,660:
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">state = {1, 2, 3};
MakeNext[state_List] := Module[{i = First[state], done = False, out},
While[! done,
Line 1,538 ⟶ 1,676:
]
Nest[MakeNext, state, 30 - 3]
ListPlot[%]</langsyntaxhighlight>
{{out}}
<pre>{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}
Line 1,547 ⟶ 1,685:
===Procedure version===
This version uses a set and, so, is limited to 65536 elements. It is easy to change this limit by using a HashSet (standard module “sets”) instead of a set. See the iterator version which uses such a HashSet.
<langsyntaxhighlight Nimlang="nim">import math
 
proc yellowstone(n: int): seq[int] =
Line 1,564 ⟶ 1,702:
inc candidate
 
echo yellowstone(30)</langsyntaxhighlight>
{{out}}
<pre>@[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>
Line 1,570 ⟶ 1,708:
===Iterator version===
This version uses a HashSet, but using a set as in the previous version is possible if we accept the limit of 65536 elements.
<langsyntaxhighlight Nimlang="nim">import math, sets
 
iterator yellowstone(n: int): int =
Line 1,593 ⟶ 1,731:
for n in yellowstone(30):
stdout.write " ", n
echo()</langsyntaxhighlight>
{{out}}
<pre> 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>
 
 
=={{header|PARI/GP}}==
<syntaxhighlight lang="PARI/GP">
yellowstone(n) = {
my(a=3, o=2, u=[]);
if(n<3, return(n)); \\ Base case: return n if it is less than 3
print1("1, 2"); \\ Print initial values
 
for(i = 4, n, \\ Iterate from 4 to n
print1(", "a); \\ Print current value of a
u = setunion(u, Set(a)); \\ Add a to the set u
 
\\ Remove consecutive elements from u
while(#u > 1 && u[2] == u[1] + 1,
u = vecextract(u, "^1")
);
 
\\ Find next value of a
for(k = u[1] + 1, 1e10,
if(gcd(k, o) <= 1, next); \\ Skip if gcd(k, o) is greater than 1
if(setsearch(u, k), next); \\ Skip if k is in set u
if(gcd(k, a) != 1, next); \\ Skip if gcd(k, a) is not 1
o = a; \\ Update o to current a
a = k; \\ Update a to k
break
)
);
 
a \\ Return the final value of a
}
 
yellowstone(20); \\ Call the function with n = 20
</syntaxhighlight>
{{out}}
<pre>
1, 2, 3, 4, 9, 8, 15, 14, 5, 6, 25, 12, 35, 16, 7, 10, 21, 20, 27
</pre>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 1,646 ⟶ 1,822:
binmode $fh;
print $fh $gd->png();
close $fh;</langsyntaxhighlight>
{{out}}
<pre>The first 30 terms in the Yellowstone sequence:
Line 1,653 ⟶ 1,829:
 
=={{header|Phix}}==
{{translibheader|JuliaPhix/pGUI}}
{{libheader|Phix/online}}
<!--<lang Phix>(phixonline?)-->
You can run this online [http://phix.x10.mx/p2js/Yellowstone.htm here].
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Yellowstone_sequence.exw
--</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"1.0.2"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">yellowstone</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">N</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">a</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">3</span><span style="color: #0000FF;">},</span>
Line 1,674 ⟶ 1,858:
<span style="color: #008080;">return</span> <span style="color: #000000;">a</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"The first 30 entries of the Yellowstone permutation:\n%Vv\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">yellowstone</span><span style="color: #0000FF;">(</span><span style="color: #000000;">30</span><span style="color: #0000FF;">)})</span>
<!--</lang>-->
<span style="color: #000080;font-style:italic;">-- a simple plot:</span>
{{out}}
<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>
=== a simple plot ===
{{libheader|Phix/pGUI}}
<!--<lang Phix>-->
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #008080;">include</span> <span style="color: #7060A8;">IupGraph</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">get_data</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000000;">graph</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">y500</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">yellowstone</span><span style="color: #0000FF;">(</span><span style="color: #000000;">500</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">w</span><span style="color: #0000FF;">,</span><span style="color: #000000;">h</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetIntInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">graph</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"DRAWSIZE"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">graph</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"XTICK"</span><span style="color: #0000FF;">,</span><span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">w</span><span style="color: #0000FF;"><</span><span style="color: #000000;">640</span><span style="color: #0000FF;">?</span><span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">h</span><span style="color: #0000FF;"><</span><span style="color: #000000;">300</span><span style="color: #0000FF;">?</span><span style="color: #000000;">100</span><span style="color: #0000FF;">:</span><span style="color: #000000;">50</span><span style="color: #0000FF;">):</span><span style="color: #000000;">20</span><span style="color: #0000FF;">))</span>
<span style="color: #7060A8;">IupSetInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">graph</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"YTICK"</span><span style="color: #0000FF;">,</span><span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">h</span><span style="color: #0000FF;"><</span><span style="color: #000000;">250</span><span style="color: #0000FF;">?</span><span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">h</span><span style="color: #0000FF;"><</span><span style="color: #000000;">140</span><span style="color: #0000FF;">?</span><span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">h</span><span style="color: #0000FF;"><</span><span style="color: #000000;">120</span><span style="color: #0000FF;">?</span><span style="color: #000000;">700</span><span style="color: #0000FF;">:</span><span style="color: #000000;">350</span><span style="color: #0000FF;">):</span><span style="color: #000000;">200</span><span style="color: #0000FF;">):</span><span style="color: #000000;">100</span><span style="color: #0000FF;">))</span>
<span style="color: #008080;">return</span> <span style="color: #0000FF;">{{</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">500</span><span style="color: #0000FF;">),</span><span style="color: #000000;">y500</span><span style="color: #0000FF;">,</span><span style="color: #004600;">CD_RED</span><span style="color: #0000FF;">}}</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #7060A8;">IupOpen</span><span style="color: #0000FF;">()</span>
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">graph</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGraph</span><span style="color: #0000FF;">(</span><span style="color: #000000;">get_data</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"RASTERSIZE=960x600"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupControlsOpen</span><span style="color: #0000FF;">()</span>
<span style="color: #0040807060A8;">IhandleIupSetAttributes</span> <span style="color: #000000;">plot</span> <span style="color: #0000FF;">=(</span> <span style="color: #7060A8000000;">IupPlotgraph</span><span style="color: #0000FF;">(,</span><span style="color: #008000;">`GTITLE="MENUITEMPROPERTIES=Yes,Yellowstone SIZE=640x320Numbers"`</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetAttributeIupSetInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">plotgraph</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"TITLETITLESTYLE"</span><span style="color: #0000FF;">,</span> <span style="color: #008000004600;">"Yellowstone Numbers"CD_ITALIC</span><span style="color: #0000FF;">);</span>
<span style="color: #7060A8;">IupSetAttributeIupSetAttributes</span><span style="color: #0000FF;">(</span><span style="color: #000000;">plotgraph</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"TITLEFONTSIZE"</span><span style`XNAME="color: #0000FF;n">,</span> <span styleYNAME="color: #008000;">"10a(n)"`</span><span style="color: #0000FF;">);</span>
<span style="color: #7060A8;">IupSetAttributeIupSetAttributes</span><span style="color: #0000FF;">(</span><span style="color: #000000;">plotgraph</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"TITLEFONTSTYLE"</span><span styleXTICK="color: #0000FF;">20,</span> <span styleXMIN=0,XMAX="color: #008000;">"ITALIC500"</span><span style="color: #0000FF;">);</span>
<span style="color: #7060A8;">IupSetAttributeIupSetAttributes</span><span style="color: #0000FF;">(</span><span style="color: #000000;">plotgraph</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"GRIDLINESTYLE"</span><span styleYTICK="color: #0000FF;">100,</span> <span styleYMIN=0,YMAX="color: #008000;">"DOTTED1400"</span><span style="color: #0000FF;">);</span>
<span style="color: #7060A8004080;">IupSetAttributeIhandle</span> <span style="color: #0000FF000000;">(dlg</span> <span style="color: #0000000000FF;">plot=</span> <span style="color: #0000FF7060A8;">,IupDialog</span> <span style="color: #0080000000FF;">(</span><span style="GRIDcolor: #000000;">graph</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">`TITLE="YESYellowstone Names"`</span><span style="color: #0000FF;">);</span>
<span style="color: #7060A8;">IupSetAttributeIupSetAttributes</span><span style="color: #0000FF;">(</span><span style="color: #000000;">plotdlg</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"AXS_XLABEL"</span><span styleMINSIZE="color: #0000FF;">,</span> <span style="color: #008000;">"n290x140"</span><span style="color: #0000FF;">);</span>
<span style="color: #7060A8;">IupSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">plot</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"AXS_YLABEL"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"a(n)"</span><span style="color: #0000FF;">);</span>
<span style="color: #7060A8;">IupSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">plot</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"AXS_XFONTSTYLE"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"ITALIC"</span><span style="color: #0000FF;">);</span>
<span style="color: #7060A8;">IupSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">plot</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"AXS_YFONTSTYLE"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"ITALIC"</span><span style="color: #0000FF;">);</span>
<span style="color: #7060A8;">IupSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">plot</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"AXS_YTICKSIZEAUTO"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"NO"</span><span style="color: #0000FF;">);</span>
<span style="color: #7060A8;">IupSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">plot</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"AXS_YTICKMAJORSIZE"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"8"</span><span style="color: #0000FF;">);</span>
<span style="color: #7060A8;">IupSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">plot</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"AXS_YTICKMINORSIZE"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"0"</span><span style="color: #0000FF;">);</span>
<span style="color: #7060A8;">IupPlotBegin</span><span style="color: #0000FF;">(</span><span style="color: #000000;">plot</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">y500</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">yellowstone</span><span style="color: #0000FF;">(</span><span style="color: #000000;">500</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">x</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">500</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">IupPlotAdd</span><span style="color: #0000FF;">(</span><span style="color: #000000;">plot</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">x</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">y500</span><span style="color: #0000FF;">[</span><span style="color: #000000;">x</span><span style="color: #0000FF;">])</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupPlotEnd</span><span style="color: #0000FF;">(</span><span style="color: #000000;">plot</span><span style="color: #0000FF;">)</span>
<span style="color: #000080;font-style:italic;">--IupSetAttribute(plot, "DS_MODE", "BAR") -- (optional)</span>
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">dlg</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupDialog</span><span style="color: #0000FF;">(</span><span style="color: #000000;">plot</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`TITLE="Yellowstone Names"`</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupShow</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span>
Line 1,714 ⟶ 1,887:
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</langsyntaxhighlight>-->
{{out}}
<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>
 
=={{header|Phixmonti}}==
{{trans|Ruby}}Require Utilitys library version 1.3
<langsyntaxhighlight Phixmontilang="phixmonti">include ..\Utilitys.pmt
 
def gcd /# u v -- n #/
Line 1,756 ⟶ 1,934:
def test n a len nip > enddef
"The first 30 entries of the Yellowstone permutation:" ? 30 yellow ?</langsyntaxhighlight>
{{out}}
<pre>The first 30 entries of the Yellowstone permutation:
Line 1,764 ⟶ 1,942:
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(load "@lib/frac.l")
(de yellow (N)
(let (L (list 3 2 1) I 4 C 3 D)
Line 1,779 ⟶ 1,957:
(inc 'I) )
(flip L) ) )
(println (yellow 30))</langsyntaxhighlight>
{{out}}
<pre>
Line 1,786 ⟶ 1,964:
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">Procedure.i gcd(x.i,y.i)
While y<>0 : t=x : x=y : y=t%y : Wend : ProcedureReturn x
EndProcedure
Line 1,803 ⟶ 1,981:
Next
For i=1 To 30 : Print(Str(Y(i))+" ") : Next : Input()
EndIf</langsyntaxhighlight>
{{out}}
<pre>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
Line 1,810 ⟶ 1,988:
=={{header|Python}}==
{{Works with|Python|3.7}}
<langsyntaxhighlight lang="python">'''Yellowstone permutation OEIS A098550'''
 
from itertools import chain, count, islice
Line 1,956 ⟶ 2,134:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre>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>
 
=={{header|Quackery}}==
 
<code>gcd</code> is defined at [[Greatest common divisor#Quackery]].
 
<syntaxhighlight lang="quackery"> [ stack ] is seqbits ( --> s )
 
[ bit
seqbits take |
seqbits put ] is seqadd ( n --> )
 
[ bit
seqbits share & not ] is notinseq ( n --> b )
 
[ temp put
' [ 1 2 3 ]
7 seqbits put
4
[ dip
[ dup -1 peek
over -2 peek ]
dup dip
[ tuck gcd 1 !=
unrot gcd 1 =
and ]
swap if
[ dup dip join
seqadd
3 ]
[ 1+
dup notinseq until ]
over size temp share
< not until ]
drop
seqbits release
temp take split drop ] is yellowstones ( n --> [ )
 
30 yellowstones echo</syntaxhighlight>
 
{{out}}
 
<pre>[ 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>
 
=={{header|Racket}}==
 
<langsyntaxhighlight lang="racket">#lang racket
 
(require plot)
Line 1,984 ⟶ 2,204:
 
(plot (points
(map (λ (i) (vector i (a098550 i))) (range 1 (add1 100)))))</langsyntaxhighlight>
 
{{out}}
Line 1,998 ⟶ 2,218:
Not really clear whether a line graph or bar graph was desired, so generate both. Also, 100 points don't really give a good feel for the overall shape so do 500.
 
<syntaxhighlight lang="raku" perl6line>my @yellowstone = 1, 2, 3, -> $q, $p {
state @used = True xx 4;
state $min = 3;
Line 2,032 ⟶ 2,252:
 
$line.spurt: SVG.serialize: $chart.plot: :lines;
$bars.spurt: SVG.serialize: $chart.plot: :bars;</langsyntaxhighlight>
{{out}}
<pre>The first 30 terms in the Yellowstone sequence:
Line 2,041 ⟶ 2,261:
=={{header|REXX}}==
===horizontal list of numbers===
<langsyntaxhighlight lang="rexx">/*REXX program calculates any number of terms in the Yellowstone (permutation) sequence.*/
parse arg m . /*obtain optional argument from the CL.*/
if m=='' | m=="," then m= 30 /*Not specified? Then use the default.*/
Line 2,060 ⟶ 2,280:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
gcd: parse arg x,y; do until y==0; parse value x//y y with y x; end; return x</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default input: &nbsp; &nbsp; <tt> 30 </tt>}}
<pre>
Line 2,068 ⟶ 2,288:
===vertical histogram plot===
A horizontal histogram could also be shown, &nbsp; but it would require a taller (higher) plot with more vertical screen real estate.
<langsyntaxhighlight lang="rexx">/*REXX program calculates any number of terms in the Yellowstone (permutation) sequence.*/
parse arg m . /*obtain optional argument from the CL.*/
if m=='' | m=="," then m= 30 /*Not specified? Then use the default.*/
Line 2,088 ⟶ 2,308:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
gcd: parse arg x,y; do until y==0; parse value x//y y with y x; end; return x</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the input: &nbsp; &nbsp; <tt> 532 </tt>}}
 
Line 2,157 ⟶ 2,377:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
see "working..." + nl
row = 3
Line 2,211 ⟶ 2,431:
see "Found " + row + " Yellowstone numbers" + nl
see "done..." + nl
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,221 ⟶ 2,441:
Found 30 Yellowstone numbers
done...
</pre>
 
=={{header|RPL}}==
{{works with|Halcyon Calc|4.2.7}}
{| class="wikitable"
! Code
! Comments
|-
|
'''IF''' DUP2 < '''THEN''' SWAP '''END'''
'''WHILE''' DUP '''REPEAT''' SWAP OVER MOD '''END'''
DROP
≫ 'GCD' STO
DUP SIZE 1 - GETI ROT ROT GET → am2 am1
≪ 3 '''DO'''
'''DO''' 1 + '''UNTIL''' DUP2 POS NOT '''END'''
'''UNTIL''' DUP am1 GCD 1 == OVER am2 GCD 1 ≠ AND '''END'''
+
≫ ≫ 'YELLO' STO
|
''( a b -- gcd(a,b) )''
Ensure a > b
Euclidean algorithm
''( { a(1)..a(n-1) } -- { a(1)..a(n) } )''
Store locally a(n-1) and a(n-2)
Find smallest number not already in sequence
Check primality requirements
Add a(n) to the sequence
|}
The following words in the command line deliver what is required:
{ 1 2 3 }
≪ 1 27 START YELLO NEXT ≫ EVAL
{{out}}
<pre>
1: { 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>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">def yellow(n)
a = [1, 2, 3]
b = { 1 => true, 2 => true, 3 => true }
Line 2,239 ⟶ 2,502:
end
 
p yellow(30)</langsyntaxhighlight>
{{out}}
<pre>
Line 2,246 ⟶ 2,509:
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">// [dependencies]
// num = "0.3"
// plotters = "^0.2.15"
Line 2,309 ⟶ 2,572:
Err(error) => eprintln!("Error: {}", error),
}
}</langsyntaxhighlight>
 
{{out}}
Line 2,317 ⟶ 2,580:
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>
[[Media:Yellowstone sequence rust.png]]
See: [https://slack-files.com/T0CNUL56D-F016J1UB554-6e7059bbcc yellowstone.png] (offsite PNG image)
 
 
 
=={{header|Scala}}==
{{trans|Java}}
<syntaxhighlight lang="Scala">
import scala.util.control.Breaks._
 
 
object YellowstoneSequence extends App {
 
println(s"First 30 values in the yellowstone sequence:\n${yellowstoneSequence(30)}")
 
def yellowstoneSequence(sequenceCount: Int): List[Int] = {
var yellowstoneList = List(1, 2, 3)
var num = 4
var notYellowstoneList = List[Int]()
while (yellowstoneList.size < sequenceCount) {
val foundIndex = notYellowstoneList.indexWhere(test =>
gcd(yellowstoneList(yellowstoneList.size - 2), test) > 1 &&
gcd(yellowstoneList.last, test) == 1
)
 
if (foundIndex >= 0) {
yellowstoneList = yellowstoneList :+ notYellowstoneList(foundIndex)
notYellowstoneList = notYellowstoneList.patch(foundIndex, Nil, 1)
} else {
breakable({
while (true) {
if (gcd(yellowstoneList(yellowstoneList.size - 2), num) > 1 &&
gcd(yellowstoneList.last, num) == 1) {
yellowstoneList = yellowstoneList :+ num
num += 1
// break the inner while loop
break
}
notYellowstoneList = notYellowstoneList :+ num
num += 1
}
});
}
}
yellowstoneList
}
 
def gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)
}
</syntaxhighlight>
{{out}}
<pre>
First 30 values in the yellowstone sequence:
List(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>
 
=={{header|Tcl}}==
<langsyntaxhighlight Tcllang="tcl">proc gcd {a b} {
while {$b} {
lassign [list $b [expr {$a % $b}]] a b
Line 2,349 ⟶ 2,667:
}
puts "The first 30 Yellowstone numbers are:"
puts [gen_yellowstones]</langsyntaxhighlight>
{{out}}
The first 30 Yellowstone numbers are:
Line 2,357 ⟶ 2,675:
{{trans|VBA}}
{{works with|v3.64.0}}
<syntaxhighlight lang="text">Dim @y(30)
@y(0) = 1
Line 2,371 ⟶ 2,689:
EndIf
 
For j = 10 To i - 1
If @y(j) = k Then Unloop : Continue
Next
Line 2,387 ⟶ 2,705:
_gcd Param (2)
If b@ = 0 Then Return (a@)
Return (FUNC(_gcd(b@, a@ % b@)))</langsyntaxhighlight>
{{out}}
<pre>
Line 2,394 ⟶ 2,712:
0 OK, 0:670
</pre>
 
=={{header|VBA}}==
<syntaxhighlight lang="tcl">
<lang Tcl>
Function gcd(a As Long, b As Long) As Long
If b = 0 Then
Line 2,429 ⟶ 2,748:
Next i
End Sub
</syntaxhighlight>
</lang>
{{out}}
<pre>
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>
 
=={{header|V (Vlang)}}==
{{trans|go}}
<syntaxhighlight lang="v (vlang)">fn gcd(xx int, yy int) int {
mut x := xx
mut y := yy
for y != 0 {
x, y = y, x%y
}
return x
}
fn yellowstone(n int) []int {
mut m := map[int]bool{}
mut a := []int{len: n+1}
for i in 1..4 {
a[i] = i
m[i] = true
}
mut min := 4
for c := 4; c <= n; c++ {
for i := min; ; i++ {
if !m[i] && gcd(a[c-1], i) == 1 && gcd(a[c-2], i) > 1 {
a[c] = i
m[i] = true
if i == min {
min++
}
break
}
}
}
return a[1..]
}
fn main() {
mut x := []int{len: 100}
for i in 0..100 {
x[i] = i + 1
}
y := yellowstone(100)
println("The first 30 Yellowstone numbers are:")
println(y[..30])
}</syntaxhighlight>
 
{{out}}
<pre>
The first 30 Yellowstone numbers are:
[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>
 
Line 2,439 ⟶ 2,808:
{{libheader|Wren-math}}
Without the extra credit part.
<langsyntaxhighlight ecmascriptlang="wren">import "./math" for Int
 
var yellowstone = Fn.new { |n|
Line 2,468 ⟶ 2,837:
var y = yellowstone.call(30)
System.print("The first 30 Yellowstone numbers are:")
System.print(y)</langsyntaxhighlight>
 
{{out}}
Line 2,474 ⟶ 2,843:
The first 30 Yellowstone numbers are:
[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>
 
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">func GCD(N, D); \Return the greatest common divisor of N and D
int N, D, R; \numerator, denominator, remainder
[if D > N then
[R:=D; D:=N; N:=R]; \swap D and N
while D > 0 do
[R:= rem(N/D);
N:= D;
D:= R;
];
return N;
];
 
int I, A(30+1), N, T;
[for I:= 1 to 3 do A(I):= I; \givens
N:= 4;
repeat T:= 4;
loop [if GCD(T, A(N-1)) = 1 and \relatively prime
GCD(T, A(N-2)) # 1 then \not relatively prime
[loop [for I:= 1 to N-1 do \test if in sequence
if T = A(I) then quit;
quit;
];
if I = N then \T is not in sequence so
[A(N):= T; \ add it in
N:= N+1;
quit;
];
];
T:= T+1; \next trial
];
until N > 30;
for N:= 1 to 30 do
[IntOut(0, A(N)); ChOut(0, ^ )];
\\for N:= 1 to 100 do Point(N, A(N)); \plot demonstration
]</syntaxhighlight>
 
{{out}}
<pre>
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>
 
Line 2,479 ⟶ 2,890:
{{trans|Julia}}
This sequence is limited to the max size of a Dictionary, 64k
<langsyntaxhighlight lang="zkl">fcn yellowstoneW{ // --> iterator
Walker.zero().tweak(fcn(a,b){
foreach i in ([1..]){
Line 2,489 ⟶ 2,900:
}
}.fp(List(2,3), Dictionary(1,True, 2,True, 3,True))).push(1,2,3);
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">println("The first 30 entries of the Yellowstone permutation:");
yellowstoneW().walk(30).concat(", ").println();</langsyntaxhighlight>
{{out}}
<pre>
Line 2,498 ⟶ 2,909:
</pre>
Plot using Gnuplot
<langsyntaxhighlight lang="zkl">gnuplot:=System.popen("gnuplot","w");
gnuplot.writeln("unset key; plot '-'");
yellowstoneW().pump(1_000, gnuplot.writeln.fp(" ")); // " 1\n", " 2\n", ...
gnuplot.writeln("e");
gnuplot.flush();
ask("Hit return to finish"); gnuplot.close();</langsyntaxhighlight>
Offsite Image: [http://www.zenkinetic.com/Images/RosettaCode/yellowstone1000.zkl.png yellowstone]
1,983

edits