A335663 For n >= 1, a(n) = f(n) where f is a bijection on Z such that f(x)-x is also a bijection on Z and f(f(x)) = x.
2, 1, 6, 9, 12, 3, 16, 19, 4, 23, 26, 5, 30, 33, 36, 7, 40, 43, 8, 47, 50, 53, 10, 57, 60, 11, 64, 67, 70, 13, 74, 77, 14, 81, 84, 15, 88, 91, 94, 17, 98, 101, 18, 105, 108, 111, 20, 115, 118, 21, 122, 125, 22, 129, 132, 135, 24, 139, 142, 25, 146, 149, 152
Offset: 1
Keywords
Examples
We begin with a(1) = 2. To calculate a(2): we first check if 2 has appeared in this sequence before. Indeed since a(1) = 2 we set a(2) = 1. For a(3): observe that 3 has not appeared before so we can't apply Rule 1. Since we have performed rule 2 zero times before, therefore, a(3) = 3+2(0)+3 = 6. For a(4): we cannot apply Rule 1 as 4 has not appeared before. We have applied Rule 2 one time before and hence a(4) = 4+2(1)+3 = 9. Similarly a(5) = 5+2(2)+3 = 12. However for a(6) we see a(3) = 6 and hence due to Rule 1, we must set a(6) = 3.
Programs
-
Maple
a:= proc() local h, t; t:=0; proc(n) option remember; if n<3 then 3-n else h:= 3+n+2*t; a(h):= n; t:= t+1; h fi end end(): seq(a(n), n=1..100); # Alois P. Heinz, Jun 17 2020
-
Mathematica
Nest[Append[#1, If[! FreeQ[#1[[All, 1]], #2], {FirstPosition[#1[[All, 1]], #2][[1]], #1[[-1, -1]]}, {#2 + 2 #1[[-1, -1]] + 3, 1 + #1[[-1, -1]]}]] & @@ {#, Length[#] + 1} &, {{2, 0}}, 62][[All, 1]] (* Michael De Vlieger, Jun 17 2020 *)
-
Python
Used = [(1, 2)] def bfun(num): print("a(1)=2") for i in range(2, num + 1): if any(i in coordinate for coordinate in Used): for j in range(0, len(Used) + 1): if i in Used[j]: print("a(" + str(i) + ")=" + str(Used[j][0])) break else: Used.append((i, i + 2 * len(Used) + 1)) print("a(" + str(i) + ")=" + str(i + 2 * len(Used) - 1)) bfun(70)
Formula
a(1) = 2 and for all i > 1 we define a(i) as follows:
Rule 1 : a(i) = j if there is some j such that j < i and a(j) = i.
Rule 2 : If Rule 1 cannot be performed then a(i) = i+2n+3 , if this rule applied n times previously.
Comments