www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: D.challenge

Justin Johansson:
 "challenging D to do this or that" in the
 context of, say, another programming language or some CS

In past months I have proposed two little challenges, the second of them was to implement this RosettaCode task in D, to produce a program that is faster, shorter and uses less memory than the current D version: http://rosettacode.org/wiki/Hamming_numbers#D If you take a look at the Haskell version (that is much faster and uses much less RAM and has a shorter source code) you see that there is lot of space for improvement: 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 !! 999999 (I don't remember yet the other older challenge.) Bye, bearophile
Aug 31 2010