Advertisement
danchaofan

Euler #91

Dec 10th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. rightTriangles = []
  2.  
  3.  
  4. def angleCheck(x1, x2, y1, y2):
  5.     zeroCount, undefCount = 0, 0
  6.     try:
  7.         slope1 = y1/x1
  8.         if slope1 == 0:
  9.             zeroCount += 1
  10.     except ZeroDivisionError:
  11.         undefCount += 1
  12.     try:
  13.         slope2 = y2/x2
  14.         if slope2 == 0:
  15.             zeroCount += 1
  16.     except ZeroDivisionError:
  17.         undefCount += 1
  18.     try:
  19.         slope3 = (y2-y1)/(x2-x1)
  20.         if slope3 == 0:
  21.             zeroCount += 1
  22.     except ZeroDivisionError:
  23.         undefCount += 1
  24.     if zeroCount == 1 and undefCount == 1:
  25.         return True
  26.     if zeroCount > 1 or undefCount > 1:
  27.         return False
  28.     if -y1*y2 == x1*x2:
  29.         return True
  30.     if -(y2-y1)*y1 == (x2-x1)*x1:
  31.         return True
  32.     if -(y2-y1)*y2 == (x2-x1)*x2:
  33.         return True
  34.     return False
  35.  
  36. for a in range(51):
  37.     for b in range(51):
  38.         for c in range(51):
  39.             for d in range(51):
  40.                 if a == c == 0:
  41.                     continue
  42.                 if b == d == 0:
  43.                     continue
  44.                 if a == b and c == d:
  45.                     continue
  46.                 if angleCheck(a, b, c, d):
  47.                     if sorted([(a, c), (b, d)]) in rightTriangles:
  48.                         continue
  49.                     rightTriangles.append(sorted([(a, c), (b, d)]))
  50. print(len(rightTriangles))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement