A118966 a(n) = (n+1)/2 if n occurs among the first n-1 terms of the sequence, otherwise a(n) = 2*n - 1.
1, 3, 2, 7, 9, 11, 4, 15, 5, 19, 6, 23, 25, 27, 8, 31, 33, 35, 10, 39, 41, 43, 12, 47, 13, 51, 14, 55, 57, 59, 16, 63, 17, 67, 18, 71, 73, 75, 20, 79, 21, 83, 22, 87, 89, 91, 24, 95, 97, 99, 26, 103, 105, 107, 28, 111, 29, 115, 30, 119, 121, 123, 32, 127, 129, 131, 34, 135
Offset: 1
Programs
-
MATLAB
% Program to test alternative definition: %"Permutation of natural number such that max(a(n)/n)-min(a(n)/n) increases monotonously by using smallest possible next number, a(0) = 0, a(1) = 1." function a = A118966( max_n ) a(1) = 0; a(2) = 1; m_max = 1; m_min = 1; n = 3; t = 1; while n <= max_n % search next number t not yet used in a while ~isempty(find(a==t, 1)) t = t+1; end m = t/(n-1); % check slope m if m < m_min || m > m_max % we found a candidate a(n) = t; n = n+1; if m > m_max m_max = m; end if m < m_min m_min = m; end t = 1; else % number t does not yet fit t = t+1; end end end % Thomas Scheuerle, Dec 24 2020
-
Mathematica
f[s_] := Block[{n = Length@s}, Append[s, If[MemberQ[s, n], (n + 1)/2, 2n - 1]]]; Rest@Nest[f, {1}, 70] (* Robert G. Wilson v, May 16 2006 *) (* Program to test alternative definition : *) (* "Permutation of natural number such that max(a(n)/n)-min(a(n)/n) increases monotonously by using smallest possible next number, a(0) = 0, a(1) = 1." *) Block[{a = {0, 1}, b = {1}, c = {0}, k, r, s}, Do[k = 2; While[Nand[Set[s, Max[#] - Min[#]] > c[[-1]], FreeQ[a, k]] &@ Append[b, Set[r, k/i]], k++]; AppendTo[a, k]; AppendTo[b, r]; AppendTo[c, s], {i, 2, 55}]; a] (* Michael De Vlieger, Dec 11 2020 *)
Formula
a(n) = A073675(n-1) + 1. - Thomas Scheuerle, Dec 27 2020
Extensions
More terms from Robert G. Wilson v, May 16 2006
Comments