Anyone knows a good algorithm for this?

Printable View