How does this simple algorithm work?

Printable View