Hi all:
-
Since these next four days will be a loooong weekend here in Madrid, I feel like concocting a brand new HP-15C Mini-ChallengeTM for you to try, namely:
A magic square is a square arrangement of numbers such that each row, column, and main diagonals add up to the same value, say K, which is called the magic square's constant.
Now let's say you're given an arbitrary 3rd order magic square which has some (not given) value K as its constant. You must write a routine which takes the given magic square as its input and then computes the elements of another magic square of the same order but having K3 as its constant instead.
You don't need to include any input or output procedures in your routine, it may assume that the given magic square is already stored in memory in any way you find convenient (such as sequential numeric registers, or a matrix, or whatever) and it just needs to compute the elements of the new magic square and leave them stored in memory, no need to actually output them to the display.
For example, if given the following magic square:
71 89 17which has K = 177 (all rows, columns, and main diagonals add up to 177) you must compute and store
5 59 113
101 29 47
the elements of another magic square of the same order but having K = 1773 = 5,545,233.
You must optimize for program length, the shorter the better. Not counting label and return, it can be done in the number of steps corresponding to a very famous integer traditionally considered having to do with luck (whether good or bad is up to you ...), and further an additional step can be shaved off with one little proviso.
I'll provide my solution and comments next Monday or so, maybe earlier if someone stumbles upon it. Have a nice weekend and all that, and
Best regards from V.
Edited for typos
Edited: 10 June 2009, 6:39 a.m.