2600.12 – Postage Function, Using [ ]


If the postal rate for first class letters is 49 cents for the first ounce or portion of an ounce, and 21 cents for every ounce or portion of an ounce after the first, then find the cost of sending a letter weighing w ounces, where w is some positive real number. Use [w] to stand for the greatest integer less than w, as usual.


Solution

So the problem calls for an expression that rounds up, but we’re only given a function that rounds down.

Here’s one way to do it:

21([w] – [[w] – w] – 1) + 49

21([w] – [[w] – w]) + 28