Skip to content

Instantly share code, notes, and snippets.

@fijiaaron
Created April 19, 2022 22:15
Show Gist options
  • Save fijiaaron/f6eb21be46f72f64b89f4b77298c1145 to your computer and use it in GitHub Desktop.
Save fijiaaron/f6eb21be46f72f64b89f4b77298c1145 to your computer and use it in GitHub Desktop.
# You have a basket of socks
# There are a random assortment of socks
# They may have pairs
# Pick a sock out of the basket
# Keep pickings socks, one a time, until you have gone through them all
# Every time you find a match, put them together and set aside
import random
# random.seed(1)
basket = [random.randint(1,4) for i in range(10)]
print(basket)
socks = set()
for sock in basket:
if sock not in socks:
socks.add(sock)
else:
print("found match: " + str(sock))
socks.remove(sock)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment