Inconsummate numbers in base 10: Difference between revisions
Content added Content deleted
(→{{header|Wren}}: Added a Python translation.) |
(Added Algol 68) |
||
Line 29: | Line 29: | ||
;* [https://www.numbersaplenty.com/set/inconsummate_number/ Numbers Aplenty - Inconsummate numbers] |
;* [https://www.numbersaplenty.com/set/inconsummate_number/ Numbers Aplenty - Inconsummate numbers] |
||
;* [[oeis:A003635|OEIS:A003635 - Inconsummate numbers in base 10]] |
;* [[oeis:A003635|OEIS:A003635 - Inconsummate numbers in base 10]] |
||
=={{header|ALGOL 68}}== |
|||
Constructs a table of digit sums and from that a table of consummate numbers. The table of consummate numbers will be inaccurate for numbers > 9999. |
|||
<syntaxhighlight lang="algol68"> |
|||
BEGIN # find some incomsummate numbers: integers that cannot be expressed as # |
|||
# an integer divided by the sum of its digits # |
|||
INT max number = 499 999; # maximum number we will consider # |
|||
# chosen because if we assume the 1000th # |
|||
# inconsummate number is <= 9 999, then the # |
|||
# maximum possible digit sum is 45 and so the # |
|||
# maximum number to test would be 45 x 9 999 # |
|||
# i.e.: 449 955 # |
|||
# construct the digit sums of the numbers up to max number # |
|||
[ 0 : max number ]INT dsum; |
|||
INT tn := 0, hn := 0, th := 0, tt := 0, ht := 0, dpos := -1; |
|||
WHILE ht /= 5 DO |
|||
INT sumd = ht + tt + th + hn + tn; |
|||
dsum[ dpos +:= 1 ] := sumd; |
|||
dsum[ dpos +:= 1 ] := sumd + 1; |
|||
dsum[ dpos +:= 1 ] := sumd + 2; |
|||
dsum[ dpos +:= 1 ] := sumd + 3; |
|||
dsum[ dpos +:= 1 ] := sumd + 4; |
|||
dsum[ dpos +:= 1 ] := sumd + 5; |
|||
dsum[ dpos +:= 1 ] := sumd + 6; |
|||
dsum[ dpos +:= 1 ] := sumd + 7; |
|||
dsum[ dpos +:= 1 ] := sumd + 8; |
|||
dsum[ dpos +:= 1 ] := sumd + 9; |
|||
IF ( tn +:= 1 ) > 9 THEN |
|||
tn := 0; |
|||
IF ( hn +:= 1 ) > 9 THEN |
|||
hn := 0; |
|||
IF ( th +:= 1 ) > 9 THEN |
|||
th := 0; |
|||
IF ( tt +:= 1 ) > 9 THEN |
|||
tt := 0; |
|||
ht +:= 1 |
|||
FI |
|||
FI |
|||
FI |
|||
FI |
|||
OD; |
|||
# table of numbers that can be formed by n / dsum[ n ] # |
|||
[ 0 : max number ]BOOL consummate; |
|||
FOR i FROM LWB consummate TO UPB consummate DO |
|||
consummate[ i ] := FALSE |
|||
OD; |
|||
FOR i TO UPB d sum DO |
|||
IF i MOD dsum[ i ] = 0 THEN |
|||
consummate[ i OVER dsum[ i ] ] := TRUE |
|||
FI |
|||
OD; |
|||
INT count := 0; |
|||
print( ( "The first 50 inconsummate numbers:", newline ) ); |
|||
FOR i TO UPB consummate WHILE count < 1000 DO |
|||
IF NOT consummate[ i ] THEN |
|||
IF ( count +:= 1 ) < 51 THEN |
|||
print( ( whole( i, -6 ) ) ); |
|||
IF count MOD 10 = 0 THEN print( ( newline ) ) FI |
|||
ELIF count = 1 000 THEN |
|||
print( ( "Inconsummate number ", whole( count, 0 ), ": ", whole( i, 0 ), newline ) ) |
|||
FI |
|||
FI |
|||
OD |
|||
END |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
The first 50 inconsummate numbers: |
|||
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 |
|||
Inconsummate number 1000: 6996 |
|||
</pre> |
|||
=={{header|Python}}== |
=={{header|Python}}== |
||
Line 79: | Line 154: | ||
Hundred-thousanth inconsummate number: 375410 |
Hundred-thousanth inconsummate number: 375410 |
||
</pre> |
</pre> |
||
=={{header|Raku}}== |
=={{header|Raku}}== |