Skip to content

Instantly share code, notes, and snippets.

@abresas
Created April 5, 2019 14:06
Show Gist options
  • Save abresas/71ad02a1b5a81b69913cd53903a58aab to your computer and use it in GitHub Desktop.
Save abresas/71ad02a1b5a81b69913cd53903a58aab to your computer and use it in GitHub Desktop.
Project euler problem 21 solution in haskell with point-free amicable definition
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