Difference between revisions of "Ulam spiral (for primes)"
(Creation of page) 
(No difference)

Latest revision as of 14:33, 11 October 2019
This page is a solution to the task Ulam spiral (for primes) in the Rosetta Code, written in Fōrmulæ.
Description (from Rosetta Code)
An Ulam spiral (of primes) is a method of visualizing primes when expressed in a (normally counterclockwise) outward spiral (usually starting at 1), constructed on a square grid, starting at the "center".
An Ulam spiral is also known as a prime spiral. The first grid (green) is shown with sequential integers, starting at 1. In an Ulam spiral of primes, only the primes are shown (usually indicated by some glyph such as a dot or asterisk), and all nonprimes as shown as a blank (or some other whitespace). Of course, the grid and border are not to be displayed (but they are displayed here when using these Wiki HTML tables). Normally, the spiral starts in the "center", and the 2^{nd} number is to the viewer's right and the number spiral starts from there in a counterclockwise direction. There are other geometric shapes that are used as well, including clockwise spirals. Also, some spirals (for the 2^{nd} number) is viewed upwards from the 1^{st} number instead of to the right, but that is just a matter of orientation. Sometimes, the starting number can be specified to show more visual striking patterns (of prime densities). [A larger than necessary grid (numbers wise) is shown here to illustrate the pattern of numbers on the diagonals (which may be used by the method to orientate the direction of spiralconstruction algorithm within the example computer programs)]. Then, in the next phase in the transformation of the Ulam prime spiral, the nonprimes are translated to blanks. In the orange grid below, the primes are left intact, and all nonprimes are changed to blanks. Then, in the final transformation of the Ulam spiral (the yellow grid), translate the primes to a glyph such as a ∙ or some other suitable glyph.
Task For any sized N x N grid, construct and show an Ulam spiral (counterclockwise) of primes starting at some specified initial number (the default would be 1), with some suitably dotty (glyph) representation to indicate primes, and the absence of dots to indicate nonprimes. You should demonstrate the generator by showing at Ulam prime spiral large enough to (almost) fill your terminal screen. See also
