How to resolve the algorithm Hamming numbers step by step in the ERRE programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Hamming numbers step by step in the ERRE programming language

Table of Contents

Problem Statement

Hamming numbers are numbers of the form   Hamming numbers   are also known as   ugly numbers   and also   5-smooth numbers   (numbers whose prime divisors are less or equal to 5).

Generate the sequence of Hamming numbers, in increasing order.   In particular:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Hamming numbers step by step in the ERRE programming language

Source code in the erre programming language

PROGRAM HAMMING


!$DOUBLE

DIM H[2000]

PROCEDURE HAMMING(L%->RES)
      LOCAL I%,J%,K%,N%,M,X2,X3,X5
      H[0]=1
      X2=2  X3=3  X5=5
      FOR N%=1 TO L%-1 DO
        M=X2
        IF M>X3 THEN M=X3 END IF
        IF M>X5 THEN M=X5 END IF
        H[N%]=M
        IF M=X2 THEN I%+=1  X2=2*H[I%]  END IF
        IF M=X3 THEN J%+=1  X3=3*H[J%]  END IF
        IF M=X5 THEN K%+=1  X5=5*H[K%]  END IF
      END FOR
      RES=H[L%-1]
END PROCEDURE

BEGIN
      FOR H%=1 TO 20 DO
        HAMMING(H%->RES)
        PRINT("H(";H%;")=";RES)
      END FOR
      HAMMING(1691->RES)
      PRINT("H(1691)=";RES)
END PROGRAM

  

You may also check:How to resolve the algorithm Comments step by step in the Oz programming language
You may also check:How to resolve the algorithm Parsing/RPN calculator algorithm step by step in the Maxima programming language
You may also check:How to resolve the algorithm Special characters step by step in the Wren programming language
You may also check:How to resolve the algorithm Generator/Exponential step by step in the FunL programming language
You may also check:How to resolve the algorithm Constrained random points on a circle step by step in the COBOL programming language