Problem 59 brute force solution