0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Project Euler No. 9

Last updated at Posted at 2013-12-05

Problem

A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, $a^2 + b^2 = c^2$. For example, $3^2 + 4^2 = 9 + 16 = 25 = 5^2$. There exists exactly one Pythagorean triplet for which $a + b + c = 1000$.

Find the product $abc$.

Code in Haskell

Euler_009.hs
module Main where

stream = [ (a,b,1000-(a+b),a*b,a*b*(1000-a-b))
           | a<-[1..500], b<-[1..500], a<b, b<(1000-a-b) ]
isPythTriple (a,b,c,d,e) = d == 1000*(500-c)


main = print answer
  where answer = head $ filter isPythTriple stream

Answer

3******0

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?