OFFSET
1,2
COMMENTS
LINKS
Chai Wah Wu, Table of n, a(n) for n = 1..10000
David L. Applegate, Hans Havermann, Bob Selcoe, Vladimir Shevelev, N. J. A. Sloane, and Reinhard Zumkeller, The Yellowstone Permutation, arXiv preprint arXiv:1501.01669 [math.NT], 2015 and J. Int. Seq. 18 (2015) 15.6.7.
MATHEMATICA
a[1]=1; a[2]=3; a[3]=2;
A251555 = Array[a, 3];
a[n_] := a[n] = For[k=2, True, k++, If[FreeQ[A251555, k], If[!CoprimeQ[k, a[n-2]] && CoprimeQ[k, a[n-1]], AppendTo[A251555, k]; Return[k]]]];
A251555 = Array[a, 100] (* Jean-François Alcover, Aug 02 2018 *)
PROG
(Python)
from fractions import gcd
A251555_list, l1, l2, s, b = [1, 3, 2], 2, 3, 4, set()
for _ in range(10**4):
....i = s
....while True:
........if not i in b and gcd(i, l1) == 1 and gcd(i, l2) > 1:
............A251555_list.append(i)
............l2, l1 = l1, i
............b.add(i)
............while s in b:
................b.remove(s)
................s += 1
............break
........i += 1 # Chai Wah Wu, Dec 21 2014
(Haskell)
import Data.List (delete)
a251555 n = a251555_list !! (n-1)
a251555_list = 1 : 3 : 2 : f 3 2 [4..] where
f u v ws = g ws where
g (x:xs) = if gcd x u > 1 && gcd x v == 1
then x : f v x (delete x ws) else g xs
-- Reinhard Zumkeller, Dec 24 2014
CROSSREFS
KEYWORD
nonn
AUTHOR
N. J. A. Sloane, Dec 21 2014
STATUS
approved