Is HP42 smarter than a kid on TV?
|
04-28-2018, 08:03 PM
(This post was last modified: 04-28-2018 08:03 PM by Dol.)
Post: #1
|
|||
|
|||
Is HP42 smarter than a kid on TV?
Just for fun,
could we make a HP42 program that fills a 5x5 matrix given an input between 65-300 ending with a 0 or a 5 where row, colum and diagonal sum equal to the input number like Miguel? For reference: https://www.youtube.com/watch?v=u0Sfe1BGjQE Good luck! Fredrik |
|||
04-28-2018, 08:14 PM
Post: #2
|
|||
|
|||
RE: Is HP42 smarter than a kid on TV?
If I have to guess, it is the 5x5 magic square, where the magic number is 65. Then one can scale the numbers and the condition of having a multiple of 5 helps redistributing the numbers.
But that's a guess. In any case the algorithms would be interesting. Wikis are great, Contribute :) |
|||
04-28-2018, 10:18 PM
Post: #3
|
|||
|
|||
RE: Is HP42 smarter than a kid on TV?
(04-28-2018 08:14 PM)pier4r Wrote: If I have to guess, it is the 5x5 magic square, where the magic number is 65. Then one can scale the numbers and the condition of having a multiple of 5 helps redistributing the numbers. Exactly. The kid just needs to remember *one* 5x5 magic square formed by the numbers 1 to 25 (which is very easy because of the symmetries, no need to remember the contents of the 25 locations), which thus has a magic sum of 65 for every row, column and both main diagonals, and then adds a constant to every number where the constant is simply the provided number less the magic constant and the result divided into 5 (which is why the provided number has to end in 0 or 5 lest the division into 5 would fail to give an integer result). For instance, in the video he is given 265. He just subtracts from it the fixed magic constant 65, which gives 200, the divides this into 5, which is 40. He then adds 40 to every number from 1 to 25, which gives numbers from 41 to 65, and proceeds to very theatrically fill up the locations in some haphazard order, just for effect. He could actually fill them up in a few seconds left to right, top to bottom, without the theatrics and the "checks" but there you are. In short, a lame theatrical act which doesn't require any mathematical skills whatsoever, let alone "genius", and a minimal amount of memory. As for the algorithm, it is anything but interesting: a few HP42S steps or about 2-3 lines of HP-71B code, at most. Execution time (one subtraction, one division, and 25 sums, all integer) is essentially 0. Regards. V. . All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
04-28-2018, 10:32 PM
Post: #4
|
|||
|
|||
RE: Is HP42 smarter than a kid on TV?
Quote:In short, a lame theatrical act which doesn't require any mathematical skills whatsoever, let alone "genius", and a minimal amount of memory. As for the algorithm, it is anything but interesting: a few HP42S steps or about 2-3 lines of HP-71B code, at most. Execution time (one subtraction, one division, and 25 sums, all integer) is essentially 0. you should out him in the youtube comments |
|||
04-28-2018, 11:26 PM
Post: #5
|
|||
|
|||
RE: Is HP42 smarter than a kid on TV?
(04-28-2018 10:32 PM)Zaphod Wrote: you should out him in the youtube comments Nope, I'm not in the business of shaming anyone publicly, least of all a very young kid. He probably makes a living out of it and who knows, perhaps he'll develop a genuine interest in mathematics as he grows up. All the same, to put my code where my mouth is, this is a 3-line, 150-byte routine for the HP-71B: 10 DATA 17,24,1,8,15,23,5,7,14,16,4,6,13,20,22,10,12,19,21,3,11,18,25,2,9 20 DESTROY ALL @ OPTION BASE 1 @ DIM A(5,5),B(5,5) @ READ A @ INPUT N 30 MAT B=((N-65)/5) @ MAT A=A+B @ MAT DISP USING "2D,2X";A >RUN ? 265 57 64 41 48 55 63 45 47 54 56 44 46 53 60 62 50 52 59 61 43 51 58 65 42 49 >RUN ? 65 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 >RUN ? 300 64 71 48 55 62 70 52 54 61 63 51 53 60 67 69 57 59 66 68 50 58 65 72 49 56 A conversion to run in the HP42S is utterly straightforward and will be left as an exercise to the reader. Regards. V. . All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
04-30-2018, 09:09 AM
Post: #6
|
|||
|
|||
RE: Is HP42 smarter than a kid on TV?
(04-28-2018 10:18 PM)Valentin Albillo Wrote: The kid just needs to remember *one* 5x5 magic square formed by the numbers 1 to 25 (which is very easy because of the symmetries, no need to remember the contents of the 25 locations), Would you elaborate a bit more on the bolded? I'd like to know how to do that. Thanks, |
|||
04-30-2018, 11:27 AM
Post: #7
|
|||
|
|||
RE: Is HP42 smarter than a kid on TV?
Here’s a quick hack to create a magic square of odd order:
Code: 00 { 77-Byte Prgm } Cheers, Werner 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
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: Thanks for doing the harder part! Here is an easier add-on: Code:
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). |
|||
04-30-2018, 06:00 PM
Post: #9
|
|||
|
|||
RE: Is HP42 smarter than a kid on TV?
Some optimization, same usage:
Code:
Perhaps we should combine both programs for best efficiency. |
|||
04-30-2018, 10:50 PM
Post: #10
|
|||
|
|||
RE: Is HP42 smarter than a kid on TV?
(04-30-2018 09:09 AM)RMollov Wrote:(04-28-2018 10:18 PM)Valentin Albillo Wrote: The kid just needs to remember *one* 5x5 magic square formed by the numbers 1 to 25 (which is very easy because of the symmetries, no need to remember the contents of the 25 locations),Would you elaborate a bit more on the bolded? This is the very magic square the kid uses as a basis, later adding the computed constant to all its elements. First notice this easy-to-remember Z pattern along the diagonal: 10-11-12-13-14-15-16: 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 This takes care of 7 numbers (by the way, the central element, 13, is simply the magic constant (65) divided by the order of the square (5): 65/5 = 13). Next notice the patterns in the smaller diagonals: 4-5-6-7-8: 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 and 18-19-20-21-22: 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 This already takes care of the locations of 17 of the 25 numbers and the remaining 8 also belong to patterns (2,3, ... , 23,24, etc.) Notice also that all elements placed symmetrically in respect to the center one add up to 26. For instance, the four corners 17 and 9 (17+9=26), 15 and 11 (15+11=26), and all the rest too (24+2, 1+25, 8+18, 4+22, 10+16, etc), so you'd only need to remember half the locations plus the fact that 13 is the center one (as explained before). In short, the whole 5x5 magic square can be remembered with very minimal effort after memorizing a few patterns and the symmetry x+x' = 26. After a little practice you'll get the hang of it. V. . All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
05-01-2018, 11:14 AM
Post: #11
|
|||
|
|||
RE: Is HP42 smarter than a kid on TV?
(04-30-2018 10:50 PM)Valentin Albillo Wrote: This is the very magic square the kid uses as a basis, later adding the computed constant to all its elements. First notice this easy-to-remember Z pattern along the diagonal: Thanks a lot, Valentin, that makes perfect sense now. Much appreciated. Cheers, |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)