OK, here is a challenge. Devise an RPN program or Solver solution to the following problem. Refer to this. Assume this pattern continues forever. I want to input a number, like 19, and the program must tell me the 4 adjacent numbers, like 6, 18, 40, and 20. I see the patterns of square numbers, but I'm not sure this will help me figure out the four numbers I am interested in.
minichallenge


« Next Oldest  Next Newest »

▼
02242008, 11:47 AM
▼
02242008, 12:32 PM
Kind of Bible Codeish.... However, the Bible Code folks do equidistant spacing to find predictions.
02242008, 12:47 PM
This looks surprisingly like a map of Paris' arrondissements . Perhaps Mike D. can help here. :)
02242008, 04:47 PM
That's Ulam Spiral. The following QBASIC program will generate a similar spiral. It is a slight adaptation of a BASIC program I found in an old book about an early Brazilian dotmatrix printer, by Victor Mirshawka (Grafix MTA: A Impressora ao Alcance de Todos). Apparently the author was not aware of Ulam Spiral, as he doesn't mention it in his printer application. Gerson.

02242008, 05:51 PM
Don, Thanks for an interesting challenge. I think this may be smaller on the 42S, but I had a 48GX on the desk, so here is an unoptimized 48g solution. I use a 'corner and sides' approach whereby the FLOOR and CEIL of the Square roots are used to generate the corners and then determine from the max corner which side the input resides on. NOTE: Assumes 1 and 2 are trivial cases not to be calculated. e.g. if input=1 then {2 4 6 8} and likewise for 2. The program (not optimized for either size or speed):
Bytes: 255
Example (sorted) results: 4 {1 3 5 15} edited to add comments
Edited: 24 Feb 2008, 6:17 p.m. ▼
02242008, 08:16 PM
Thanks Gerson and Hudendai. Yes, Gerson, I had read about that pattern of prime numbers going along the diagonals on an arrangement like this, and that is fascinating. I didn't realize that its name was the Ulam Spiral, however. Hudendai, thanks for your 48 solution, I am impressed! I'm going to translate it to RPN and maybe try it on my HP65.
▼
02252008, 12:15 AM
Don,
bytes: 76
(edited) Example results: 4 XEQ 00 Y: 1 X: 15
Edited: 25 Feb 2008, 1:41 a.m. ▼
02252008, 09:13 AM
Hudendai, that's great! I see what you mean about the 2 trivial solutions, which will always be one greater and one less than your input number. I'm going to enter this on my 65 and try it. Then I'm going to study it to see exactly how you did it! Thanks, Don ▼
02252008, 09:17 PM
Don, I combined terms and was able to revise all solutions to this form
First root : I+2c+3 (solution for both sides and corners)As a result, I was able to rewrite the 42s solution down to MUCH smaller size. ▼
02252008, 09:49 PM
Edited: 26 Feb 2008, 8:45 a.m. 