Humble numbers: Difference between revisions

Added PL/M
m (Phix/mpfr)
(Added PL/M)
Line 2,385:
142,038 humble numbers have 41 digits (21.7s, total:1,551,120)
152,515 humble numbers have 42 digits (23.9s, total:1,703,635)
</pre>
 
=={{header|PL/M}}==
{{Trans|ALGOL W}}
Tested using a PLM286 to C converter and a suitable I/O library.
<lang plm>HUMBLE: DO;
/* find some Humble numbers - numbers with no prime factors above 7 */
/* External I/O procedures */
WRITE$STRING: PROCEDURE( S ) EXTERNAL; DECLARE S POINTER; END;
WRITE$WORD: PROCEDURE( W ) EXTERNAL; DECLARE W WORD; END;
WRITE$NL: PROCEDURE EXTERNAL; END;
/* End external I/O procedures */
DECLARE MAX$HUMBLE LITERALLY '400';
/* returns the minimum of a and b */
MIN: PROCEDURE( A, B ) WORD;
DECLARE ( A, B ) WORD;
IF A < B THEN RETURN( A ); ELSE RETURN( B );
END MIN;
/* display a statistic about Humble numbers */
WRITEHSTAT: PROCEDURE( S, D );
DECLARE ( S, D ) WORD;
CALL WRITE$STRING( @( 'there are', 0 ) );
CALL WRITE$WORD( S );
CALL WRITE$STRING( @( ' Humble numbers with ', 0 ) );
CALL WRITE$WORD( D );
CALL WRITE$STRING( @( ' digit', 0 ) );
IF D > 1 THEN CALL WRITE$STRING( @( 's', 0 ) );
CALL WRITE$NL();
END WRITEHSTAT;
/* find and print Humble Numbers */
MAIN: PROCEDURE;
DECLARE H( MAX$HUMBLE ) WORD;
DECLARE ( P2, P3, P5, P7, M
, LAST2, LAST3, LAST5, LAST7
, H1, H2, H3, H4, H5, H6, HPOS
) WORD;
/* 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;
DO HPOS = 1 TO MAX$HUMBLE - 1;
/* the next Humble number is the lowest of the next multiple */
/* of 2, 3, 5, 7 */
M = MIN( MIN( MIN( P2, P3 ), P5 ), P7 );
H( HPOS ) = M;
IF M = P2 THEN DO;
/* the Humble number was the next multiple of 2 */
/* the next multiple of 2 will now be twice the Humble */
/* number following the previous multple of 2 */
LAST2 = LAST2 + 1;
P2 = 2 * H( LAST2 );
END;
IF M = P3 THEN DO;
LAST3 = LAST3 + 1;
P3 = 3 * H( LAST3 );
END;
IF M = P5 THEN DO;
LAST5 = LAST5 + 1;
P5 = 5 * H( LAST5 );
END;
IF M = P7 THEN DO;
LAST7 = LAST7 + 1;
P7 = 7 * H( LAST7 );
END;
END;
DO HPOS = 0 TO 49; CALL WRITE$WORD( H( HPOS ) ); END;
CALL WRITE$NL();
DO HPOS = 0 TO MAX$HUMBLE - 1;
M = H( HPOS );
IF M < 10 THEN H1 = H1 + 1;
ELSE IF M < 100 THEN H2 = H2 + 1;
ELSE IF M < 1000 THEN H3 = H3 + 1;
ELSE IF M < 10000 THEN H4 = H4 + 1;
END;
CALL WRITEHSTAT( H1, 1 );
CALL WRITEHSTAT( H2, 2 );
CALL WRITEHSTAT( H3, 3 );
CALL WRITEHSTAT( H4, 4 );
END MAIN;
END HUMBLE;</lang>
{{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>
 
3,048

edits