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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Hamming numbers step by step in the BASIC256 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 BASIC256 programming language

Source code in the basic256 programming language

print "The first 20 Hamming numbers are :"
for i = 1 to 20
    print Hamming(i);" ";
next i

print
print "H( 1691) = "; Hamming(1691)
end

function min(a, b)
    if a < b then return a else return b
end function

function Hamming(limit)
    dim h(1000000)

    h[0] = 1
    x2 = 2 : x3 = 3 : x5 = 5
    i  = 0 : j  = 0 : k  = 0
    for n = 1 to limit
        h[n]  = min(x2, min(x3, x5))
        if x2 = h[n] then i += 1: x2 = 2 *h[i]
        if x3 = h[n] then j += 1: x3 = 3 *h[j]
        if x5 = h[n] then k += 1: x5 = 5 *h[k]
    next n
    return h[limit -1]
end function

  

You may also check:How to resolve the algorithm Abundant odd numbers step by step in the Rust programming language
You may also check:How to resolve the algorithm Stair-climbing puzzle step by step in the ActionScript programming language
You may also check:How to resolve the algorithm Old lady swallowed a fly step by step in the Mercury programming language
You may also check:How to resolve the algorithm Quine step by step in the Dao programming language
You may also check:How to resolve the algorithm Miller–Rabin primality test step by step in the Phix programming language