blob: 05a0dd418cf2ced82fefed6c1d8190a5fa320791 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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]
|