How to resolve the algorithm Yellowstone sequence step by step in the XPL0 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Yellowstone sequence step by step in the XPL0 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 XPL0 programming language
Source code in the xpl0 programming language
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
]
You may also check:How to resolve the algorithm Bitmap/Bézier curves/Quadratic step by step in the Go programming language
You may also check:How to resolve the algorithm Tonelli-Shanks algorithm step by step in the D programming language
You may also check:How to resolve the algorithm Priority queue step by step in the ATS programming language
You may also check:How to resolve the algorithm Find Chess960 starting position identifier step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Magic squares of doubly even order step by step in the Go programming language