login
This site is supported by donations to The OEIS Foundation.
Logo

Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A006509 Cald's sequence: a(n+1)=a(n)-p(n) if new and >0, else a(n)+p(n) if new, otherwise 0, where p(n) = n-th prime.
(Formerly M2539)
13
1, 3, 6, 11, 4, 15, 2, 19, 38, 61, 32, 63, 26, 67, 24, 71, 18, 77, 16, 83, 12, 85, 164, 81, 170, 73, 174, 277, 384, 275, 162, 35, 166, 29, 168, 317, 468, 311, 148, 315, 142, 321, 140, 331, 138, 335, 136, 347, 124, 351, 122, 355, 116, 357, 106, 363, 100, 369, 98, 375, 94, 377, 84, 391, 80, 393, 76, 407, 70, 417, 68, 421, 62, 429, 56, 435, 52, 441, 44, 445, 36, 455, 34, 465, 898, 459, 902, 453, 910, 449, 912, 1379, 900, 413, 904, 405, 908, 399, 920, 397, 938, 1485, 928, 365, 934, 1505, 2082, 1495, 2088, 1489, 888, 281, 894, 1511, 892, 261, 0, 643, 1290, 637, 1296, 635, 1308, 631, 1314, 623, 1324, 615, 1334, 607, 1340 (list; graph; refs; listen; history; internal format)
OFFSET

1,2

REFERENCES

F. Cald, Problem 356, Franciscan order, J. Rec. Math., 7 (No. 4, 1974), 318; 10 (No. 1, 1974), 62-64.

"Cald's Sequence", Popular Computing (Calabasas, CA), Vol. 4 (No. 41, Aug 1976), pp. 16-17.

N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

LINKS

T. D. Noe, Table of n, a(n) for n=1..10000

MAPLE

M1:=500000; a:=array(0..M1); have:=array(0..M1); a[0]:=1;

for n from 0 to M1 do have[n]:=0; od: have[0]:=1; have[1]:=1;

M2:=2000; nmax:=M2; for n from 1 to M2 do p:=ithprime(n); i:=a[n-1]-p; j:=a[n-1]+p;

if i >= 1 and have[i]=0 then a[n]:=i; have[i]:=1;

elif j <= M1 and have[j]=0 then a[n]:=j; have[j]:=1;

elif j <= M1 then a[n]:=0; else nmax:=n-1; break; fi; od:

# To get A006509:

[seq(a[n], n=0..M2)];

# To get A112877 (off by 1 because of different offset in A006509):

zzz:=[]; for n from 0 to nmax do if a[n]=0 then zzz:=[op(zzz), n]; fi; od: [seq(zzz[i], i=1..nops(zzz))];

MATHEMATICA

lst = {1}; f := Block[{b = Last@lst, p = Prime@ Length@lst}, If[b > p && !MemberQ[lst, b - p], AppendTo[lst, b - p], If[ !MemberQ[lst, b + p], AppendTo[lst, b + p], AppendTo[lst, 0]] ]]; Do[f, {n, 60}]; lst (from Robert G. Wilson v (rgwv(at)rgwv.com), Apr 25 2006)

PROG

(Haskell)

a006509 n = a006509_list !! (n-1)

a006509_list = 1 : f [1] a000040_list where

   f xs'@(x:_) (p:ps) | x' > 0 && x' `notElem` xs = x' : f (x':xs) ps

                      | x'' `notElem` xs          = x'' : f (x'':xs) ps

                      | otherwise                 = 0 : f (0:xs) ps

                      where x' = x - p; x'' = x + p

-- Reinhard Zumkeller, Oct 17 2011

CROSSREFS

Cf. A005132, A093903. Zeros are in A112877. Sorted: A111338, A111339.

Cf. A117128, A117129, A064365.

Cf. A000040.

Sequence in context: A110080 A093903 A117128 * A144562 A102889 A183543

Adjacent sequences:  A006506 A006507 A006508 * A006510 A006511 A006512

KEYWORD

nonn,nice,easy

AUTHOR

N. J. A. Sloane (njas(AT)research.att.com).

EXTENSIONS

More terms from Larry Reeves (larryr(AT)acm.org), Jul 20 2001

Many more terms added by N. J. A. Sloane (njas(AT)research.att.com), Apr 20 2006, to show difference from A117128.

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Transforms | Puzzles | Hot | Classics
Recent Additions | More pages | Superseeker | Maintained by The OEIS Foundation Inc.

Content is available under The OEIS End-User License Agreement .

Last modified February 15 21:23 EST 2012. Contains 205856 sequences.