# Mary baked a number of cookies. She ate one, gave half of the remaining cookies to her sister, ate another one, then gave half of the remaining cookies to her brother. Given that she ended up with 5 cookies, how many did she start with?

May 30, 2016

$23$

#### Explanation:

Work backwards through the story:

• Mary ends up with $5$ cookies, after giving away half to her brother. So before she gave away half, she had $10$ cookies.

• Before she had $10$ cookies she ate one, so prior to eating that cookie she had $11$ cookies.

• Before she gave away half to her sister, she had $22$ cookies.

• Before eating the first cookie she started with $23$ cookies.

We can express the story algebraically.

If Mary starts with $n$ cookies, then she ends up with:

$\frac{\frac{n - 1}{2} - 1}{2} = 5$

Multiplying both sides by $2$ we get:

$\frac{n - 1}{2} - 1 = 10$

Add one to both sides to get:

$\frac{n - 1}{2} = 11$

Multiply both sides by $2$ to get:

$n - 1 = 22$

Add one to both sides to get:

$n = 23$

Alternative method

In terms of functions, we can define:

$d \left(x\right) = x - 1$

$h \left(x\right) = \frac{x}{2}$

Then the inverse functions are:

${d}^{- 1} \left(x\right) = x + 1$

${h}^{- 1} \left(x\right) = 2 x$

If $n$ is the original number of cookies then:

$h \left(d \left(h \left(d \left(n\right)\right)\right)\right) = 5$

Hence:

$n = {d}^{- 1} \left({h}^{- 1} \left({d}^{- 1} \left({h}^{- 1} \left(5\right)\right)\right)\right) = 2 \cdot \left(2 \cdot 5 + 1\right) + 1 = 23$