How to resolve the algorithm Yellowstone sequence step by step in the zkl programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Yellowstone sequence step by step in the zkl programming language

Table of Contents

Problem Statement

The Yellowstone sequence, also called the Yellowstone permutation, is defined as: For n <= 3, For n >= 4,

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

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).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Yellowstone sequence step by step in the zkl programming language

Source code in the zkl programming language

fcn yellowstoneW{	// --> iterator
   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);
}

println("The first 30 entries of the Yellowstone permutation:");
yellowstoneW().walk(30).concat(", ").println();

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();

  

You may also check:How to resolve the algorithm Elementary cellular automaton/Infinite length step by step in the Raku programming language
You may also check:How to resolve the algorithm Polymorphism step by step in the M2000 Interpreter programming language
You may also check:How to resolve the algorithm Sort an array of composite structures step by step in the Ring programming language
You may also check:How to resolve the algorithm Pseudo-random numbers/PCG32 step by step in the Kotlin programming language
You may also check:How to resolve the algorithm JSON step by step in the CoffeeScript programming language