Guest User

Untitled

a guest
May 24th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. from itertools import combinations
  2.  
  3. # Given an array of integers, write a function that returns true if there is a triplet (a, b, c) that satisfies a2 + b2 = c2.
  4.  
  5. """
  6. Input: arr[] = {3, 1, 4, 6, 5}
  7. Output: True
  8. There is a Pythagorean triplet (3, 4, 5).
  9. """
  10.  
  11. def sets_of_three(arr):
  12. return list(combinations(arr, 3))
  13.  
  14. def pythag(tup):
  15. if (tup[0]**2) + (tup[1]**2) == tup[2]**2:
  16. print(tup)
  17.  
  18.  
  19. def pyTrip(arr):
  20.  
  21. allTriplets = sets_of_three(arr)
  22. print(allTriplets)
  23.  
  24. for trip in allTriplets:
  25. pythag(trip)
  26.  
  27. pyTrip([3, 1, 4, 6, 5])
Add Comment
Please, Sign In to add comment