Skip to content

Instantly share code, notes, and snippets.

@public
Created July 12, 2013 10:30
Show Gist options
  • Save public/5983421 to your computer and use it in GitHub Desktop.
Save public/5983421 to your computer and use it in GitHub Desktop.
import Data.List
import Math.NumberTheory.Primes.Sieve
import Control.Monad
import Debug.Trace
numWays without p =
let (poor, rich) = splitAt p without
with = poor ++
zipWith (+) with rich
in with
counter = foldl numWays (1 : repeat 0)
main = do
let ways = counter $ takeWhile (<5000) [fromInteger p | p <- primes]
print $ ways !! 10
print $ ways !! 5000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment