A New Small HP15C Challenge (Prize awarded!) [LONG] Message #1 Posted by Valentin Albillo on 15 June 2004, 7:37 a.m.
Hi all,
To spice the week a little, exclusively for HP15C owners and lovers (i.e., most of us; no other calculators allowed), here's a New, Small HP15C 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
highquality scan of your preferred rare vintage HP brochure to choose among these three:
HP65 brochure (in English, rare!)
HP55 brochure (in Spanish, very rare!!)
HP01 brochure (in French, extremely rare!!!)
You can click the above links to see (purposely lowquality, lores) samples of all three. The scanned brochures themselves are marvelous, large, hires 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 Challenge
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 nondiscounted 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 HP15C, which will be called either from the keyboard or from some
other main program, and must *EXACTLY* meet the following specifications, totheletter.
 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 nondiscounted amounts to discounted amounts, your routine
will be called with matrix C (which will hold a certain number of nondiscounted amounts, arbitrary dimensions) in the X register.
. Your
routine must replace them inplace 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
discounted amounts:
RCL MATRIX C [A] > [C 1 3]
where now C holds the discounted amounts, C = (18, 27, 45)
 To convert discounted amounts to nondiscounted 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 inplace with the nondiscounted 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, nondiscounted amounts:
RCL MATRIX D [A] > [d 1 3]
where now D holds the original, nondiscounted 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, nondiscounted 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)
Notes:
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.
