Inconsummate numbers in base 10: Difference between revisions

→‎{{header|ALGOL 68}}: Simplify - no need for the divisor sum table, find the consummate numbers while finding the sums, handle the stretch goal
(→‎{{header|Python}}: prepend Pascal. no divisor of a niven number)
(→‎{{header|ALGOL 68}}: Simplify - no need for the divisor sum table, find the consummate numbers while finding the sums, handle the stretch goal)
Line 31:
 
=={{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# maxtable numberof =numbers 499that 999;can #be formed by n / digit maximumsum numbern we will consider #
[ 0 : max999 999 number ]BOOL consummate;
# chosen because if we assume the 1000th #
FOR i FROM LWB consummate TO UPB consummate DO
# inconsummate number is <= 9 999, then the #
consummate[ i ] := FALSE
# maximum possible digit sum is 45 and so the #
OD;
# maximum number to test would be 45 x 9 999 #
# calculate the maximum number we must consider to find consummate #
# i.e.: 449 955 #
# numbers up to UPB consummate - which is 9 * the number of digits in #
# UPB consummate # i.e.: 449 955 #
INT max sum := 9;
INT v := UPB consummate;
WHILE ( v OVERAB 10 ) > 0 DO max sum +:= 9 OD;
INT max number = UPB consummate * max sum;
# construct the digit sums of the numbers up to max number #
# and find the consumate numbers, we start the loop from 10 to avoid #
[ 0 : max number ]INT dsum;
INT# tnhaving :=to deal with 0,-9 hn := 0, th := 0, tt := 0, ht := 0, dpos := -1; #
WHILEconsummate[ ht1 /=] 5:= DOTRUE;
INT tn := 1, INThn sumd:= 0, th := 0, tt := 0, ht +:= tt0, +mi th:= +0, hntm +:= tn0;
FOR n FROM 10 dsum[BY dpos10 +:=TO 1max ]number := sumd;DO
dsum[INT dpossumd +:= 1tm ]+ :=mi sumd+ ht + tt + th + hn + 1tn;
dsum[FOR dposd +:=FROM 1n ]TO :=n sumd+ +9 2;DO
dsum[ dpos +:= 1IF ]d :=MOD sumd += 0 3;THEN
# d is comsummate #
dsum[ dpos +:= 1 ] := sumd + 4;
dsum[ dpos +:= 1 ] : IF INT d ratio = sumdd +OVER 5sumd;
dsum[ dpos +:= 1 ] := sumd + 6; d ratio <= UPB consummate
dsum[ dpos +:= 1 ] := sumd + 7;THEN
dsum[ dpos +:= 1 consummate[ d ratio ] := sumd + 8;TRUE
dsum[ dpos +:= 1 ] := sumd + 9;FI
FI;
sumd +:= 1
OD;
IF ( tn +:= 1 ) > 9 THEN
tn := 0;
IF ( hn +:= 1 ) > 9 THEN
hn := 0;
Line 64 ⟶ 72:
IF ( tt +:= 1 ) > 9 THEN
tt := 0;
IF ( ht +:= 1 ) > 9 THEN
ht := 0;
IF ( #mi inconsummate+:= number1 is) <=> 9 999, then the #THEN
# chosen becausemi if we:= assume the 1000th #0;
# maximum possibletm digit+:= sum is 45 and so the #1
FI
FI
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 < 1000100 000 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 OR count = 10 000 OR count = 100 000 THEN
print( ( "Inconsummate number ", whole( count, 0 ), ": ", whole( i, 0 ), newline )-6 )
, ": ", whole( i, -8 ), newline
)
IF i MOD dsum[ i ] = 0 THEN )
FI
FI
Line 102 ⟶ 109:
441 443 461 466 471 476 482 483 486 488
491 492 493 494 497 498 516 521 522 527
Inconsummate number 1000: 6996
Inconsummate number 10000: 59853
Inconsummate number 100000: 536081
</pre>
 
3,021

edits