Skip to content

Instantly share code, notes, and snippets.

@sgerrand
Created February 6, 2013 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgerrand/4726803 to your computer and use it in GitHub Desktop.
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
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