From 345f3268bdfb191282bf44cdd2c8121c33d2560a Mon Sep 17 00:00:00 2001 From: Mistivia Date: Sun, 13 Apr 2025 02:11:32 +0800 Subject: Highly Divisible Triangular Number --- 0012/main.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 0012/main.hs diff --git a/0012/main.hs b/0012/main.hs new file mode 100644 index 0000000..d40b1a5 --- /dev/null +++ b/0012/main.hs @@ -0,0 +1,18 @@ +divisors num = length $ filter divisable [1..num] + where divisable x = num `mod` x == 0 + +pairDivisors (x,y) = (divisors x) * (divisors y) + +triangleNums :: [(Integer,Integer)] +triangleNums = map toPair [1..] + where + toPair n = if n `mod` 2 == 0 then + (n `div` 2,n+1) + else + ((n+1) `div` 2, n) + +firstWithDivisorNum n = impl triangleNums + where impl ((a,b):xs) = if pairDivisors (a,b) >= n then (a * b) else impl xs + +main = do + putStrLn $ show $ firstWithDivisorNum 500 -- cgit v1.0