Created
May 14, 2016 11:56
-
-
Save JadenGeller/bde391ba142c6a1d357aba2422b2340a to your computer and use it in GitHub Desktop.
Factorization in Haskell
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 Data.Numbers.Primes | |
import Data.List | |
factors :: Integral n => n -> [n] | |
factors n = case find (\p -> n `mod` p == 0) candidates of | |
Just p -> p : (factors $ n `div` p) | |
Nothing -> [n] | |
where candidates = takeWhile (<= ceiling (sqrt (fromIntegral n))) primes | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment