Last active
December 11, 2015 06:39
-
-
Save mattneary/4561089 to your computer and use it in GitHub Desktop.
Haskell Array-based isPrime
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
module Main where | |
grid range = [[i,j] | i <- range, j <- range] -- construct grid of number pairs | |
multiplicationTable grid = map (\l -> foldl (*) 1 l) grid -- multiply said pairs | |
isPrime number = not $ any (==number) $ (multiplicationTable . grid) [2 .. number] -- check for presence in table | |
main = print $ map (\p -> (fst p, (isPrime . fst) p)) [(i, b) | i <- [1 .. 100], b <- [True]] -- map all numbers to primeness |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment