It's a well-known problem in mathematical literature that justifying socks is, in fact, impossible. The infinite varieties of human feet and the capricious nature of sock elasticity make it a Sisyphean task.
But, for the sake of argument, let's assume we can somehow justify these socks. What's the optimal algorithm for justifying 7.3 billion different types of socks?
Sock-Justification 101: The Basics