Post Reply 
Is HP42 smarter than a kid on TV?
04-30-2018, 02:20 PM (This post was last modified: 04-30-2018 04:14 PM by Gerson W. Barbosa.)
Post: #8
RE: Is HP42 smarter than a kid on TV?
(04-30-2018 11:27 AM)Werner Wrote:  Here’s a quick hack to create a magic square of odd order:
Code:
00 { 77-Byte Prgm }
01▸LBL "MAGIC"
02 ENTER
03 NEWMAT
04 EDIT
05 LASTX
06 X↑2
07 1
08 LASTX
09 1
10 +
11 2
12 ÷
13 STOIJ
14 R↑
15▸LBL 02
16 ENTER
17 ↑
18 FS? 77
19 GTO 01
20 FS? 76
21 GTO 00
22 ←
23 FC? 77
24 GTO 02
25 J-
26 I+
27 GTO 00
28▸LBL 02
29 FS? 76
30 ↓
31 X=0?
32 GTO 00
33 J+
34▸LBL 01
35 I+
36 I+
37▸LBL 00
38 R↓
39 DSE ST X
40 GTO 02
41 RCLEL
42 EXITALL
43 END

Thanks for doing the harder part! Here is an easier add-on:

Code:

00 { 33-Byte Prgm }
01▸LBL "MAG2"
02 RCL ST Y
03 DIM?
04 R↓
05 2
06 1/X
07 X<>Y
08 ×
09 LASTX
10 X↑2
11 NOT
12 BASE+/-
13 ×
14 -
15 RCL ST Y
16 DIM?
17 R↓
18 ÷
19 +
20 END

Examples:

1)

5 XEQ MAGIC
265 XEQ MAG2

2)

3 XEQ MAGIC
27 XEQ MAG2

—>

08 13 06

07 09 11

12 05 10


Gerson.

=========

PS:

k = constant of the magic square (265 in the TV show)

m = n(n^2 + 1)/2; magic constant of the original magic square (whose elements start with 1)

n = order of the square

c = (k - m)/n; constant to be added to each element of the original magic square so that the new magic sum is k

Notice that k must be equal or greater than m and be divisible by n

The sums, except the diagonals, can be checked with RSUM:

ENTER
RSUM
X<>Y
TRANS
RSUM


Just for fun, another example:

101 XEQ MAGIC
260176505 XEQ MAG2

Runs instantly on Free42 on my smartphone :-)

Edited to delete the last three or four lines (there was no need to preserve Werner’s original matrix anymore).
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Is HP42 smarter than a kid on TV? - Dol - 04-28-2018, 08:03 PM
RE: Is HP42 smarter than a kid on TV? - Gerson W. Barbosa - 04-30-2018 02:20 PM



User(s) browsing this thread: 1 Guest(s)