How to resolve the algorithm Humble numbers step by step in the Action! programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Humble numbers step by step in the Action! programming language
Table of Contents
Problem Statement
Humble numbers are positive integers which have no prime factors > 7.
Humble numbers are also called 7-smooth numbers, and sometimes called highly composite, although this conflicts with another meaning of highly composite numbers.
Another way to express the above is:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Humble numbers step by step in the Action! programming language
Source code in the action! programming language
;;; 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
You may also check:How to resolve the algorithm Primality by trial division step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Day of the week step by step in the EasyLang programming language
You may also check:How to resolve the algorithm Musical scale step by step in the Nanoquery programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the SPARC Assembly programming language
You may also check:How to resolve the algorithm Verify distribution uniformity/Chi-squared test step by step in the Nim programming language