This post gives the answer to last week’s Problem of the Week.

First of all, I have to admit that this problem actually came from the Quicker Maths blog. This blog actually pulled the problem from IBM’s Ponder this section.

First of all, in order to write the equation algebraicly, we could express the relationship as follows:
x2 + y2 = x + y × 1000

Unfortunately, the difficulty with solving the problem with just pencil and paper is the fact that we have to solve for the variables when they are both integers. For this reason, let’s do it with a programming language such as Python:

arr = []
for x in range(1000, 10000):
    for y in range(x, 10000):
        sum = x * x + y * y
        if sum == x * 10000 + y:
            arr.append("x = {0}, y = {1} => {2}".format(x, y, sum))
        elif sum == y * 10000 + x:
            arr.append("x = {0}, y = {1} => {2}".format(y, x, sum))

print("x * x + y * y = x * 10000 + y where:")
print("\n".join(arr))

Using this code will result in the following being printed out:

x * x + y * y = x * 10000 + y where:
x = 9412, y = 2353 => 94122353

As you can see, this was the brute-force way of solving this problem, but sometimes the brute-force way is the fastest way to come to the correct answer. 8)


Leave a Reply

Your email address will not be published. Required fields are marked *