Dijkstra attributes to Hamming the problem of building the infinite ascending sequence of all positive numbers greater than 1 containing no prime factors other than 2, 3 and 5, i.e. numbers of the form 2^i x 3^j x 5^k (i,j,k >= 0). The ideas to compute them are the following:Try yourself before you check the Functional solution and the Prolog solution.
- Given a hamming number h, then 2h, 3h, 5h are hamming numbers.
- 1 is a hamming number at it is used to start the computation.
- To maintain them sorted, it is only needed to compare the numbers coming from the multiplication for 2, 3, 5 not used yet. Other products will result greater than some of then, so they are not candidates to be the first in the sorted list.
But Logic Programming is more Expressive than Functional Programming
Go to index