Post Reply 
Ulam spiral – non-trivial neighbors of a generic element (HP-12C)
01-25-2018, 05:17 PM (This post was last modified: 01-25-2018 11:37 PM by Gerson W. Barbosa.)
Post: #1
Ulam spiral – non-trivial neighbors of a generic element (HP-12C)
Ulam spiral

64 63 62 61 60 59 58 57
37 36 35 34 33 32 31 56
38 17 16 15 14 13 30 55
39 18 05 04 03 12 29 54
40 19 06 01 02 11 28 53
41 20 07 08 09 10 27 52
42 21 22 23 24 25 26 51
43 44 45 46 47 48 49 50


Code:

01 ENTER 
02 ENTER 
03 ENTER 
04 4
05 *
06 2
07 -
08 √x
09 INTG
10 ENTER 
11 +
12 +
13 5
14 +
15 x<>y
16 1
17 -
18 √x
19 FRAC
20 x=0
21 GTO 42
22 Rv
23 x<>y
24 4
25 *
26 3
27 -
28 √x
29 FRAC
30 x=0
31 GTO 42
32 Rv 
33 x<>y
34 ENTER 
35 +
36 8
37 +
38 x<>y
39 -
40 LASTx
41 GTO 00
42 Rv 
43 ENTER 
44 ENTER 
45 2
46 -
47 GTO 00

Examples:

22 R/S -> 45
x<>y -> 7

31 R/S -> 56
x<>y -> 58

n1 = 5 + n + 2*INT(√(4*n - 2)) (This formula from Don Shepherd’s recent article on the same subject).

For elements on the main diagonals, where either (n - 1) or (4*n - 3) are perfect squares,

n2 = n1 - 2

Otherwise

n2 = 2*n + 8 - n1

The central element, 1, has three non-trivial neighbors: 4, 6 and 8. The program will return 6 and 8.

Code-optimization is left as an exercise.

Edited to fix a typo in step 04.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Ulam spiral – non-trivial neighbors of a generic element (HP-12C) - Gerson W. Barbosa - 01-25-2018 05:17 PM



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