first solution to problem 5 - brute force