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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Yellowstone sequence step by step in the AutoHotkey 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 AutoHotkey programming language

Source code in the autohotkey programming language

A := [], in_seq := []
loop 30 {
    n := A_Index
    if n <=3
        A[n] := n,    in_seq[n] := true
    else while true
    {
        s := A_Index
        if !in_seq[s] && relatively_prime(s, A[n-1]) && !relatively_prime(s, A[n-2])
        {
            A[n] := s
            in_seq[s] := true
            break
        }
    }
}
for i, v in A
    result .= v ","
MsgBox % result := "[" Trim(result, ",") "]"
return
;--------------------------------------
relatively_prime(a, b){
    return (GCD(a, b) = 1)
}
;--------------------------------------
GCD(a, b) {
    while b
        b := Mod(a | 0x0, a := b)
    return a
}


  

You may also check:How to resolve the algorithm Anonymous recursion step by step in the Qi programming language
You may also check:How to resolve the algorithm User input/Graphical step by step in the Quackery programming language
You may also check:How to resolve the algorithm Bitwise IO step by step in the Ada programming language
You may also check:How to resolve the algorithm Nth root step by step in the Scheme programming language
You may also check:How to resolve the algorithm Secure temporary file step by step in the NetRexx programming language