Created
February 6, 2013 23:20
-
-
Save sgerrand/4726803 to your computer and use it in GitHub Desktop.
Haskell based solution to problem #91 ("Right triangles with integer coordinates") in Project Euler: http://projecteuler.net/problem=91
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reduce x y = (quot x d, quot y d) | |
where d = gcd x y | |
right_angle_triangles_in_quadrant n = | |
3 *n * n + 2 * sum others | |
where | |
others =[min xc yc| | |
x1 <- [1..n], | |
y1 <- [1..n], | |
let (yi,xi) = reduce x1 y1, | |
let yc = quot (n-y1) yi, | |
let xc = quot x1 xi | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment