Yellowstone sequence: Difference between revisions

From Rosetta Code
Content added Content deleted
mNo edit summary
Line 2: Line 2:
== The Yellowstone Permutation ==
== The Yellowstone Permutation ==


<br>





Line 39: Line 39:
:* &nbsp; The OEIS entry: &nbsp; [https://oeis.org/A098550 A098550 The Yellowstone permutation].
:* &nbsp; The OEIS entry: &nbsp; [https://oeis.org/A098550 A098550 The Yellowstone permutation].
:* &nbsp; Applegate et al, 2015: The Yellowstone Permutation [https://arxiv.org/abs/1501.01669]
:* &nbsp; Applegate et al, 2015: The Yellowstone Permutation [https://arxiv.org/abs/1501.01669]

<br> <br>




=={{header|Julia}}==
=={{header|Julia}}==

Revision as of 00:16, 15 February 2020

Yellowstone sequence is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

The Yellowstone Permutation



The Yellowstone sequence, also called the Yellowstone permutation, is defined as:

For n <= 3,

a(n) = n.

For n >= 4,

a(n) = the smallest number not already in sequence such that a(n) is relatively prime to a(n-1) and is not relatively prime to a(n-2).

The sequence is a permutation of the natural numbers, and gets its name from what its authors felt was a spiking, fountain like appearance of a plot of the sequence.


Task

Find and show as output the first 30 Yellowstone numbers.


Extra

Demonstrate how to plot, with x = n and y coordinate a(n), the first 100 Yellowstone numbers.


Example

a(4) is 4 because 4 is the smallest number following 1, 2, 3 in the sequence that is relatively prime to the entry before it (3), and is not relatively prime to the number two entries before it (2).

Related tasks

See also:




Julia

<lang julia>using Plots

function yellowstone(N)

   a = [1, 2, 3]
   b = Dict(1 => 1, 2 => 1, 3 => 1)
   while length(a) < N
       for i in 4:typemax(Int)
           if !haskey(b, i) && (gcd(i, a[end]) == 1) && (gcd(i, a[end - 1]) > 1)
               push!(a, i)
               b[i] = 1
               break
           end
       end
   end
   return a

end

println(yellowstone(30))

x = 1:100 y = yellowstone(100) plot(x, y)

</lang>

Output:
The first 30 entris 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]