OFFSET
1,2
COMMENTS
A variation of Cald's sequence A006509; a sequence of distinct positive integers with property that absolute successive differences are distinct primes.
A more long-winded definition: Start with a(1) = 1. Keep a list of the primes that have been used so far; initially this list is empty. Each prime can be used at most once.
To get a(n), subtract from a(n-1) each prime p < a(n-1) that has not yet been used, starting from the smallest. If for any such p, a(n-1)-p is not yet in the sequence, set a(n) = a(n-1)-p and mark p as used.
If no p works, then add each prime p that has not yet been used to a(n-1), again starting with the smallest. When p is such that a(n-1)+p is not yet in the sequence, set a(n) = a(n-1)+p and mark p as used. Repeat.
The main question is: does every number appear in the sequence?
LINKS
Alois P. Heinz, Table of n, a(n) for n = 1..10000
EXAMPLE
1 -> 1+2 = 3 and prime 2 has been used.
3 -> 3+3 = 6 and prime 3 has been used.
6 could go to 6-5 = 1, except 1 is already in the sequence; so 6 -> 6+5 = 11 and prime 5 has been used.
11 -> 11-7 = 4 (for the first time we can subtract) and prime 7 has been used.
PROG
(Haskell)
import Data.List (delete)
a093903 n = a093903_list !! (n-1)
a093903_list = 1 : f [1] a000040_list where
f xs@(x:_) ps = g ps where
g (q:qs) | x <= q = h ps
| y `notElem` xs = y : f (y:xs) (delete q ps)
| otherwise = g qs where
y = x - q
h (r:rs) | z `notElem` xs = z : f (z:xs) (delete r ps)
| otherwise = h rs where
z = x + r
-- Reinhard Zumkeller, Oct 17 2011
CROSSREFS
KEYWORD
AUTHOR
Amarnath Murthy, May 24 2004
EXTENSIONS
Definition (and sequence) corrected by R. Piyo (nagoya314(AT)yahoo.com) and N. J. A. Sloane, Dec 09 2004
Edited, offset changed to 1, a(16) and following terms added by Klaus Brockhaus, Nov 10 2005
STATUS
approved