We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I came up with a nice formula for solving the problem.
We start off with a self-referential formula:
t = money + wrappers
t = floor(n/c) + floor((t-1)/m)
The reason we use t-1 over t is because the wrapper you acquire from your last exchanged chocolate is not part of your available resources.
We then solve for t:
t - floor((t - 1) / m) = floor(n/c)
ceil(t - (t - 1) / m) = floor(n/c)
ceil((mt - t + 1) / m) = floor(n/c)
We can convert this to an inequality. The idea is that mt - t + 1 must be at between floor(n/c)-1 (non-inclusive) and floor(n/c) (inclusive) multiples of m.
Chocolate Feast
You are viewing a single comment's thread. Return to all comments →
I came up with a nice formula for solving the problem.
We start off with a self-referential formula:
The reason we use
t-1
overt
is because the wrapper you acquire from your last exchanged chocolate is not part of your available resources.We then solve for t:
We can convert this to an inequality. The idea is that
mt - t + 1
must be at betweenfloor(n/c)-1
(non-inclusive) andfloor(n/c)
(inclusive) multiples ofm
.Note there can be multiple values of
t
that are within this range. We select the largest, because we want the maximum amount of chocolatesAnother form of this is what @ansonete described below: