Skip to content

Instantly share code, notes, and snippets.

@juanitobanca
Last active March 3, 2017 04:04
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 juanitobanca/0d3fa3bc914c446c8c690dc900a40786 to your computer and use it in GitHub Desktop.
Save juanitobanca/0d3fa3bc914c446c8c690dc900a40786 to your computer and use it in GitHub Desktop.
def triplets( alist ):
alist.sort()
p = getPartitionInt( alist )
trips = set()
if p == -1:
return "No Triplets"
glz = alist[:p]
gez = alist[p:]
for l in glz:
for e in gez:
if -(l+e) < 0:
x = binarySearch(glz, -(l+e))
else:
x = binarySearch(gez, -(l+e))
if x:
t = [l,e,-(l+e)]
t.sort()
trips.add(tuple(t))
return trips
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment