OFFSET
0,3
COMMENTS
This sequence seems likely to be a permutation of the nonnegative integers.
A245340(n) = smallest m such that a(m) = n, or -1 if n never appears.
See A245394 and A245395 for record values of a(n) and where they occur. - Reinhard Zumkeller, Jul 21 2014
See A370956 and A370959 for record values of the inverse A245340 and where they occur. - N. J. A. Sloane, Apr 29 2024
A very nice (maybe the most natural) variant of Recamán's sequence A005132. - M. F. Hasler, Nov 03 2014
LINKS
Reinhard Zumkeller, Table of n, a(n) for n = 0..100000 (first 10000 terms from Ferenc Adorján)
Ferenc Adorján, Some characteristics of Leroy Quet's permutation sequences
N. J. A. Sloane, Log-log plot of A370956 vs A370959 (shows terms in A125717 that take the longest to appear).
MATHEMATICA
f[l_List] := Block[{n = Length[l], k = Mod[l[[ -1]], n]}, While[MemberQ[l, k], k += n]; Append[l, k]]; Nest[f, {0}, 70] (* Ray Chandler, Feb 04 2007, updated for change to offset Oct 10 2019 *)
PROG
(PARI) {Quet_p2(n)=/* Permutation sequence a'la Leroy Quet, A125717 */local(x=[1], k=0, w=1); for(i=2, n, if((k=x[i-1]%i)==0, k=i); while(bittest(w, k-1)>0, k+=i); x=concat(x, k); w+=2^(k-1)); return(x)} [Ferenc Adorjan]
(Haskell)
import Data.IntMap (singleton, member, (!), insert)
a125717 n = a125717_list !! n
a125717_list = 0 : f [1..] 0 (singleton 0 0) where
f (v:vs) w m = g (reverse[w-v, w-2*v..1] ++ [w+v, w+2*v..]) where
g (x:xs) = if x `member` m then g xs else x : f vs x (insert x v m)
-- Reinhard Zumkeller, Jul 21 2014
(PARI) A125717(n, show=0)={my(u=1, a); for(n=1, n, a%=n; while(bittest(u, a), a+=n); u+=1<<a; show&&print1(a", ")); a} \\ M. F. Hasler, Nov 03 2014
(Python)
from itertools import count, islice
def agen(): # generator of terms
an, aset = 0, {0}
for n in count(1):
yield an
an = next(m for m in count(an%n, n) if m not in aset)
aset.add(an)
print(list(islice(agen(), 70))) # Michael S. Branicky, Jun 07 2023
CROSSREFS
KEYWORD
AUTHOR
Leroy Quet, Feb 01 2007
EXTENSIONS
Extended by Ray Chandler, Feb 04 2007
a(0) added by Franklin T. Adams-Watters, Mar 31 2014
Edited by N. J. A. Sloane, Mar 15 2024
STATUS
approved