Skip to content

Instantly share code, notes, and snippets.

@praveeng1618
Last active October 17, 2019 18:53
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 praveeng1618/85e02d6fd7925035b9b92cd86f8745f7 to your computer and use it in GitHub Desktop.
Save praveeng1618/85e02d6fd7925035b9b92cd86f8745f7 to your computer and use it in GitHub Desktop.
Given a list of numbers, find if there exists a pythagorean triplet in that list. A pythagorean triplet is 3 variables a, b, c where a^2 + b^2 = c^2
import sys
t = [int(x) for x in input().split()]
if len(t) < 3 :
print(False)
sys.exit()
for i in range(len(t)):
for j in range(i+1,len(t)):
for k in range(j+1,len(t)):
if ((t[i]**2)+(t[j]**2)) == (t[k]**2):
print("True")
sys.exit()
elif ((t[i]**2)+(t[k]**2)) == (t[j]**2):
print("True")
sys.exit()
elif ((t[k]**2)+(t[j]**2)) == (t[i]**2):
print("True")
sys.exit()
print("False")
@praveeng1618
Copy link
Author

Example:
Input
3 5 12 5 13
Output
True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment