OFFSET
1,2
COMMENTS
Sequence is a permutation of the positive integers.
The permutation is self-inverse. Except for fixed points 1, 2, 3 it consists completely of 2-cycles: (4,5), (6,7), (8,11), (9,10), (12,15), (13,14), (16,23), (17,22), ..., (24,31), ..., (32,47), ... . - Klaus Brockhaus
The permutation transforms enumeration system of positive irreducible fractions A071766/A229742 (HCS) into enumeration system A245325/A245326, and vice versa. - Yosu Yurramendi, Jun 09 2015
LINKS
FORMULA
For n >= 2: If a(n-1) = 2^m, m=positive integer, then a(n)= 2^(m+1)-1. If a(n-1) = 3*2^m, m= nonnegative integer, then a(n) = 3*2^(m+1)-1. Otherwise, a(n) = a(n-1) -1.
For n >= 2: a(2*n) = 2*a(n)+1, a(2*n+1) = 2*a(n). - Yosu Yurramendi, Jun 08 2015
MAPLE
A[1]:= 1: A[2]:= 2: B[1]:= 0: B[2]:= 0:
for n from 3 to 100 do
for m from A[n-1]-1 by A[n-1] while assigned(B[m]) do od:
A[n]:= m;
B[m]:= 0;
od:
seq(A[n], n=1..100); # Robert Israel, Jun 09 2015
MATHEMATICA
f[n_] := Block[{a = {1}, i, k}, Do[k = 1; While[Or[Mod[k, a[[i - 1]]] != a[[i - 1]] - 1, MemberQ[a, k]], k++]; AppendTo[a, k], {i, 2, n}]; a]; f@ 120 (* Michael De Vlieger, Jun 11 2015 *)
A[n_]:= If[n<4, n, If[EvenQ[n], 2A[n/2] + 1, 2A[(n - 1)/2]]]; Table[A[n], {n, 100}] (* Indranil Ghosh, Mar 21 2017 *)
f[lst_List] := Block[{k = 2, m = lst[[-1]]}, While[ MemberQ[lst, k] || 1 + Mod[k, m] != m, k++]; Append[lst, k]]; Nest[f, {1}, 70] (* Robert G. Wilson v, Jan 22 2018 *)
PROG
(R)
a <- 1:3 # If it were c(1, 3, 2), it would be A054429
maxn <- 50 # by choice
#
for(n in 2:maxn){
a[2*n ] <- 2*a[n]+1
a[2*n+1] <- 2*a[n]
}
#
a
# Yosu Yurramendi, Jun 08 2015
(PARI) A(n) = if(n<4, n, if(n%2, 2*A(n\2), 2*A(n/2)+1));
for(n=1, 50, print1(A(n), ", ")) \\ Indranil Ghosh, Mar 21 2017
CROSSREFS
KEYWORD
easy,nonn
AUTHOR
Leroy Quet, Apr 19 2006
EXTENSIONS
More terms from Klaus Brockhaus
STATUS
approved