-
Notifications
You must be signed in to change notification settings - Fork 676
/
p091.py
31 lines (25 loc) · 793 Bytes
/
p091.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#
# Solution to Project Euler problem 91
# Copyright (c) Project Nayuki. All rights reserved.
#
# https://www.nayuki.io/page/project-euler-solutions
# https://github.com/nayuki/Project-Euler-solutions
#
def compute():
LIMIT = 51
ans = sum(1
for x1 in range(LIMIT)
for y1 in range(LIMIT)
for x2 in range(LIMIT)
for y2 in range(LIMIT)
# For uniqueness, ensure that (x1,y1) has a larger angle than (x2,y2)
if y2 * x1 < y1 * x2 and is_right_triangle(x1, y1, x2, y2))
return str(ans)
# Tests whether the three points {(0,0), (x1,y1), (x2,y2)} form a right triangle.
def is_right_triangle(x1, y1, x2, y2):
a = x1**2 + y1**2
b = x2**2 + y2**2
c = (x2 - x1)**2 + (y2 - y1)**2
return (a + b == c) or (b + c == a) or (c + a == b)
if __name__ == "__main__":
print(compute())