[challenge] Hamming numbers

Philippe Sigaud philippe.sigaud at gmail.com
Sun Sep 5 05:34:46 PDT 2010


On Sat, Sep 4, 2010 at 23:55, bearophile <bearophileHUGS at lycos.com> wrote:

>
> It computes the result (ghc-6.8.2) in 0.93s using only 8.7 MB of memory.
>

OK, so that may the difference between GHCi and GHC proper. Less than 1s is
impressive.
I see I have GHC 6.12.3 on my system. I may give this code a try one day. I
tend to do most (if not all) of my Haskell 'dips' with GHCi.



>
> > For my own D version, that is quite near the Rosetta Code version, I get
> > 3.7s, 100 Mo of RAM. (-O -release -inline)
> > Using the RC code (your own, translated from Java, right?), I get the
> same.
> > Same result, same time, same memory consumption. Yeah, my code is not
> wrong :-)
>
> On my very slow PC using DMD the D version requires about 2.7s and about
> max 92 MB of memory.
>

Maybe my PC is even slower :-)


>
> The second Python version (the one by Hettinger) takes about 4.95s and less
> than 4.5 MB of memory.
> (The third Python version, that uses the eager array and Psyco is faster.)
>
> Are you able to write a short D version similar to the second Python
> version? (I have created one, but it's not as short as the second Python
> version, and it takes something like 4 seconds or more).
>

Funnily, this second Python version was the only one I knew. So no, I'm not
able to do the deferred output in D. That's were the trick is anyway, to
have the solution recurse on a 'younger' version of itself. Maybe with lazy
int delegates ?


Philippe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100905/18596b39/attachment-0001.html>


More information about the Digitalmars-d mailing list