Skip to content

Instantly share code, notes, and snippets.

@IrakliJani
Created January 17, 2015 18:46
Show Gist options
  • Save IrakliJani/6ab161372414b8c11b29 to your computer and use it in GitHub Desktop.
Save IrakliJani/6ab161372414b8c11b29 to your computer and use it in GitHub Desktop.
Haskell Code
factors :: Int -> [Int]
factors n =
[x | x <- [1..n], n `mod` x == 0]
factors 72
out> [1,2,3,4,6,8,9,12,18,24,36,72]
prime :: Int -> Bool
prime n = factors n == [1, n]
prime 71
out> True
primes :: Int -> [Int]
primes n = [x | x <- [2..n], prime x]
primes 71
out> [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment