an elegant algorithm related to Ulam's spiral
|
01-23-2018, 06:04 PM
(This post was last modified: 03-09-2019 03:52 PM by Don Shepherd.)
Post: #1
|
|||
|
|||
an elegant algorithm related to Ulam's spiral
Ulam's spiral is a simple structure with a couple of fascinating characteristics.
Code:
The squares of odd numbers (1, 9, 25, 49) follow a diagonal path to the lower right; squares of even numbers (4, 16, 36, 64) follow a similar pattern to the upper left. There are many diagonal paths that include prime numbers. These are easily visible when you extend the spiral to higher values. There is a very elegant algorithm for determining the non-trivial neighbors of a selected number that was shown to me by member Allen Thomson several years ago. For example, the non-trivial neighbors of number 22 are 7 and 45 (21 and 23 would be trivial neighbors of 22). I have implemented this algorithm on the HP-12c, HP-17b solver, and the HP-65. Here is the 17b solver solution. Enter a value for N and solve for ANS1 and ANS2. Code:
Here is the solution for the 12c. Enter a value and press R/S. One solution will be displayed. Press X<-->Y for the second solution. Code:
edited on 3/9/2019 to add HP-65 solution Here is the solution for the HP-65. Enter the value you want to check and press A. Then press B and C for the two answers. Code:
|
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)