瀏覽代碼

Special Pythagorean Triplet

Mistivia 6 天之前
父節點
當前提交
a35ca0e5ac
共有 1 個文件被更改,包括 11 次插入0 次删除
  1. 11 0
      0009/main.hs

+ 11 - 0
0009/main.hs

@@ -0,0 +1,11 @@
+triplets = foldl1 (++) $ map triplets1 [1..499]
+    where triplets1 x = foldl1 (++) $ map triplets2 [x+1..999-x]
+            where triplets2 y = [(x,y,1000-x-y)]
+
+theTripet = filter (\(a,b,c) -> a^2 + b^2 == c^2) triplets
+
+tripletProduct (a,b,c) = a * b * c
+
+main = do
+    putStrLn $ show $ tripletProduct $ head theTripet
+