[challenge] Hamming numbers

Peter Alexander peter.alexander.au at gmail.com
Fri Sep 3 12:36:26 PDT 2010


== Quote from Don (nospam at nospam.com)'s article
> That's not a very useful problem, because the timing depends entirely on
> BigInt, which is completely unoptimised for small values.

True, but it would be nice to get it as concise as Haskell's.

In an ideal world, we'd simply write it as:

auto H()
{
	return chain([BigInt(1)], setIntersection(map!"2*a"(H()), map!"3*a"(H()), map!"5*a"(H())));
}

BigInt hamming(int limit)
{
	return H().at(limit);
}

But the unfortunately, due to D's type system, you cannot have recursive types (H's type depends on
its own type).

You should be able to get around this by introducing a "abstract range wrapper". I'll see what I can
come up with.


More information about the Digitalmars-d mailing list