From 3b2a2c6f8ff46123a154c32dcfd35d8fdec8f439 Mon Sep 17 00:00:00 2001 From: Mistivia Date: Thu, 24 Apr 2025 15:31:47 +0800 Subject: update --- 5-kyu/recreation-one.hs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 5-kyu/recreation-one.hs 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] -- cgit v1.0