aboutsummaryrefslogtreecommitdiff
path: root/haskell/039-interger_right_triangle.hs
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-08-17 20:39:03 +0200
committerCharles <sircharlesaze@gmail.com>2019-08-17 20:39:03 +0200
commit9a65938232d1fa9e1afe9a6eb2de48d25ff738a6 (patch)
tree6f5e9dbef23a884a74f9fa10643ff5c0bea3d751 /haskell/039-interger_right_triangle.hs
parent78fbf8dbcf39aa51cf682a8795d0d0c3be6034c6 (diff)
downloadproject_euler-9a65938232d1fa9e1afe9a6eb2de48d25ff738a6.tar.gz
project_euler-9a65938232d1fa9e1afe9a6eb2de48d25ff738a6.tar.bz2
project_euler-9a65938232d1fa9e1afe9a6eb2de48d25ff738a6.zip
haskell problem 22, 24, 25, 29, 39, 40, 45, 53, 59
Diffstat (limited to 'haskell/039-interger_right_triangle.hs')
-rw-r--r--haskell/039-interger_right_triangle.hs24
1 files changed, 24 insertions, 0 deletions
diff --git a/haskell/039-interger_right_triangle.hs b/haskell/039-interger_right_triangle.hs
new file mode 100644
index 0000000..fda5eb9
--- /dev/null
+++ b/haskell/039-interger_right_triangle.hs
@@ -0,0 +1,24 @@
+-- Integer right triangles
+--
+-- Problem 39
+-- If p is the perimeter of a right angle triangle with integral length sides,
+-- {a,b,c}, there are exactly three solutions for p = 120.
+--
+-- {20,48,52}, {24,45,51}, {30,40,50}
+--
+-- For which value of p ≤ 1000, is the number of solutions maximised?
+
+
+import Data.List(maximumBy)
+
+-- 4m20s stucks
+main = do
+ print (maximumBy (\(_, xs) (_, ys) -> compare (length xs) (length ys)) [
+ (p,
+ [(a, b, p - a - b) | a <- [1..p], b <- [1..(p-a)],
+ validRightTriangle a b (p - a - b)])
+ | p <- [1..1000]
+ ])
+
+validRightTriangle :: Int -> Int -> Int -> Bool
+validRightTriangle a b c = a ^ 2 + b ^ 2 == c ^ 2