OFFSET
1,3
COMMENTS
An alternating integer is a positive integer for which, in base-10, the parity of its digits alternates.
The number of terms < 10^n (n>=0): 1, 10, 55, 280, 1405, 7030, 35155, ..., . - Robert G. Wilson v, Apr 01 2011
The number of terms between 10^n and 10^(n+1) is 9 * 5^n for n>=0. For n>=0, number of terms < 10^n is 1 + 9 * (5^n-1)/4. - Franklin T. Adams-Watters, Apr 01 2011
A228710(a(n)) = 1. - Reinhard Zumkeller, Aug 31 2013
LINKS
Reinhard Zumkeller, Table of n, a(n) for n = 1..10000
45th International Mathematical Olympiad (45th IMO), Problem #6 and Solution, Mathematics Magazine, 78 (2005), pp. 247, 250, 251.
EXAMPLE
121 is alternating and in the sequence because its consecutive digits are odd-even-odd, 1 being odd and 2 even. Of course, 1234567890 is also alternating.
MATHEMATICA
fQ[n_] := Block[{m = Mod[ IntegerDigits@ n, 2]}, m == Split[m, UnsameQ][[1]]]; Select[ Range[0, 130], fQ] (* Robert G. Wilson v, Apr 01 2011 *)
PROG
(Haskell)
a030141 n = a030141_list !! (n-1)
a030141_list = filter ((== 1) . a228710) [0..]
-- Reinhard Zumkeller, Aug 31 2013
(PARI) is(n, d=digits(n))=for(i=2, #d, if((d[i]-d[i-1])%2==0, return(0))); 1 \\ Charles R Greathouse IV, Jul 08 2022
(Python)
from itertools import count
def A030141_gen(startvalue=0): # generator of terms >= startvalue
return filter(lambda n:all(int(a)+int(b)&1 for a, b in zip(str(n), str(n)[1:])), count(max(startvalue, 0)))
(Python)
from itertools import chain, count, islice
def altgen(seed, digits):
allowed = "02468" if seed in "13579" else "13579"
if digits == 1: yield from allowed; return
for f in allowed: yield from (f + r for r in altgen(f, digits-1))
def agen(): yield from chain(range(10), (int(f+r) for d in count(2) for f in "123456789" for r in altgen(f, d-1)))
print(list(islice(agen(), 65))) # Michael S. Branicky, Jul 12 2022
CROSSREFS
KEYWORD
nonn,base,easy
AUTHOR
EXTENSIONS
Offset corrected by Reinhard Zumkeller, Aug 31 2013
STATUS
approved