Last active
April 2, 2018 05:58
-
-
Save samidarko/de61edebd97bc28a8285ec2860fc56e0 to your computer and use it in GitHub Desktop.
find divisors of n
This file contains hidden or 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
findDivisors :: (RealFrac a, Integral b, Floating a) => a -> [b] | |
findDivisors n = fn (truncate . sqrt $ n) | |
where | |
n' = truncate n | |
fn i | |
| i == 1 = 1:n':[] | |
| n' `mod` i == 0 = let n_by_i = (n' `div` i) | |
in if n_by_i == i then i : fn next | |
else i : n_by_i : fn next | |
| otherwise = fn next | |
where next = i-1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment