From 4a781087c9520ecb700f0f557960e0e0de461a4d Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Sat, 26 Jun 2021 14:37:28 +0100 Subject: (Code)+math module that holds all my mathematical functions --- Math.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Math.hs (limited to 'Math.hs') diff --git a/Math.hs b/Math.hs new file mode 100644 index 0000000..b1eac91 --- /dev/null +++ b/Math.hs @@ -0,0 +1,12 @@ +module Math where + isPrime :: Int -> Bool + + isPrime n = (length [ x | x <- [2..(ceiling $ sqrt $ fromIntegral 2)], + n `mod` x == 0]) == 0 + + factors :: Int -> [Int] + + factors n = [x | x <- [1..(n `div` 2)], n `mod` x == 0] ++ [n] + + intersect' :: [Int] -> [Int] -> [Int] + intersect' a b = [x | x <- a, x `elem` b] -- cgit v1.2.3-13-gbd6f