Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  list doesn't end (Francesco Ariis)


----------------------------------------------------------------------

Message: 1
Date: Mon, 25 Nov 2019 14:20:24 +0100
From: Francesco Ariis <fa...@ariis.it>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] list doesn't end
Message-ID: <20191125132024.ga16...@x60s.casa>
Content-Type: text/plain; charset=utf-8

On Mon, Nov 25, 2019 at 08:55:17AM +0100, Alexander Chen wrote:
> Hi Francesco,
> 
> Their is a ^2, ^3, ^4 in the lists, respectively.
> 
> see https://projecteuler.net/problem=87

This runs reasonably fast even on my old 32bit machine:

    import qualified Data.Set as S
    import Data.Numbers.Primes

    sol72 :: Integer -> Int
    sol72 l = S.size . S.fromList $
                [(x+y+z) | x <- p2, y <- p3, z <- p4, x+y+z < l]
        where
              f :: Integer -> [Integer]
              f n = takeWhile (< l) $ map (^n) primes

              p2, p3, p4 :: [Integer]
              p2 = f 2
              p3 = f 3
              p4 = f 4

    λ> sol72 (50 * 10^6)
    1097343

Notice how the lengths for lists p2, p3 and p4 are actually 908, 73
and 23!
-F



------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 137, Issue 12
******************************************

Reply via email to