login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A093903 a(1) = 1; for n > 1, a(n) = a(n-1)-p if there exists a prime p (take the smallest) that has not yet been used and is such that a(n) is new and > 0, otherwise a(n) = a(n-1)+p if the same conditions are satisfied. 11

%I #19 Apr 05 2014 09:46:27

%S 1,3,6,11,4,15,2,19,38,9,32,63,26,67,24,71,18,77,16,83,12,85,164,81,

%T 170,73,174,65,168,61,188,75,206,69,208,59,210,53,216,49,222,43,224,

%U 33,226,29,228,17,240,13,242,475,236,477,220,471,202,465,194,487,204,481,200

%N a(1) = 1; for n > 1, a(n) = a(n-1)-p if there exists a prime p (take the smallest) that has not yet been used and is such that a(n) is new and > 0, otherwise a(n) = a(n-1)+p if the same conditions are satisfied.

%C A variation of Cald's sequence A006509; a sequence of distinct positive integers with property that absolute successive differences are distinct primes.

%C 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.

%C 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.

%C 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.

%C The main question is: does every number appear in the sequence?

%H Alois P. Heinz, <a href="/A093903/b093903.txt">Table of n, a(n) for n = 1..10000</a>

%e 1 -> 1+2 = 3 and prime 2 has been used.

%e 3 -> 3+3 = 6 and prime 3 has been used.

%e 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.

%e 11 -> 11-7 = 4 (for the first time we can subtract) and prime 7 has been used.

%o (Haskell)

%o import Data.List (delete)

%o a093903 n = a093903_list !! (n-1)

%o a093903_list = 1 : f [1] a000040_list where

%o f xs@(x:_) ps = g ps where

%o g (q:qs) | x <= q = h ps

%o | y `notElem` xs = y : f (y:xs) (delete q ps)

%o | otherwise = g qs where

%o y = x - q

%o h (r:rs) | z `notElem` xs = z : f (z:xs) (delete r ps)

%o | otherwise = h rs where

%o z = x + r

%o -- _Reinhard Zumkeller_, Oct 17 2011

%Y Similar to Cald's sequence A006509 and Recamán's sequence A005132. Differs from A006509. Cf. A094746 (the primes associated with this sequence), A113959 (where n appears), A113960, A113961, A113962.

%Y Cf. A000040.

%K nonn,easy,nice,look

%O 1,2

%A _Amarnath Murthy_, May 24 2004

%E Definition (and sequence) corrected by R. Piyo (nagoya314(AT)yahoo.com) and _N. J. A. Sloane_, Dec 09 2004

%E Edited, offset changed to 1, a(16) and following terms added by _Klaus Brockhaus_, Nov 10 2005

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 25 01:06 EDT 2024. Contains 371964 sequences. (Running on oeis4.)