Skip to content

Instantly share code, notes, and snippets.

@dmalikov
Created December 1, 2011 20:47
Show Gist options
  • Save dmalikov/1419737 to your computer and use it in GitHub Desktop.
Save dmalikov/1419737 to your computer and use it in GitHub Desktop.
Project Euler 75 (3 s)
import Data.List
possibleTriangles :: Integer -> Int
possibleTriangles n = length . filter (\x -> length x == 1) . group . sort . concat $ [ [s,2*s..n] | i <- [1,3..(upperBound n)]
, j <- [2,4..(upperBound n)-i]
, gcd i j == 1
, let s = abs (j*j - i*i) + 2*i*j + i*i + j*j ]
upperBound :: Integer -> Integer
upperBound = truncate . sqrt . fromIntegral
main = print . possibleTriangles $ 1500000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment