|A New Small HP-15C Challenge (Prize awarded!) [LONG]|
Message #1 Posted by Valentin Albillo on 15 June 2004, 7:37 a.m.
To spice the week a little, exclusively for HP-15C owners and lovers (i.e., most of us; no other calculators allowed), here's a New, Small HP-15C Challenge. As always, it's very small yet it tries hard to be both entertaining and educational as well. But this time there are a couple novelties:
- You must have a real pro attitude this time. You'll be "commissioned" to develop a solution strictly according to a series of compulsory requirements, and you must deliver, as in real life.
- There's a (small) Prize awarded this time to the person who writes the best routine which unfailingly meets all specifications. 'Best' is intended to mean the routine is as short, fast, and uses the least resources as possible. If several solutions are equally deserving, all with be awarded the prize, myself being the final and sole judge.
The (small) Prize is your choice of a complete, very
high-quality scan of your preferred rare vintage HP brochure to choose among these three:
HP-65 brochure (in English, rare!)
HP-55 brochure (in Spanish, very rare!!)
HP-01 brochure (in French, extremely rare!!!)
You can click the above links to see (purposely low-quality, lo-res) samples of all three. The scanned brochures themselves are marvelous, large, hi-res scans, multiple pages for each brochure, to be delivered to you electronically. They're certainly a pleasure to behold and read (though it also makes you a little sad and nostalgic to see what superb products and marketing brochures HP produced in its prime ...)
Even if you're not (!?) that interested in the scanned brochures, have a go at the Challenge. Though it seems simple enough, you'll quickly realize it's far from trivial to come up with even a working version according to the specifications, let alone an optimum one.
The owner of a small business wants, given a certain discount percentage rate
between 10.00% and 99.99% (both included), to compute both discounted amounts
from a series of non-discounted amounts and vice versa. She also wants to be able
to total both types of amounts for a series of conversions, plus be able to
specify the percentage rate at any time.
To that effect she's commissioned you to write a routine (LBL A ... RTN) for
her trusty HP-15C, which will be called either from the keyboard or from some
other main program, and must *EXACTLY* meet the following specifications, to-the-letter.
- To specify the percentage rate (P), your routine will be called with the
percentage (between 10.00% and 99.99%) in the X register, will
likely store it somewhere else for later computations, and must
return with that same value unchanged in the X register, like this:
To set a 10.00% discount:
10 [A] -> 10.0000
- To convert non-discounted amounts to discounted amounts, your routine
will be called with matrix C (which will hold a certain number of non-discounted amounts, arbitrary dimensions) in the X register.
routine must replace them in-place with the discounted amounts and return
with said matrix C in the X register, like this:
Assuming that P = 10.00% and with C = (20, 30, 50), to compute the
RCL MATRIX C [A] -> [C 1 3]
where now C holds the discounted amounts, C = (18, 27, 45)
- To convert discounted amounts to non-discounted amounts, your routine
will be called with matrix D (which will hold a certain number of discounted amounts, arbitrary dimensions) in the X register. Your routine must
replace them in-place with the non-discounted amounts and return with
said matrix D in the X register, like this:
Assuming that P = 10.00% and with D = (36, 63, 81), to compute the
original, non-discounted amounts:
RCL MATRIX D [A] -> [d 1 3]
where now D holds the original, non-discounted amounts, D= (40, 70, 90)
- To totalize the discounted amounts in matrix C to the grand totals stored
in matrix E, your routine must expect matrix C to be in Y and matrix E
to be in X, like this:
RCL MATRIX C, RCL MATRIX E [A] -> [E 1 3]
Assuming C = (18, 27, 45) and that E was (10, 20, 30), E is now (28, 47, 75)
- To totalize the original, non-discounted amounts in matrix D to the grand
totals in matrix E, your routine must expect matrix D to be in Y and matrix E
to be in X, like this:
RCL MATRIX D, RCL MATRIX E [A] -> [E 1 3]
Assuming D = (40, 70, 90) and that E was (15, 20, 25), E is now (55, 90, 115)
Well, let's see if you're up to the task. Of course, the least resources
your routine uses, the better. There's a solution fulfilling all specified
requirements in 24 program steps or less (including LBL A ... RTN), which I will post after the Challenge is over, within a few days. Hope you'll enjoy it and ...
Best regards from V.