[QUIZ] Perl 'Easy' Quiz of the Week #2006-04-02 - Rounded Fractions

Yitzchak Scott-Thoennes <[email protected]> Sun, 2 Apr 2006 13:21:17 -0700
Newsgroups gmane.comp.lang.perl.qotw.discuss
Organization bs"d
Message-ID <[email protected]>
IMPORTANT: Please do not post solutions, hints, or other spoilers
until at least 60 hours after the date of this message.  Thanks.

Cooking often involves multiplication and rounding of fractions, at
least for those of us stuck under the tyranny of U.S. customary units.
For instance, to make oatmeal, I use 7 parts water to 4 parts
thick-cut rolled oats.  If I have 1 2/3 cups oats, about how much
water should I use?  5/3 * 7/4 = 35/12 = ~3 cups.

Your task: create a script that prompts for a ratio of two integers
and a quantity given as a whole number and/or a fraction (e.g. "1
3/5", "12", "3/7") and print out a rounded result of multiplying the
quantity by the ratio in the same format.

The result should be rounded to the nearest half, third, or fourth,
whichever is most accurate (in cases exactly between two quantities,
using the lowest denominator).  You may assume none of the integers are
overly large.