Skip to content

Instantly share code, notes, and snippets.

@weskerfoot
Created January 30, 2013 22:45
Show Gist options
  • Save weskerfoot/4678017 to your computer and use it in GitHub Desktop.
Save weskerfoot/4678017 to your computer and use it in GitHub Desktop.
pe9
import Control.Monad
coprime a b = gcd a b == 1
istriple m n = coprime m n && odd (m - n) && (m > n) && m > 0 && n > 0
triple m n k =
let a = k * (m^2 - n^2)
b = k * (2*m*n)
c = k * (m^2 + n^2)
in [a,b,c]
main = do
let candidates = filter (uncurry istriple) $ join [[(m,n) | n <- [1..500]] | m <- [1..500]]
print $ head $ dropWhile ((/=1000) . sum) $ join [[triple m n k | k <- [1..(1000-(m+n))]] | (m,n) <- candidates, (m+n) < 1000]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment