aboutsummaryrefslogtreecommitdiff
path: root/0012
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-04-13 02:11:32 +0800
committerMistivia <i@mistivia.com>2025-04-13 02:11:32 +0800
commit345f3268bdfb191282bf44cdd2c8121c33d2560a (patch)
tree452a8b7b7af0c425e535488e8240da5a7ccf34c8 /0012
parent609a4795fa59775f51127400d626d625de828c76 (diff)
Highly Divisible Triangular Number
Diffstat (limited to '0012')
-rw-r--r--0012/main.hs18
1 files changed, 18 insertions, 0 deletions
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