Inconsummate numbers in base 10: Difference between revisions

Content added Content deleted
(Added Wren)
m (Python example)
Line 30: Line 30:
;* [[oeis:A003635|OEIS:A003635 - Inconsummate numbers in base 10]]
;* [[oeis:A003635|OEIS:A003635 - Inconsummate numbers in base 10]]


=={{header|Python}}==
<syntaxhighlight lang=python>''' Rosetta code rosettacode.org/wiki/Inconsummate_numbers_in_base_10 '''


def digitalsum(num):
''' Return sum of digits of a number in base 10 '''
return sum(int(d) for d in str(num))


def generate_inconsummate(max_wanted):
''' generate the series of inconsummate numbers up to max_wanted '''
minimum_digitsums = [(10**i, int((10**i - 1) / (9 * i)))
for i in range(1, 15)]
limit = min(p[0] for p in minimum_digitsums if p[1] > max_wanted)
arr = [1] + [0] * (limit - 1)

for dividend in range(1, limit):
quo, rem = divmod(dividend, digitalsum(dividend))
if rem == 0 and quo < limit:
arr[quo] = 1
for j, flag in enumerate(arr):
if flag == 0:
yield j


for i, n in enumerate(generate_inconsummate(100000)):
if i < 50:
print(f'{n:6}', end='\n' if (i + 1) % 10 == 0 else '')
elif i == 999:
print('\nThousandth inconsummate number:', n)
elif i == 9999:
print('\nTen-thousanth inconsummate number:', n)
elif i == 99999:
print('\nHundred-thousanth inconsummate number:', n)
break
</syntaxhighlight>{{out}}
<pre>
62 63 65 75 84 95 161 173 195 216
261 266 272 276 326 371 372 377 381 383
386 387 395 411 416 422 426 431 432 438
441 443 461 466 471 476 482 483 486 488
491 492 493 494 497 498 516 521 522 527

Thousandth inconsummate number: 6996

Ten-thousanth inconsummate number: 59853

Hundred-thousanth inconsummate number: 375410
</pre>