Last active
October 17, 2019 18:53
-
-
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
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
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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example:
Input
3 5 12 5 13
Output
True