Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.
%I #18 Oct 11 2019 16:31:21
%S 1,4,7,2,5,8,3,10,13,6,11,14,9,16,19,12,17,20,23,15,22,25,18,26,21,29,
%T 24,31,27,32,35,38,28,33,37,30,39,34,40,43,36,41,44,47,42,50,53,45,49,
%U 46,51,55,48,57,52,58,61,54,59,56,62,65,68,63,67,60,69,64,70,73,66,71
%N a(1)=1; for n>1, a(n) is the smallest positive integer not occurring earlier in the sequence where |a(n)-a(n-1)| does not divide (a(n)+a(n-1)).
%C Sequence is a permutation of the positive integers.
%H Reinhard Zumkeller, <a href="/A113963/b113963.txt">Table of n, a(n) for n = 1..10000</a>
%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>
%e Among those positive integers not among the first 4 integers of the sequence, a(5) = 5 is the lowest such that |a(5)-a(4)| = |5-2| = 3 does not divide (a(5)+a(4)) = 5+2 = 7. 3, for example, is not among the first 4 terms of the sequence, but |3-2| = 1 does indeed divide (3+2). So a(5) is not 3, but is instead 5.
%t f[l_] := Block[{k=1, m}, m = Last[l]; While[MemberQ[l, k] || Mod[m + k, Abs[k - m]] == 0, k++ ]; Return[Append[l, k]]; ]; Nest[f, {1}, 100] (* _Ray Chandler_, Nov 13 2005 *)
%o (Haskell)
%o import Data.List (delete)
%o a113963 n = a113963_list !! (n-1)
%o a113963_list = 1 : f 1 [2..] where
%o f z xs = g xs where
%o g (y:ys) = if (y + z) `mod` abs (y - z) > 0
%o then y : f y (delete y xs) else g ys
%o -- _Reinhard Zumkeller_, Sep 04 2014
%o (Python)
%o A113963 = [1]
%o for n in range(1,10**2):
%o ....a, b = 1, A113963[-1]
%o ....while a in A113963 or not (a+b) % (a-b):
%o ........a += 1
%o ....A113963.append(a) # _Chai Wah Wu_, Sep 05 2014
%Y Cf. A113964, A113965, A113966.
%Y Cf. A246433 (inverse), A246704 (fixed points).
%K nonn
%O 1,2
%A _Leroy Quet_, Nov 10 2005
%E Extended by _Ray Chandler_, Nov 13 2005