Problem 5 solution - bruteforce, not very nice