I need help finding an equation to solve the problem found here: aha! : paul scott : a regular problem

i have worked it out using trail and error and stuffing around with match sticks but i have know idea how to make an equation to solve it.

Do i need to use simultaneous equations?

Thanks in advance,

Fuzzy