Multiple solution to a simple algorithm problem