I need to define the list of the numbers whose only prime factors are 2, 3 and 5, the Hamming numbers. (I.e. numbers in the form of 2^i * 3^j * 5^k. The sequence starts with 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, …)
I may do it using the factors
function, or otherwise. The factors
below should return factors of its argument. I believe I’ve implemented it correctly.
factors :: Int -> [Int]
factors n = [x | x <- [1..(div n 2) ++ n], mod n x == 0]
I tried to make the list of 2^i * 3^j * 5^k using list comprehensions but got stuck on writing the guard:
hamming :: [Int]
hamming = [n | n <- [1..], „where n is a member of helper“]
helper :: [Int]
helper = [2^i * 3^j * 5^k | i <- [0..], j <- [0..], k <- [0..]]