Skip to content

Instantly share code, notes, and snippets.

@syntacticsugar
Last active May 11, 2019 18:03
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 syntacticsugar/719dc805fda6a71c6a34f2524aeb14f1 to your computer and use it in GitHub Desktop.
Save syntacticsugar/719dc805fda6a71c6a34f2524aeb14f1 to your computer and use it in GitHub Desktop.
For an array of socks, return the total number of matching pairs. (integer represents a unique color)
n = 7
arr = [ 1,2,1,2,1,3,2 ]
def matchingPairs(qty,socks):
pairs = 0
counts = {}
for s in socks:
if s in counts:
counts[s] += 1
else:
counts[s] = 1
print(counts)
total = 0
for val in counts.values():
total = total + int(val/2)
return total
print (matchingPairs(n,arr))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment