Inconsummate numbers in base 10: Difference between revisions

Added Action!
(Added Action!)
Line 29:
;* [https://www.numbersaplenty.com/set/inconsummate_number/ Numbers Aplenty - Inconsummate numbers]
;* [[oeis:A003635|OEIS:A003635 - Inconsummate numbers in base 10]]
 
=={{header|Action!}}==
{{Trans|PL/M}}
and based on the Algol 68 sample. As with the PL/M sample, the limit of 16 bit arithmetic means only the basic task can be handled.
<syntaxhighlight lang="action!">
;;; find some incomsummate numbers: integers that cannot be expressed as
;;; an integer divided by the sum of its digits
 
PROC Main()
 
CARD i, tn, hn, th, tt, sumD, d, n, dRatio, count, maxSum, v, maxNumber
 
; table of numbers that can be formed by n / digit sum n
DEFINE MAX_C = "999"
BYTE ARRAY consummate(MAX_C+1)
FOR i = 0 TO MAX_C DO
consummate( i ) = 0
OD
 
; calculate the maximum number we must consider
v = MAX_C / 10;
maxSum = 9;
WHILE v > 0 DO
maxSum ==+ 9
v ==/ 10
OD
maxNumber = maxSum * MAX_C
 
; construct the digit sums of the numbers up to maxNumber
; and find the consumate numbers, we start the loop from 10 to avoid
; having to deal with 0-9
consummate( 1 ) = 1
tn = 1 hn = 0 th = 0 tt = 0
FOR n = 10 TO maxNumber STEP 10 DO
sumD = tt + th + hn + tn
FOR d = n TO n + 9 DO
IF d MOD sumD = 0 THEN
; d is comsummate
dRatio = d / sumD
IF dRatio <= MAX_C THEN
consummate( dRatio ) = 1
FI
FI
sumD ==+ 1
OD
tn ==+ 1
IF tn > 9 THEN
tn = 0
hn ==+ 1
IF hn > 9 THEN
hn = 0
th ==+ 1
IF th > 9 THEN
th = 0
tt ==+ 1
FI
FI
FI
OD
 
count = 0
PrintE( "The first 50 inconsummate numbers:" )
i = 0
WHILE i < MAX_C AND count < 50 DO
i ==+ 1
IF consummate( i ) = 0 THEN
count ==+ 1
Put(' )
IF i < 10 THEN Put(' ) FI
IF i < 100 THEN Put(' ) FI
IF i < 1000 THEN Put(' ) FI
PrintC( i )
IF count MOD 10 = 0 THEN PutE() FI
FI
OD
 
RETURN
</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
</pre>
 
=={{header|ALGOL 68}}==
3,026

edits