Created
May 20, 2013 02:38
-
-
Save maxwellE/5610142 to your computer and use it in GitHub Desktop.
Haskell List Monad Example
This file contains 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 Control.Monad | |
import Data.List | |
import Primes | |
primes4 = takeWhile (<10000) $ dropWhile (<1000) primes | |
result = do | |
a <- primes4 | |
b <- dropWhile (<= a) primes4 | |
guard ((sort $ show a) == (sort $ show b)) | |
let c = 2 * b - a | |
guard (c < 10000) | |
guard ((sort $ show a) == (sort $ show c)) | |
guard $ isPrime c primes | |
return (a, b, c) | |
isPrime n (x:xs) = (x*x > n) || (mod n x /= 0) && (isPrime n xs) | |
primes = 2 : filter (\x -> isPrime x primes) [3..] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not my code, just keeping for reference.