A monkey picks a pile of peaches. Each day it eats half of what is left, plus 1 more. On the morning of day days, only 1 is left. Write peaches(days): how many peaches were there on day 1? If days is 2: 1 is left on day 2, so day 1 had (1 + 1) × 2 = 4. If days is 1, the answer is 1.
peaches(10)→1534peaches(2)→4peaches(3)→10int peaches(int days)int peaches(int days) {
int x = 1;
for (int d = days - 1; d >= 1; d--) {
// your code here: from the next day's count, work out the day before
}
return x;
}
Run tries the examples. When they look right, Submit.