Created
June 12, 2017 09:39
-
-
Save KatagiriSo/43f729dd4b87f211a13f6528a51b86e0 to your computer and use it in GitHub Desktop.
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
main = do | |
print $ factorize(1000) | |
prime :: Int -> Bool | |
prime n = length([x | x <- [1..n], n `mod` x == 0 ]) == 2 | |
primes :: Int -> [Int] | |
primes n = [x | x <- [1..n], prime x] | |
factor :: Int -> Int -> Bool | |
factor x y = x `mod` y == 0 | |
factorize :: Int -> [Int] | |
factorize 1 = [] | |
factorize n = | |
let | |
x = head [x | x <- primes n, factor n x] | |
in | |
x:(factorize (n `div` x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment