Sha256: c2be447fe8ad31b4d65f5cd8743b0fcb6724a2ac13d9c1378b79c1e50cb97bb0
Contents?: true
Size: 501 Bytes
Versions: 396
Compression:
Stored size: 501 Bytes
Contents
module Prime (nth) where nth :: Int -> Maybe Integer nth x | x <= 0 = Nothing | otherwise = Just $ nth' x nth' :: Int -> Integer nth' = (primes !!) . pred -- all primes > 5 are in the form of 6n+1 or 6n+5 (for n >= 1) primes :: [Integer] primes = 2 : 3 : 5 : filter (go $ drop 2 primes) candidates where candidates = [x | n6 <- [6, 12 ..], x <- [n6 + 1, n6 + 5]] go (p:ps) n = case n `quotRem` p of (_, 0) -> False (q, _) -> q < p || go ps n go _ _ = undefined
Version data entries
396 entries across 396 versions & 1 rubygems