A274648 A variation on Recamán's sequence (A005132): a(n) is the first positive number of the form a(n-1)-n*k, k>0 not already in the sequence; and if no such number exists, then a(n) is the first number of the form a(n-1)+n*k, k>0 not already in the sequence.
0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9, 24, 8, 25, 43, 5, 45, 66, 44, 67, 19, 69, 17, 71, 15, 73, 103, 72, 40, 106, 38, 108, 36, 110, 34, 112, 32, 114, 30, 116, 28, 118, 26, 120, 168, 119, 169, 16, 68, 121, 175, 65, 177, 63, 179, 61, 181, 59, 183
Offset: 0
Keywords
Links
Programs
-
Mathematica
f[s_List] := Block[{k = 1, l = s[[-1]], n = Length@ s}, While[ MemberQ[s, l - k*n] && l > k*n, k++]; If[l > k*n, Append[s, l - k*n], k = 1; While[ MemberQ[s, l + k*n], k++]; Append[s, l + k*n]]]; Nest[f, {0}, 60] (* Robert G. Wilson v, Sep 07 2016 *)
Comments