Created
April 5, 2019 14:06
-
-
Save abresas/71ad02a1b5a81b69913cd53903a58aab to your computer and use it in GitHub Desktop.
Project euler problem 21 solution in haskell with point-free amicable definition
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 Amicable2 where | |
d :: Int -> Int | |
d x = sum [n | n <- [1 .. (x `div` 2)], x `mod` n == 0] | |
(===) :: (Eq b) => (a -> b) -> (a -> b) -> a -> Bool | |
(f === g) x = f x == g x | |
(/==) :: (Eq b) => (a -> b) -> (a -> b) -> a -> Bool | |
(f /== g) x = f x /= g x | |
(&&&) :: (a -> Bool) -> (a -> Bool) -> a -> Bool | |
(f &&& g) x = f x && g x | |
amicable :: Int -> Bool | |
amicable = d /== id &&& ((d . d) === id) | |
main = print $ sum $ filter amicable [1 .. 9999] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment