Pairing socks algorithm
stackoverflow.com