This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A261573 #13 Sep 16 2015 17:48:26 %S A261573 0,3,7,2,8,1,9,18,28,17,5,18,4,19,35,52,34,15,35,14,36,13,37,12,38,11, %T A261573 39,10,40,71,103,70,104,69,33,70,32,71,31,72,30,73,29,74,120,167,119, %U A261573 168,118,67,119,66,120,65,121,64,6,65,125,186,124,61,125,60,126,59,127,58,128,57 %N A261573 A variation of Recamán's sequence A005132: Define a(0) = 0, and for n > 0, a(n) = a(n-1) - (n+2) if positive and not already in the sequence, otherwise a(n) = a(n-1) + (n+2). %C A261573 As in Recamán's sequence, terms are repeated, the first being 18 = a(7) = a(11). %C A261573 More generally, for k >= 0, a_k(0) = 0, and for n > 0, a_k(n) = a_k(n-1) - (n+k) if positive and not already in the sequence, otherwise a_k(n) = a_k(n-1) + (n+k). %C A261573 For k = 0, this is Recamán's sequence A005132. %H A261573 Freddy Barrera, <a href="/A261573/b261573.txt">Table of n, a(n) for n = 0..10000</a> %H A261573 Freddy Barrera, <a href="/A261573/a261573.png">Line plot of the first 1000 terms.</a> %H A261573 Freddy Barrera, <a href="/A261573/a261573_1.png">Scatter plot of the first 1000 terms.</a> %H A261573 Freddy Barrera, <a href="/A261573/a261573_2.png">Line plot of the first 1000 terms when k = 0, 1, 2, ..., 9</a> %H A261573 Freddy Barrera, <a href="/A261573/a261573_3.png">Scatter plot of the first 1000 terms when k = 0, 1, 2, ..., 9</a> %t A261573 f[s_List] := Block[{a = s[[-1]], len = Length@ s}, Append[s, If[a > len + 1 && ! MemberQ[s, a - len - 2], a - len - 2, a + len + 2]]]; Nest[f, {0}, 70] (* _Robert G. Wilson v_, Sep 08 2015 *) %o A261573 (Python) %o A261573 def sequence(n, k): %o A261573 """For n > 0 and k >= 0, generates the first n terms of the sequence""" %o A261573 A, a = {0}, 0 %o A261573 yield a %o A261573 for n in range(1, n + 1): %o A261573 a = a - (n + k) %o A261573 if a > 0 and a not in A: %o A261573 A.add(a) %o A261573 yield a %o A261573 else: %o A261573 a = a + 2 * (n + k) %o A261573 A.add(a) %o A261573 yield a %o A261573 # List of the first 1000 terms of the sequence with k = 2. %o A261573 list(sequence(1000, 2)) %Y A261573 Cf. A005132, A057167. %K A261573 nonn %O A261573 0,2 %A A261573 _Freddy Barrera_, Aug 24 2015