summaryrefslogtreecommitdiff
path: root/5-kyu/recreation-one.hs
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-04-24 15:31:47 +0800
committerMistivia <i@mistivia.com>2025-04-24 15:31:47 +0800
commit3b2a2c6f8ff46123a154c32dcfd35d8fdec8f439 (patch)
tree1f06b1463f334b0a3ebddc65d67d09c49baa1b5a /5-kyu/recreation-one.hs
parent2a9e59907868d12a2a3ea387ec90074e26cc90c3 (diff)
update
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]