summaryrefslogtreecommitdiff
path: root/5-kyu/recreation-one.hs
diff options
context:
space:
mode:
Diffstat (limited to '5-kyu/recreation-one.hs')
-rw-r--r--5-kyu/recreation-one.hs24
1 files changed, 24 insertions, 0 deletions
diff --git a/5-kyu/recreation-one.hs b/5-kyu/recreation-one.hs
new file mode 100644
index 0000000..05a0dd4
--- /dev/null
+++ b/5-kyu/recreation-one.hs
@@ -0,0 +1,24 @@
+-- https://www.codewars.com/kata/55aa075506463dac6600010d
+module Codewars.G964.Sumdivsq where
+
+divisors x = impl 1 []
+ where
+ impl cur result =
+ if cur > x then
+ result
+ else
+ if x `mod` cur == 0 then
+ impl (cur+1) (cur:result)
+ else
+ impl (cur+1) result
+
+isSquare :: Int -> Bool
+isSquare n = root * root == n
+ where root = round (sqrt $ fromIntegral n)
+
+listSquared :: Int -> Int -> [(Int, Int)]
+listSquared m n = filter (\(n, s) -> isSquare s) pairs
+ where
+ pairs = map
+ (\x -> (x, sum $ map (^2) $ divisors x))
+ [m..n]