This is a great example that I don't have the time to look into now. In
essence the task is to generate all numbers of the form 2^^a*3^^b*5^^c
where a, b, and c are natural numbers.
Currently Phobos doesn't have the means to compute the cross-product of
ranges. I encourage people to think about implementing that.
Andrei
bearophile wrote:
You can try translating this in efficient, readable and short D2 code using
Phobos2 (the purpose is to find spots where Phobos2 may need improvements):
http://rosettacode.org/wiki/Hamming_numbers#Haskell
Haskell version:
hamming = 1 : map (2*) hamming `merge` map (3*) hamming `merge` map (5*) hamming
where merge (x:xs) (y:ys)
| x < y = x : xs `merge` (y:ys)
| x > y = y : (x:xs) `merge` ys
| otherwise = x : xs `merge` ys
main = do
print $ take 20 hamming
print $ hamming !! 1690
print $ hamming !! 1000000
(There's also a good enough Python version in that page).
Bye,
bearophile