A340125 Numbers whose sum of even digits and sum of odd digits are equal and whose digits are in nondecreasing order.
0, 112, 134, 156, 178, 336, 358, 1223, 1245, 1267, 1289, 1447, 1469, 2334, 2356, 2378, 2558, 3445, 3467, 3489, 3669, 4556, 4578, 5667, 5689, 6778, 7889, 11114, 11136, 11158, 11338, 12225, 12247, 12269, 12449, 22233, 22345, 22367, 22389, 22556, 22578, 23447, 23469, 24455
Offset: 1
Examples
1223 is in the sequence as the sum of the odd digits is 1 + 3 = 4 and the sum of the even digits is 2 + 2 = 4 are equal.
Links
- David A. Corneth, Table of n, a(n) for n = 1..10001
Programs
-
Mathematica
seodQ[n_]:=With[{idn=IntegerDigits[n]},Total[Select[idn,EvenQ]]==Total[Select[idn,OddQ]]&&Min[Differences[idn]]>=0]; Select[Range[0,25000],seodQ] (* Harvey P. Dale, Dec 30 2024 *)
-
PARI
is(n) = { my(d = digits(n), w = vector(2)); if(d != vecsort(d), return(0)); for(i = 1, #d, w[d[i]%2 + 1] += d[i] ); w[1] == w[2] }
-
Python
def ok(n): digs = list(map(int, str(n))) return sorted(digs) == digs and sum(d*(-1)**d for d in digs) == 0 def aupto(lim): return [m for m in range(lim+1) if ok(m)] print(aupto(24455)) # Michael S. Branicky, Feb 21 2021