28 lines
576 B
Plaintext
28 lines
576 B
Plaintext
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
|