Weekly Pocket Money Problem
Say that there is a parent and a child, and the child wants to obtain the highest number of pocket money possible while competing against other siblings.
Here are the constraints.
- The parents have a fixed weekly allowance
for all children. - The children have no knowledge of
. - No child knows what the other sibling requests.
- Not every child asks for allowance money every week.
- The child may ask for money in increments of a dollar
times as long as long as for that week. - If a child requests for money that would result in
, the child gets smacked and receives nothing. - The child does not want to get smacked and want to maximize the pocket money.
Solution
The solution to the problem can be described by the following pseudo-code.
def calculate_threshold(smack_num, initial_cwnd=1, security_coefficient=0.5):
cwnd = initial_cwnd
while cwnd < smack_num:
cwnd *= 2
return cwnd * security_coefficient
def calculate_cwnd(weeks, threshold, initial_cwnd=1):
cwnd = initial_cwnd
for week in range(1, weeks + 1):
print(f"Week {week}: cwnd = {cwnd}")
requests = int(cwnd)
for _ in range(requests):
if cwnd <= threshold:
cwnd += 1
else:
cwnd += 1 / cwnd
Although not described above, if the child gets smacked at any point, then a new threshold is calculated using that
Example Problem
A child starts numbering weeks from 0 (zero) when he get smacked. On Week 0 he got smacked when he asked 24 dollars. Assuming that the child asks for money each week, the child will ask for
Week 0: In this example, we know the threshold from week 0. Since knowing the threshold entails getting smacked, we won't be receiving any more money for this week.
Week 1: We start at week 1 with
Week 2: Since
Week 3: We start off with
Week 4: This week is especially important because we will surpass our threshold in this week. We start with
is under the threshold: . is under the threshold: . is under the threshold: . is under the threshold: . is at the threshold: . is over the threshold: . is over the threshold: . is over the threshold: .
Week 5: The child will make
In practicality, however, it may be difficult to calculate precisely the values for when it is over the threshold. We can use a general approximation that may be useful on an exam where calculator functionality is limited.
For every iteration over the threshold, we can increment