This JavaScript library provides two functions for operating with the values of a zero-indexed Ulam Spiral:
import getLatticeCoordinatesFor from 'zero-indexed-ulam-spiral/getLatticeCoordinatesFor'
console.log(getLatticeCoordinatesFor(31))
// > [2, 3]
import getSpiralIndexForCoordinates from 'zero-indexed-ulam-spiral/getSpiralIndexForCoordinates'
console.log(getSpiralIndexForCoordinates([5, 6]))
// > 133
Zero indexing is the most popular convention for indexes in programming. Either way, it’s really easy to transform.
This library is about operating with the pairing function from the lattice to the spiral and back. If you want to plot primes on top of it, it should be simple enough.
And yes, the diagonal stripe prime patterns always appear, no matter what the starting value is :)
yarn add zero-indexed-ulam-spiral
MIT