QSort in D: is this best?
bearophile
bearophileHUGS at lycos.com
Sun Dec 20 08:02:46 PST 2009
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
More information about the Digitalmars-d
mailing list