OFFSET
0,4
COMMENTS
A version of a greedy construction of an integer-valued function a such that a(n)/a(n+1) runs through all nonnegative rationals exactly once.
After initial 0, odd-indexed terms are integers in order with m repeated phi(m) times; even-indexed terms are the corresponding numbers <= m and relatively prime to m, in descending order. - Franklin T. Adams-Watters, Dec 06 2006
LINKS
Reinhard Zumkeller, Table of n, a(n) for n = 0..10000
N. J. A. Sloane, FORTRAN program
EXAMPLE
After [0 1 1 2 1 3 2] we have seen the fractions 0/1, 1/1, 1/2, 2/1, 1/3, 3/2; we consider k = 1, 3, 4, 5, ...; the first of these that gives a new ratio is k=3, giving 2/3, so the next term is 3.
MATHEMATICA
a[0] = 0; a[1] = a[2] = 1; a[n_] := a[n] = Module[{m = a[n-1], ff = Table[ a[i]/a[i+1], {i, 0, n-2}], ok}, ok := GCD[m, k] == 1 && FreeQ[ff, m/k]; For[k = m-1, k >= 1, k--, If[ok, Return[k]]]; For[k = m+1, True, k++, If[ok, Return[k]]]]; Table[a[n], {n, 0, 89}] (* Jean-François Alcover, Oct 28 2017 *)
PROG
(Haskell) Following Franklin T. Adams-Watters's comment.
import Data.List (transpose)
a071912 n = a071912_list !! n
a071912_list = 0 : concatMap f [1..] where
f x = concat $ transpose [take (length tots) $ repeat x, reverse tots]
where tots = a038566_row x
-- Reinhard Zumkeller, Dec 16 2013
CROSSREFS
KEYWORD
AUTHOR
N. J. A. Sloane, Jun 13 2002
STATUS
approved