Skip to content

armandwayoff/Ulam-Spiral

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

62 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

made-with-p5js made-with-python

$$\text{\Huge Ulam Spiral }$$

What's the Ulam spiral ?

In this repository, I offer two versions of the Ulam spiral. The first is an interactive application written in JavaScript on which you can create your own Ulam spiral according to certain parameters. The second is a version written in Python.

My codes are based on the A063826 sequence:

let $n \in \mathbb{N}^\star$, we define the sequence $(a_n)$ as follows $$a_n := \left \lfloor \sqrt{4n+1} \right \rfloor\ \mathrm{mod}[4].$$ For all $n \in \mathbb{N}^\star, a_n \in \{ 1, 2, 3, 4 \}$. Let $1, 2, 3, 4$ represent moves to the right, down, left and up; this sequence describes the movements in the clockwise square spiral.

Table of Contents

Interactive Application

The interactive application is programmed with the p5.js library. This library is ideal because it has a full set of drawing functionality.

To use the library, simply add it to your HTML code:

<!DOCTYPE html>
<html>
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.10.2/p5.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.10.2/addons/p5.sound.min.js"></script>
  </head>
</html>

Visit the Application

Overview of the Application

overview-application

Python Version

Output Example

Here is an output example with a size 15 Ulam spiral starting at 1:

197	   	   	  	193	  	191	   	  	   	  	   	   	   	   
   	   	   	  	   	  	   	139	  	137	  	   	   	   	   
199	   	101	  	   	  	97 	   	  	   	  	   	   	   	181
   	   	   	  	   	  	   	61 	  	59 	  	   	   	131	   
   	   	103	  	37 	  	   	   	  	   	31	   	89 	   	179
   	149	   	67	   	17	   	   	  	13 	  	   	   	   	   
   	   	   	  	   	  	5  	   	3 	   	29	   	   	   	   
   	151	   	  	   	19	   	   	2 	11 	  	53 	   	127	   
   	   	107	  	41 	  	7  	   	  	   	  	   	   	   	   
   	   	   	71	   	  	   	23 	  	   	  	   	   	   	   
   	   	109	  	43 	  	   	   	47	   	  	   	83 	   	173
   	   	   	73	   	  	   	   	  	79 	  	   	   	   	   
   	   	   	  	113	  	   	   	  	   	  	   	   	   	   
   	157	   	  	   	  	   	163	  	   	  	167	   	   	   
211	   	   	  	   	  	   	   	  	   	  	   	223