Last active
August 29, 2015 14:04
-
-
Save hollingberry/728f9624750f10f56ebb to your computer and use it in GitHub Desktop.
How many integers from 1 to 10000 can be written as the product of two (not necessarily distinct) primes?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List | |
import Data.Numbers.Primes | |
maxValue :: Int | |
maxValue = 10^5 | |
uniqOrdered :: [Int] -> [Int] | |
uniqOrdered = map head . group . sort | |
possiblePrimes :: [Int] | |
possiblePrimes = takeWhile (< div maxValue 2) primes | |
primeProducts :: [Int] | |
primeProducts = uniqOrdered [p1 * p2 | p1 <- possiblePrimes, p2 <- possiblePrimes, p1 * p2 < maxValue] | |
main :: IO () | |
main = print . length $ primeProducts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment