Created
April 19, 2022 22:15
-
-
Save fijiaaron/f6eb21be46f72f64b89f4b77298c1145 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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