diff options
| author | Mistivia <i@mistivia.com> | 2025-04-24 15:31:47 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-04-24 15:31:47 +0800 |
| commit | 3b2a2c6f8ff46123a154c32dcfd35d8fdec8f439 (patch) | |
| tree | 1f06b1463f334b0a3ebddc65d67d09c49baa1b5a /5-kyu/recreation-one.hs | |
| parent | 2a9e59907868d12a2a3ea387ec90074e26cc90c3 (diff) | |
update
Diffstat (limited to '5-kyu/recreation-one.hs')
| -rw-r--r-- | 5-kyu/recreation-one.hs | 24 |
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] |
