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!)
A140778 a(n) is the smallest positive integer such that no number occurs twice in the sequence and its absolute first differences. 6
1, 3, 7, 12, 18, 8, 17, 28, 13, 27, 43, 19, 39, 60, 22, 45, 70, 26, 55, 85, 31, 63, 96, 34, 69, 105, 37, 77, 118, 42, 88, 135, 48, 97, 147, 52, 103, 156, 56, 113, 171, 59, 120, 184, 65, 131, 198, 71, 143, 216, 74, 149, 227, 79, 159, 240, 82, 165, 249, 86, 175, 265, 91, 183 (list; graph; refs; listen; history; text; internal format)
OFFSET
1,2
COMMENTS
This sequence and its first differences include every positive integer (exactly once).
LINKS
EXAMPLE
For a(5), the sequence to that point is [1,3,7,12], with absolute differences [2,4,5]. The next number cannot be 6, because then 6 would be in both the sequence and the first differences. Since all values smaller than 6 are taken, the difference must be positive and at least 6. A difference of 6 works, a(5) = 18.
MAPLE
b:= proc() false end:
a:= proc(n) option remember; local k;
if n=1 then b(1):= true; 1
else for k while b(k) or (t-> b(t) or t=k)(abs(a(n-1)-k)) do od;
b(k), b(abs(a(n-1)-k)):= true$2; k
fi
end:
seq(a(n), n=1..100); # Alois P. Heinz, May 14 2015
MATHEMATICA
a[n_] := a[n] = Module[{}, If [n == 1, b[1] = True; 1, For[k = 1, b[k] || Function[t, b[t] || t == k][Abs[a[n-1] - k]], k++]; {b[k], b[Abs[a[n-1] - k]]} = {True, True}; k]]; Table[a[n], {n, 1, 100}] (* Jean-François Alcover, Jan 22 2017, after Alois P. Heinz *)
PROG
(PARI) IsInList(v, k) = for(i=1, #v, if(v[i]==k, return(1))); return(0) IsInDiff(v, k) = for(i=2, #v, if(abs(v[i]-v[i-1])==k, return(1))); return(0) NextA140778(v)={ local(i, d); if(#v==0, return(1)); i=2; while(1, d=abs(i-v[ #v]); if(!(i==d || IsInList(v, i) || IsInDiff(v, i) || IsInList(v, d) || IsInDiff(v, d)), return(i)); i++) } v=[]; for(i=1, 100, v=concat(v, NextA140778(v))); v
(PARI) {u=0; a=1; for(n=1, 99, u+=1<<a; print1(a", "); for(k=1, 9e9, (bittest(u, k)||bittest(u, abs(a-k))||a==2*k)&&next; u+=1<<abs(a-k); a=k; break))} \\ M. F. Hasler, May 13 2015
CROSSREFS
Sequence in context: A227133 A170883 A198463 * A095115 A310249 A310250
KEYWORD
easy,nonn
AUTHOR
STATUS
approved

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 23 20:33 EDT 2024. Contains 371916 sequences. (Running on oeis4.)