HP15C MiniChallenge: RSUM, CSUM Message #1 Posted by Valentin Albillo on 10 June 2005, 5:00 a.m.
Hi, all
As an appetizer before the next S&SMC (#11), here you are, a new, very easy, small, and potentially useful minichallenge specifically for the HP15C.
Tha facts
Many handhelds and calculators that have builtin matrix operations capabilities do include a couple of matrix functions, usually called RSUM/CSUM that return the sum of all rows/columns of any given matrix. This is the case, for instance, for the HP41C's Advantage ROM, where according to its manual:
CSUM finds sums of columns and puts them in a row matrix
RSUM finds sums of rows and puts them in a column matrix
i.e., if some matrix A is 4x5, say, CSUM would return a 1x5 matrix, B, where each element would be the sum of the corresponding column in A. Likewise, RSUM would return a 4x1 matrix, B, where each element would be the sum of the corresponging row in A.
Now, the HP15C does not include such matrix operations as builtin functions, so this is the
Challenge
You must write two separate small routines (LBL ... RTN) that will implement the RSUM and CSUM functionality described above.
Your routines should assume that there exists an MxN matrix called A, and upon being called must return a matrix B to the X register, containing the respective sums. For the case of the RSUM routine, the resulting matrix B must be Mx1, while for the CSUM routine, it must be 1xN.
Your must optimize your routines for speed and space, the faster and shorter the better. Here's an example. Given:
 1 7 3 2 5 
A =  0 4 5 6 3 
 4 8 3 1 7 
 8 3 6 12 6 
CSUM must return: B =  3 22 7 9 21 
RSUM must return:  12 
B =  6 
 17 
 7 
Epilogue
My original solutions, not counting the mandatory LBL and RTN, are 8 steps for RSUM and 9 steps for CSUM. Both can return the sum of all rows/columns of a 6x8 matrix in 5 seconds flat.
Now it's your turn ! Don't be afraid to try, it's actually very easy. Let's see your solutions ! :)
Best regards from V.
