Humble numbers: Difference between revisions
Content added Content deleted
m (→{{header|ALGOL 68}}: Show the first 50 numbers, not 49) |
(Added Action!) |
||
Line 81: | Line 81: | ||
1272 have 8 digits |
1272 have 8 digits |
||
1767 have 9 digits |
1767 have 9 digits |
||
</pre> |
|||
=={{header|Action!}}== |
|||
{{Trans|PLM}}...which is based on the Algol 68 sample. |
|||
<br>As with the PL/M sample, we only consider up to 4 digit Humble Numbers, as Action! integers are limited to 16 bit signed or unsiged. |
|||
<syntaxhighlight lang="action!"> |
|||
;;; Find some humble numbers - numbers with no prime factors above 7 |
|||
PROC humbleStat( CARD s, d ) ;;; displays a statistic about humble numbers |
|||
Print( "There are " ) |
|||
IF s < 10 THEN Put(' ) FI |
|||
IF s < 100 THEN Put(' ) FI |
|||
PrintC( s )Print( " humble numbers with " )PrintC( d )Print( " digit" ) |
|||
IF d > 1 THEN Put('s) FI |
|||
PutE() |
|||
RETURN |
|||
PROC Main() ;;; find and print humble numbers |
|||
DEFINE MAX_HUMBLE = "400" |
|||
CARD ARRAY H( MAX_HUMBLE ) |
|||
CARD h1, h2, h3, h4, h5, h6, hPos, m |
|||
CARD p2, p3, p5, p7 |
|||
CARD last2, last3, last5, last7 |
|||
; 1 is the first humble number |
|||
H( 0 ) = 1 |
|||
h1 = 0 h2 = 0 h3 = 0 h4 = 0 h5 = 0 h6 = 0 |
|||
last2 = 0 last3 = 0 last5 = 0 last7 = 0 |
|||
p2 = 2 p3 = 3 p5 = 5 p7 = 7 |
|||
FOR hPos = 1 TO MAX_HUMBLE - 1 DO |
|||
; the next humble number is the lowest of the |
|||
; next multiples of 2, 3, 5, 7 |
|||
IF p2 < p3 THEN m = p2 ELSE m = p3 FI |
|||
IF p5 < m THEN m = p5 FI |
|||
IF p7 < m THEN m = p7 FI |
|||
H( hPos ) = m |
|||
IF m = p2 THEN last2 = last2 + 1 p2 = 2 * H( last2 ) FI |
|||
IF m = p3 THEN last3 = last3 + 1 p3 = 3 * H( last3 ) FI |
|||
IF m = p5 THEN last5 = last5 + 1 p5 = 5 * H( last5 ) FI |
|||
IF m = p7 THEN last7 = last7 + 1 p7 = 7 * H( last7 ) FI |
|||
OD |
|||
FOR hPos = 0 TO 49 DO |
|||
Put(' )PrintC( H( hPos ) ) |
|||
OD |
|||
PutE() |
|||
FOR hPos = 0 TO MAX_HUMBLE - 1 DO |
|||
m = H( hPos ) |
|||
IF m < 10 THEN h1 = h1 + 1 |
|||
ELSEIF m < 100 THEN h2 = h2 + 1 |
|||
ELSEIF m < 1000 THEN h3 = h3 + 1 |
|||
ELSEIF m < 10000 THEN h4 = h4 + 1 |
|||
FI |
|||
OD |
|||
humbleStat( h1, 1 ) |
|||
humbleStat( h2, 2 ) |
|||
humbleStat( h3, 3 ) |
|||
humbleStat( h4, 4 ) |
|||
RETURN |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
1 2 3 4 5 6 7 8 9 10 12 14 15 16 18 20 21 24 25 27 28 30 32 35 36 40 42 45 48 49 50 54 56 60 63 64 70 72 75 80 81 84 90 96 98 100 105 108 112 120 |
|||
There are 9 humble numbers with 1 digit |
|||
There are 36 humble numbers with 2 digits |
|||
There are 95 humble numbers with 3 digits |
|||
There are 197 humble numbers with 4 digits |
|||
</pre> |
</pre> |
||