Created
January 8, 2017 03:14
-
-
Save DawnPaladin/95c31a9b7ed9edc56f63d14035d21045 to your computer and use it in GitHub Desktop.
Advanced, broken sock sorting for https://medium.com/@DawnPaladin/sorting-socks-e31e254bfa6f
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
def advanced(sock_pile) | |
sock_book = Hash.new(Array.new) | |
pairs = [] | |
sock_pile.each do |sock| | |
if sock_book[sock].length > 0 | |
pairs.push([sock, sock_book[sock].pop]) | |
else | |
sock_book[sock].push(sock) | |
end | |
end | |
pairs | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment