Skip to content

Instantly share code, notes, and snippets.



Last active Aug 29, 2015
What would you like to do?
Python program resembling how I pile my socks.
import random
# Each colour of sock represented by an integer.
socks = 2 * range(20)
# Randomize the order of our socks.
# Container variable for our sorted socks and working stack.
sorted = []
stack = []
# Iterate over the unsorted socks one by one.
for sock in socks:
if sock in stack:
# If we have a matching sock already picked add them to our
# sorted socks.
# Otherwise place the sock in our sorting stack.
# Print a per sock representation of our sorting procedure.
print 'Stack:', stack
print 'Sorted:', sorted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.