Created
March 25, 2018 16:32
-
-
Save cpfiffer/a9aa9de34ab1e9d05dfcf172c4d9d6b9 to your computer and use it in GitHub Desktop.
Solves problem 21 of Project Euler with list comprehensions.
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
module P21 (properDivisors, sumDivisors, sumAmicable, isAmicable, amicableList) where | |
properDivisors :: Int -> [Int] | |
properDivisors x = [xs | xs <- [1..x-1], x `mod` xs == 0] | |
sumDivisors :: Int -> Int | |
sumDivisors x = sum $ properDivisors x | |
sumAmicable = sum [x | x <- [1..10000], isAmicable x] | |
amicableList = [x | x <- [1..10000], isAmicable x] | |
isAmicable x = if sumDivisors otherNumber == x && not (x == otherNumber) then True else False | |
where otherNumber = sumDivisors x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment