Skip to content

Instantly share code, notes, and snippets.

@maxwellE
Created May 20, 2013 02:38
Show Gist options
  • Save maxwellE/5610142 to your computer and use it in GitHub Desktop.
Save maxwellE/5610142 to your computer and use it in GitHub Desktop.
Haskell List Monad Example
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..]
@maxwellE
Copy link
Author

Not my code, just keeping for reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment