[Haskell-cafe] List of all powers
Henning Thielemann
lemming at henning-thielemann.de
Wed Nov 14 14:05:17 EST 2007
On Wed, 14 Nov 2007, Kurt Hutchinson wrote:
> As part of a solution I'm working on for Project Euler problem 119, I
> wanted to create an ordered list of all powers of all positive
> integers (starting with squares). This is what I came up with:
>
> powers = ( uniq . map fst . iterate next ) ( 1, ( 0, powertable ) )
>
> powertable = map (\ n -> map (\ p -> n ^ p ) [ 2 .. ] ) [ 2 .. ]
iterate (n*) (n^2)
should be much more efficient.
More information about the Haskell-Cafe
mailing list