Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from itertools import combinations
- # Given an array of integers, write a function that returns true if there is a triplet (a, b, c) that satisfies a2 + b2 = c2.
- """
- Input: arr[] = {3, 1, 4, 6, 5}
- Output: True
- There is a Pythagorean triplet (3, 4, 5).
- """
- def sets_of_three(arr):
- return list(combinations(arr, 3))
- def pythag(tup):
- if (tup[0]**2) + (tup[1]**2) == tup[2]**2:
- print(tup)
- def pyTrip(arr):
- allTriplets = sets_of_three(arr)
- print(allTriplets)
- for trip in allTriplets:
- pythag(trip)
- pyTrip([3, 1, 4, 6, 5])
Add Comment
Please, Sign In to add comment