Generalize Problem 1 Solution

Now, solution is a function that can take any upper-limit, and doesn't
always just calculate the solution for 1000