Challenging Mathematical Teasers; Pecking Order

I was going through the book "Challenging Mathematical Teasers" by J.A.H. Hunter, and, of course, I got stumped. Naturally, I went to the solutions part of the book, but here's the kicker, the solution raised more questions.

My question is, rather, a favor, could someone please explain the logic of the solution to this question:

Four sparrows found a dish of seed, Fine birdie food, no common weed. Said Pip: "In turn each take two grains And then a third of what remains. It's me as first, then Pep, then Pop, With Pap the last. And then we stop."

But Pap cried out: "It isn't fair. Mine's two seeds less than half Pep's share." Old Pip was boss, his word was law, So little Pap got nothing more. Poor Pap, his share was rather small! How many seeds were there in all?

First, try to solve this question on your own. Now here is the solution:

Say there were $$x$$ seeds.
Pip left $$(2x-4)/3$$, Pep left $$(4x-20)/9$$, Pop left $$(8x-76)/27$$.
Then, Pep took $$(2x+8)/9$$.
Pap took $$(8x+32)/81$$.
So $$(8x+32)/81=(x+4)/9 - 2$$.
Hence, $$x=158$$.

The question is, can someone explain to me how you would even get these equations in the first place?

There are $$x$$ seeds. Pip takes $$2$$ grains and a third of what remains, which amounts to $$2 + (x-2)/3=(x+4)/3$$. So after Pip, there are $$x-(x+4)/3=(2x-4)/3$$ seeds. Pep takes $$2 + ((2x-4)/3 - 2)/3 = (2x+8)/9$$ seeds and leaves $$(2x-4)/3 - (2x+8)/9 = (4x-20)/9$$ seeds. Proceed like this until you find that Pap took $$(8x+32)/81$$ seeds. But this is equal to two less than half Pep's share: $$\frac{8x+32}{81}=\frac{1}{2}\frac{2x+8}{9}-2$$ Solve for $$x$$.
• He takes $2$ seeds. Remaining are $x-2$ seeds. He takes a third of that as well, which is $(x-2)/3$. In total, he takes his original $2$ seeds and this other part: $2 + (x-2)/3$ – J_P Jun 24 at 19:20
Suppose you start with $$x$$ seeds. First, Pip takes two seeds and a third of what's left, i.e., $$(x-2)*(1/3)+2$$ is the share of Pip = $$(x-4)/3$$. Therefore Pip leaves, $$x-(x-4)/3=(2x-4)/3$$
Similarly, Pep will take, $$((2x-4)/3-2)*(1/3)+2 = (2x+8)/9$$... And so on
That's how you get the equations and you solve for $$x$$