# 0-level algebra and the quant interview question

Apparently a position for a quant trader at a major bank required the candidate to solve this math riddle:

Given a four digit number described by the letters **a1,a2,b1,b2**, provide a formula to tell me if **a1,a2 + b1,b2 = a2,b1**.

For example, they use the number 1978. 19 + 78 = 97.

This doesn't really seem like a quantitative analysis problem, this seems to be algebra.

So, we know

a2 + b2 = (r * 10) + b1

where r is the "remainder" that will go into the adjacent left column. using the example above, 9 + 8 = (1 * 10) + 7

restating as

(r * 10) = a2 + b2 - b1

We also know that completing the addition in the adjacent left column means

r+ a1 + b1 = a2

so

r = a2 - a1 - b1

and

r * 10 = (a2 - a1 - b1) * 10

equating these

a2 + b2 - b1 = (a2 - a1 - b1) * 10

and solving for each now yields

a1 = (((a2 + b2 - b1) / 10) + b1 - a2) * (-1)

a2 = ((a2 - a1 - b1) * 10) - b2 + b1

b1 = (((a2 - a1 - b1) * 10) - a2 - b2) * (-1)

b2 = ((a2 - a1 - b1) * 10) - a2 + b1

Here's the haskell to find all such numbers from 1000 to 9999:

*last update 2011-09-09*