How to resolve the algorithm Yellowstone sequence step by step in the J programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Yellowstone sequence step by step in the J 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 J programming language
Source code in the j programming language
Until=: 2 :'u^:(0-:v)^:_'
assert 44 -: >:Until(>&43) 32 NB. increment until exceeding 43
gcd=: +.
coprime=: 1 = gcd
prepare=:1 2 3"_ NB. start with the vector 1 2 3
condition=: 0 1 -: (coprime _2&{.) NB. trial coprime most recent 2, nay and yay
append=: , NB. concatenate
novel=: -.@e. NB. x is not a member of y
term=: >:@:]Until((condition *. novel)~) 4:
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
GCD=: +.
relatively_prime=: 1 = GCD
yellowstone=: {{
s=. 1 2 3 NB. initial sequence
while. y > # s do.
z=. <./(1+s)-.s NB. lowest positive inteeger not in sequence
while. if. 0 1 -: z relatively_prime _2{.s do. z e. s end. do.
z=. z+1
end. NB. find next value for sequence
s=. s, z
end.
}}
You may also check:How to resolve the algorithm Happy numbers step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Test a function step by step in the Haskell programming language
You may also check:How to resolve the algorithm Check output device is a terminal step by step in the Factor programming language
You may also check:How to resolve the algorithm Discordian date step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Host introspection step by step in the UNIX Shell programming language