%I #38 Jul 13 2022 02:06:50
%S 0,1,2,3,4,5,6,7,8,9,10,12,14,16,18,21,23,25,27,29,30,32,34,36,38,41,
%T 43,45,47,49,50,52,54,56,58,61,63,65,67,69,70,72,74,76,78,81,83,85,87,
%U 89,90,92,94,96,98,101,103,105,107,109,121,123,125,127,129
%N Numbers in which parity of the decimal digits alternates.
%C An alternating integer is a positive integer for which, in base-10, the parity of its digits alternates.
%C The number of terms < 10^n (n>=0): 1, 10, 55, 280, 1405, 7030, 35155, ..., . - _Robert G. Wilson v_, Apr 01 2011
%C 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
%C A228710(a(n)) = 1. - _Reinhard Zumkeller_, Aug 31 2013
%H Reinhard Zumkeller, <a href="/A030141/b030141.txt">Table of n, a(n) for n = 1..10000</a>
%H 45th International Mathematical Olympiad (45th IMO), <a href="http://www.jstor.org/stable/30044168">Problem #6 and Solution</a>, Mathematics Magazine, 78 (2005), pp. 247, 250, 251.
%H <a href="/index/Ar#10-automatic">Index entries for 10-automatic sequences</a>.
%e 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.
%t 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 *)
%o (Haskell)
%o a030141 n = a030141_list !! (n-1)
%o a030141_list = filter ((== 1) . a228710) [0..]
%o -- _Reinhard Zumkeller_, Aug 31 2013
%o (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
%o (Python)
%o from itertools import count
%o def A030141_gen(startvalue=0): # generator of terms >= startvalue
%o return filter(lambda n:all(int(a)+int(b)&1 for a, b in zip(str(n),str(n)[1:])),count(max(startvalue,0)))
%o A030141_list = list(islice(A030141_gen(),30)) # _Chai Wah Wu_, Jul 12 2022
%o (Python)
%o from itertools import chain, count, islice
%o def altgen(seed, digits):
%o allowed = "02468" if seed in "13579" else "13579"
%o if digits == 1: yield from allowed; return
%o for f in allowed: yield from (f + r for r in altgen(f, digits-1))
%o 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)))
%o print(list(islice(agen(), 65))) # _Michael S. Branicky_, Jul 12 2022
%Y Complement: A228709.
%Y Subsequences: A030142, A030143, A030144, A030147, A030152, A062285.
%Y Cf. A110303, A110304, A110305, A056830, A103181, A228722, A228723.
%K nonn,base,easy
%O 1,3
%A _Patrick De Geest_
%E Offset corrected by _Reinhard Zumkeller_, Aug 31 2013