Skip to content

Instantly share code, notes, and snippets.

@fijiaaron
Created Apr 19, 2022
Embed
What would you like to do?
# 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