OFFSET
1,2
COMMENTS
This is sequence (d(n)) generated by the following generic rule, "Rule 3" (see below) with parameters a(1) = 0 and d(1) = 1, while A257906 gives the corresponding sequence a(n).
Rule 3 follows. For k >= 1, let A(k) = {a(1), …, a(k)} and D(k) = {d(1), …, d(k)}. Begin with k = 1 and nonnegative integers a(1) and d(1).
Step 1: If there is an integer h such that 1 - a(k) < h < 0 and h is not in D(k) and a(k) + h is not in A(k), let d(k+1) be the least such h, let a(k+1) = a(k) + h, replace k by k + 1, and repeat Step 1; otherwise do Step 2.
Step 2: Let h be the least positive integer not in D(k) such that a(k) - h is not in A(k). Let a(k+1) = a(k) + h and d(k+1) = h. Replace k by k+1 and do Step 1.
See A257905 for a guide to related sequences and conjectures.
An informal version of Rule 3 follows: the sequences "d" and "a" are jointly generated, the "driving idea" idea being that each new term of "d" is obtained by a greedy algorithm. See A131388 for a similar procedure (Rule 1).
LINKS
Clark Kimberling (first 1000 terms) & Antti Karttunen, Table of n, a(n) for n = 1..10000
EXAMPLE
a(1) = 0, d(1) = 1;
a(2) = 2, d(2) = 2;
a(3) = 5, d(3) = 3;
a(4) = 3, d(4) = -2.
MATHEMATICA
{a, f} = {{0}, {1}}; Do[tmp = {#, # - Last[a]} &[Min[Complement[#, Intersection[a, #]]&[Last[a] + Complement[#, Intersection[f, #]] &[Range[2 - Last[a], -1]]]]];
If[! IntegerQ[tmp[[1]]], tmp = {Last[a] + #, #} &[NestWhile[# + 1 &, 1, ! (! MemberQ[f, #] && ! MemberQ[a, Last[a] - #]) &]]]; AppendTo[a, tmp[[1]]]; AppendTo[f, tmp[[2]]], {120}]; {a, f} (* Peter J. C. Moses, May 14 2015 *)
PROG
(Scheme, with memoization-macro definec)
;; Naive quadratic algorithm, but suffices us for now. Needs also code from A257906:
(definec (A257907 n) (cond ((= 1 n) 1) (else (let ((k (- n 1)) (a_k (A257906 (- n 1)))) (let aloop ((h (+ 1 (- 1 a_k)))) (cond ((zero? h) (let bloop ((h 1)) (cond ((and (not_in_range_of? (- a_k h) A257906 k) (not_in_range_of? h A257907 k)) h) (else (bloop (+ 1 h)))))) ((and (not_in_range_of? (+ a_k h) A257906 k) (not_in_range_of? h A257907 k)) h) (else (aloop (+ 1 h)))))))))
(define (not_in_range_of? k fun upto_n) (let loop ((i 1)) (cond ((> i upto_n) #t) ((= (fun i) k) #f) (else (loop (+ i 1))))))
;; Antti Karttunen, May 20 2015
(Haskell)
import Data.List ((\\))
a257907 n = a257907_list !! (n-1)
a257907_list = 1 : f [0] [1] where
f xs@(x:_) ds = g [2 - x .. -1] where
g [] = h : f ((x + h) : xs) (h : ds) where
(h:_) = [z | z <- [1..] \\ ds, x - z `notElem` xs]
g (h:hs) | h `notElem` ds && y `notElem` xs = h : f (y:xs) (h:ds)
| otherwise = g hs
where y = x + h
-- Reinhard Zumkeller, Jun 03 2015
CROSSREFS
KEYWORD
sign,easy
AUTHOR
Clark Kimberling, May 16 2015
STATUS
approved