Hi to all of you, specially to HP-15C lovers:
Here's a little HP-15C Quiz/Challenge which doesn't
just try to be merely enjoyable but useful as well. Though it is
proposed and particularized for the venerable HP-15C, the
intended solution will be equally applicable to all other
HP calculators with matrix capabilities, i.e.: HP42S,
HP-71B+Math ROM, and HP-41C+Advantage ROM, among others.
The Quiz/Challenge
Suppose we're dealing with an HP-15C's application that requires a number of matrices holding id codes of some sort,
represented as 10-digit integer values from -1E9 to +1E9, say.
The challenge is to write a general purpose subroutine which takes two matrix
descriptors placed in the X,Y stack registers and must then swap the values
of their corresponding matrix elements, subject to these requirements:
1) It must work with any two distinct arbitrary matrices
placed in X,Y, (i.e: A,B,C,D, or E), of the same, arbitrary
dimensions up to a minimum of 30 elements per matrix.
The routine must not assume any two particular matrices
nor any specific dimensions.
2) It must be as short and fast as possible, and use as few
registers and resources as possible, preferably just the stack.
For example, if you have C = (3, 1, 4) and D = (2, 7, 1), the
code segment:
RCL MATRIX C(where LBL A, ..., RTN is your subroutine) should result in
RCL MATRIX D
GOSUB A
matrix C and matrix D holding now (2, 7, 1) and (3,1,4),
respectively.
Try your hand at it. For the record, my best solution to
date is an 11-step routine (not including LBL & RTN),
which swaps two 5x5 matrices in 3.7 seconds,
and uses no register at all, not even the index registers
R0, R1 and RI, just the stack. Let's see yours :-)