frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Prime Number Grid

https://susam.net/primegrid.html
110•todsacerdoti•2h ago

Comments

susam•2h ago
Hello! I wrote this simple prime number grid visualiser last night, just for fun. It is inspired by the "Show HN" post https://news.ycombinator.com/item?id=44888548 that I stumbled upon a few days ago.

My tool uses the Miller-Rabin primality test with prime bases drawn from https://oeis.org/A014233 to determine whether a number is prime. This allows it to handle numbers up to 3317044064679887385961980.

For example, https://susam.net/primegrid.html#3317044064679887385961781-2... shows the upper limit of the numbers this tool can check. The three circles displayed there represent the following prime numbers:

  3317044064679887385961783
  3317044064679887385961801
  3317044064679887385961813
I hope this is fun for you too!
camillomiller•2h ago
It's so cool actually!

You actually sent me on a rabbit hole trying to visually look for patterns :D But I guess the discretionality with which you can organize in rows and columns makes mine quite a pointless excercise :D

jona-f•2h ago
If you select 30, 60 or 90 columns you get the clearest patterns. It kinda seems that the more divisors the number of columns has, the clearer the vertical clusters are. And somehow 30, 60 and 90 stand out. Number theory is so weird. I expected more randomness.
susam•2h ago
The reason vertical clusters appear in these examples is that all your chosen numbers are multiples of 6. A prime number greater than 3 leaves a remainder of either 1 or 5 when divided by 6. In other words:

For all primes p greater than 3, p ≡ ±1 (mod 6).

Therefore, when the total number of columns is a multiple of 6, all primes except 2 fall into the same columns, namely 1, 5, 7, 11, 13, 17 and so on.

jacobtomlinson•1h ago
I just set the column width to 6 to verify this for myself. What a neat tool!
ainiriand•1h ago
Go for 258 and be ready to get your mind blown.
Daub•54m ago
Very cool. Go from 30 to 31 to see this ‘pattern’ twist in on itself.
Tepix•1h ago
Great visualization! Can you please add a on-mouse-over so when i hover my mouse over a dot i can see the prime number it represents?

Would we see new patterns emerge if the number of columns increases per row by X (X being constant or perhaps prime numbers ;-) )?

susam•52m ago
Adding mouseover text to every prime number slows down rendering on large grids (say, with a million or more numbers). So mouseover text is available as an optional feature. You can toggle it using the 't' button at the top: click once to enable the text, and click again to disable it.
Tepix•17m ago
Thanks, that was fast!

Here's an idea on how to implement it without the slowdown: https://jsfiddle.net/qpswztj8/

Given that it's a preformatted text with a known number of columns, the number below the mouse pointer can be computed using the mouse position, character width and line height.

davedx•41m ago
I think another interesting feature would be if you could change the number base to 16 or some other base, I'm really curious if the pattern would change.
lblume•40m ago
Numbers are prime irrespective of base.
xandrius•28m ago
So it's already supported!
rmrfchik•2h ago
Nice patterns are reveals when cols is prime.
ethan_smith•2h ago
This happens because when columns = p (prime), numbers in each column share the same remainder mod p, creating visible diagonal patterns as multiples of p are eliminated from primality.
scotty79•1h ago
Almost all of these patterns that you see don't really come from primes. If you display numbers not divisible by first 100 natural numbers you get pretty much the same picture.
agnishom•2h ago
Since this is in a grid, how about visualizing Gaussian primes instead?
throw310822•2h ago
Kind of surprising, my intuitive idea of primes is that they become rarer much faster, while there's really a ton of them.
susam•2h ago
They indeed do become rarer. Plotting all the primes in a single row makes this apparent, like so: https://susam.net/primegrid.html#1-1-1000000

In fact, according to the celebrated prime number theorem, the number of primes less than or equal to n is asymptotic to n/log n, which means the density of primes near n is asymptotic to 1/log n.

I have a small section about this at https://susam.net/journey-to-prime-number-theorem.html#prime... if you want to read more about this.

See also: https://en.wikipedia.org/wiki/Prime_number_theorem

eru•1h ago
Yes.

> In fact, according to the celebrated prime number theorem, the number of primes less than or equal to n is asymptotic to n/log n, which means the density of primes near n is asymptotic to 1/log n.

When written down as a string of digits, log n is another way to say 'proportional to the number of digits'.

The number of digits grows fairly slowly, thus also the 'probability' of a number being prime drops very slowly.

kristopolous•2h ago
This is a very well researched topic

https://en.m.wikipedia.org/wiki/Prime_number_theorem

Someone•2h ago
That’s what ‘everybody’ thinks. I think that’s from reading so much about them being hard to find. They aren’t hard to find, though, it’s (as far as we know) hard to recognize integers as being primes.

There are more prime numbers than there are squares of integers.

eru•1h ago
> They aren’t hard to find, though, it’s (as far as we know) hard to recognize integers as being primes.

Depends on what you mean by 'hard'. It's easy in the sense that we have algorithms to decide whether a number is prime or composite that take time polynomial in the space it takes to write down your number (ie polynomial in log n).

throw310822•1h ago
> I think that’s from reading so much about them being hard to find

More from the fact that each prime number makes all its multiples non-prime, so you'd expect this would accumulate quickly in making primes an increasingly rare find. Which is the case, but slower than intuition suggests.

mickeyp•2h ago
I really love susam's blog posts and curiosity. I highly recommend that people check out his site for more of his insights.
nyc111•56m ago
I tried but his pages do not have links to a home page or other posts
genezeta•32m ago
There's this https://susam.net/pages.html for your convenience. (Also this https://susam.net/links.html maybe a bit more organised.)
vim-guru•1h ago
This works surprisingly well for logo design. Cool concept
martinclayton•1h ago
Hours of fun (stimulation?) to be had...

Try these shapes: 100x113, then 100x114, then 100x115, the "patterns" swing from slant down, to vertical, to slant up.

I'd love this (even more) with some animation and colo(u)r options.

susam•1h ago
This was just a quick experiment I put together last night in my free time, so the tool is quite bare bones. If you're on a desktop browser and don't mind opening the developer tools console, you can run this little snippet to animate the grid:

  cols.value = 1n; setInterval(() => {cols.value++; readInput()}, 250);
quijoteuniv•1h ago
Wow! I see the pattern now! ;) … nice work
kitd•1h ago
Really interesting, stepping up and down the "cols" number, seeing the dots align at certain key points, especially at multiples of 30.
krige•1h ago
There's also a cool effect where incrementing columns by one has the dots align diagonally, and then vertically multiple times.
dev0p•1h ago
Editable size pls? I wonder if this could be visualized in 3 dimensions...
vintermann•1h ago
Fun to see that prime numbers of columns causes stripy patterns, and some stripe to the left and some stripe to the right. Probably some deep number theoretic reason for that.
fendy3002•1h ago
it's interesting that for 6 cols only the 1st and 5th column has value, ignoring first row.
anthk•47m ago
I'd love this but in SDL+GL allowing to scale up and down an image. Or better, a command to write an XBM/XPM image and then I'd convert it to any format I like.
wmanley•20m ago
Scaling is already supported - try Ctrl+Mouse Wheel or pinch to zoom on mobile. It also supports writing an image with the keyboard shortcut "Print Screen".
willvarfar•22m ago
Perhaps explore plotting the Ulam spiral too? https://en.wikipedia.org/wiki/Ulam_spiral

Of course the pressing question is, if this is the start field for a Conway game-of-life, do any interesting patterns evolve?

It would be fun to brute-force a few starting grid sizes and seeing how long the game continues. Games that last more than a few steps can be set aside for human evaluation.

Because if it turns out that some particular smallish grid or spiral of primes causes something interesting to happen in game-of-life, then you can imagine HN melting down!?

cuber_messenger•20m ago
Decreasing the number of columns looks like rotating some noisy parallel lines counterclockwise. Very fun.
courtcircuits•3m ago
Gonna make API calls to that next time I need to generate an Elgamal key pair
dirkc•3m ago
Nice visualization! 2 suggestions if I can nitpick :)

1. Make the grid render as a square when rows == columns 2. Default to the largest number of rows and columns that would still avoid page scrolling

Prime Number Grid

https://susam.net/primegrid.html
113•todsacerdoti•2h ago•42 comments

Lazy-brush – smooth drawing with mouse or finger

https://lazybrush.dulnan.net
240•tvdvd•3d ago•35 comments

OpenMower – An open source lawn mower

https://github.com/ClemensElflein/OpenMower
324•rickcarlino•9h ago•75 comments

How to Build a Medieval Castle

https://archaeology.org/issues/september-october-2025/features/how-to-build-a-medieval-castle/
67•benbreen•5h ago•8 comments

Netflix Revamps Tudum's CQRS Architecture with Raw Hollow In-Memory Object Store

https://www.infoq.com/news/2025/08/netflix-tudum-cqrs-raw-hollow/
29•NomDePlum•2d ago•18 comments

X-ray scans reveal Buddhist prayers inside tiny Tibetan scrolls

https://www.popsci.com/technology/tibetan-prayer-scroll-scans/
125•Hooke•2d ago•35 comments

Tiny-tpu: A minimal tensor processing unit (TPU), inspired by Google's TPU

https://github.com/tiny-tpu-v2/tiny-tpu
196•admp•13h ago•6 comments

Show HN: Whispering – Open-source, local-first dictation you can trust

https://github.com/epicenter-so/epicenter/tree/main/apps/whispering
405•braden-w•17h ago•118 comments

Counter-Strike: A billion-dollar game built in a dorm room

https://www.nytimes.com/2025/08/18/arts/counter-strike-half-life-minh-le.html
367•asnyder•19h ago•300 comments

Ted Chiang: The Secret Third Thing

https://linch.substack.com/p/ted-chiang-review
128•pseudolus•10h ago•57 comments

Obsidian Bases

https://help.obsidian.md/bases
534•twapi•13h ago•160 comments

Show HN: I built an app to block Shorts and Reels

https://scrollguard.app/
588•adrianhacar•2d ago•237 comments

Left to Right Programming

https://graic.net/p/left-to-right-programming
330•graic•17h ago•268 comments

How to Use Snprintf

https://bernsteinbear.com/blog/snprintf/
10•surprisetalk•2d ago•2 comments

FFmpeg Assembly Language Lessons

https://github.com/FFmpeg/asm-lessons
371•flykespice•20h ago•123 comments

Walkie-Textie Wireless Communicator

http://www.technoblogy.com/show?2AON
154•chrisjj•2d ago•96 comments

The Life and Death of London's Crystal Palace (2021)

https://heritagecalling.com/2021/11/29/picturing-the-crystal-palace/
10•zeristor•4d ago•4 comments

Show HN: We started building an AI dev tool but it turned into a Sims-style game

https://www.youtube.com/watch?v=sRPnX_f2V_c
126•maxraven•15h ago•61 comments

Croatian freediver held breath for 29 minutes

https://divernet.com/scuba-news/freediving/how-croatian-freediver-held-breath-for-29-minutes/
223•toomanyrichies•10h ago•95 comments

An IRC-Enabled Lawn Mower (2021)

https://jotunheimr.idlerpg.net/users/jotun/lawnmower/
94•rickcarlino•2d ago•19 comments

Electromechanical reshaping, an alternative to laser eye surgery

https://medicalxpress.com/news/2025-08-alternative-lasik-lasers.html
252•Gaishan•1d ago•108 comments

Anna's Archive: An Update from the Team

https://annas-archive.org/blog/an-update-from-the-team.html
944•jerheinze•18h ago•444 comments

Newgrounds: Flash Forward 2025

https://www.newgrounds.com/bbs/topic/1542140
79•lsferreira42•12h ago•26 comments

Association for the Preservation of Spiritualist and Occult Periodicals

https://iapsop.com
34•andrii•3d ago•4 comments

The rising returns to R&D: Ideas are not getting harder to find

https://papers.ssrn.com/sol3/papers.cfm?abstract_id=5242171
104•surprisetalk•4d ago•37 comments

Launch HN: Reality Defender (YC W22) – API for Deepfake and GenAI Detection

https://www.realitydefender.com/platform/api
82•bpcrd•19h ago•41 comments

Shamelessness as a strategy (2019)

https://nadia.xyz/shameless
185•wdaher•12h ago•104 comments

Show HN: I built a toy TPU that can do inference and training on the XOR problem

https://www.tinytpu.com
106•evxxan•14h ago•19 comments

A general Fortran code for solutions of problems in space mechanics [pdf]

https://jonathanadams.pro/blog-articles/Nasa-Fortran-Code-1963.pdf
49•keepamovin•10h ago•23 comments

Spice Data (YC S19) Is Hiring a Product Associate (New Grad)

https://www.ycombinator.com/companies/spice-data/jobs/RJz1peY-product-associate-new-grad
1•richard_pepper•13h ago