Skip to content

Instantly share code, notes, and snippets.

@jpetazzo
Created March 1, 2012 01:08
Show Gist options
  • Save jpetazzo/1946386 to your computer and use it in GitHub Desktop.
Save jpetazzo/1946386 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
A = [1, 8, -3, 0, 1, 3, -2, 4, 5]
def complementary_pairs(K, A):
buckets = {}
for x in A:
if x not in buckets:
buckets[x] = 0
buckets[x] += 1
N = 0
for i in buckets:
N += buckets[i] * buckets.get(K-i, 0)
return N
print complementary_pairs(6, A)
#!/usr/bin/env python
def isAnagramOfPalindrome(s):
buckets = {}
for c in s:
if c not in buckets:
buckets[c] = 0
buckets[c] += 1
how_many_odds = 0
for v in buckets.values():
if v%2:
how_many_odds += 1
return how_many_odds<2
if __name__ == '__main__':
import sys
s = sys.argv[1]
print isAnagramOfPalindrome(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment