Skip to content(if available)orjump to list(if available)

Show HN: Prime Number Grid Visualizer

Show HN: Prime Number Grid Visualizer

14 comments

·August 13, 2025

Hello HN. I made this simple little tool that let's you input rows and columns to create a grid, then it plots the grid with prime numbers.

I made it for fun, but I'd love suggestions on how I can improve it in any way. Thanks, love you.

kawfey

I spammed the columns from 1 to 402 (with 400 rows), and i saw some cool patterns. I can see a few nodes of clockwise rotation that converges into a single node from >200 columns that starts makes its way down the screen. Trippy.

I made a screen recording of it: https://n0ssc.com/wp-content/uploads/2025/08/prime-doublespe...

jasonjmcghee

I did the same thing - but you can just put your cursor in the number box and hold up / down arrow key.

lurn_mor

Very! I saw the distant galaxies spin.

artemonster

I did the same thing and saw galaxies

brandonasuncion

Reminds me of a really cool coding trick to get a "random" permutation of an array in O(1) time/memory.

https://lemire.me/blog/2017/09/18/visiting-all-values-in-an-...

eps

Ha, super, thanks for making it.

Check out 431 columns - this yields no obvious persistent patterns.

smusamashah

Add option to skip all even numbers, another to skip all numbers ending with 5. Also, a way to see the number when you click a pixel or space.

It's fun seeing all these patterns. I did some edit. I was thinking that skipping over numbers divisible by 2 and 5 will get rid of most visible gaps, but they keep emerging.

navane

I'm probably an idiot but having the columns at a multiple of 6 is very pleasing

AnotherGoodName

The reason behind that is similar to how all prime numbers above 2 are of the form 2n+1 since all other numbers are divisible by 2. Eg. all prime numbers >2 are odd.

In this case you're seeing the extension of this to include multiples of 3. That is, all prime numbers above 6 are of the form 6n+1 or 6n+5, all other numbers are either divisible by 2 or 3.

You can extend these patterns. Whenever you have a composite number you'll get periodic points where factors are known. Eg. to extend it one step further you could say all prime numbers above 30 are of the form 30n + [1,7,11,13,17,19,23,29], all others are divisible by 2, 3 or 5.

From this you can also quickly iterate towards to the prime number formula for the frequency of primes. eg. Only half of numbers above 2 can be prime (1/2), the rest are multiples of 2. Over 6 you have half of two thirds of numbers that can possibly be prime, the rest are multiples of 2 or 3. Over 30 only 1/2 x 2/3 x 4/5 could possibly be prime. etc. This converges to the prime number theorem!

Anyway if anyone ever expresses amazement that's good to see but mathematically it's well known. Prime numbers have patterns in their frequency, specifically where there's period multiples of factors there can't possibly be primes. It's the basis for prime number theory and patterns in primes have been known since Erasthosenes was back in BC times. So if you see a pattern here just remember that the pattern comes from looking at a period of a composite number and within that composite number there's guaranteed periodic gaps in primes where the factors of that number repeat.

This btw is something mathematicians deal with a lot. People seem to think prime numbers have no patterns and any view of them that reveals patterns is a surprising which is a weird misconception. Prime numbers absolutely have patterns. It's the basis for prime number theory.

susam

A prime number greater than 3 must leave a remainder 1 or 5 when divided by 6. In other words:

If n is prime and n > 3, then n ≡ 1 (mod 6) or n ≡ 5 (mod 6).

Or more succinctly:

n ≡ ±1 (mod 6).

So when the total number of columns is a multiple of 6, all the primes greater than 3 line up on the nth columns for n = 1, 5, 7, 11, etc.

wordglyph

So cool! I'd like to be able to start at any number

dduplex

Thanks! Do you mean you’d like to be able to input any number you like?

The numbered values are editable inputs. You can click into them and type in the amount you’d like. If you couldn’t tell they were editable inputs, that’s valuable feedback! I’ll redesign them to make it more obvious that you can do so, and don’t have to just click the +/- buttons.

Cieric

I think they mean that the number that the image starts on is by default 0, I think they want to be able to change the starting number so top left could start at something else and increment from there. Adding on to that it would also be interesting to change what the number increments by.

hobo_in_library

The density of prime numbers remains remarkably consistent as you increase the grid size. Even the end of a 10,000 x 10,000 grid had just as many primes per inch as the earlier numbers