59 lines
1.6 KiB
Text
59 lines
1.6 KiB
Text
;;; 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
|