Post Reply 
Ulam spiral – non-trivial neighbors of a generic element (HP-12C)
01-27-2018, 08:06 AM
Post: #5
RE: Ulam spiral – non-trivial neighbors of a generic element (HP-12C)
(01-27-2018 03:26 AM)Gerson W. Barbosa Wrote:  
(01-25-2018 05:27 PM)Don Shepherd Wrote:  Yes, I knew my programs get a sqrt(neg number) error for n=1.

Don, I did notice that error, but it was not my intention to fix it. I was just interested in knowing the formulas you have used. After analyzing the first few lines of your 12C program and getting the formula for the first non-trivial neighbor I got lazy and rather than trying to figure out the formula for the second one I decided to find a relationship between them. That was not hard, but probably a straightforward conversion of your program to RPL would have yielded better byte counts. Each of the following is 117.5 bytes long:


« DUP 5 + OVER 4 * 2 - √ IP DUP + + SWAP DUP 4 * 3 - √ FP OVER 1 - √ FP * NOT { DROP DUP 2 - } { 4 + DUP + OVER - } IFTE
»

« DUP 5 + OVER 4 * 2 - √ IP DUP + + 2 OVER - ROT DUP 4 * 3 - √ FP OVER 1 - √ FP * NOT { DROP NEG } { 3 + DUP + + } IFTE
»

« DUP 5 + OVER 4 * 2 - √ IP DUP + + DUP 2 - ROT DUP 4 * 3 - √ FP OVER 1 - √ FP * NOT { DROP } { 3 + DUP + SWAP - } IFTE
»
Thanks Gerson.

I continue to be amazed at what can be accomplished with RPL. You have my deepest respect.

Don
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Ulam spiral – non-trivial neighbors of a generic element (HP-12C) - Don Shepherd - 01-27-2018 08:06 AM



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