
Highlighting prime numbers with CSS - mholt
https://github.com/xieranmaya/blog/issues/12
======
ecma
The highlighting and counting is cool but isn't this just colouring prime
numbered elements (off by one) by knowing the primes up to √n? Bit of a
circular problem! (:

It'd be pretty cool if CSS could define new rules based on counters and
calculated properties. Then you might be able to bootstrap from something
small like "2 is prime" and discover the rest of the primes up to n. Is this
sort of wizardry possible?

~~~
burnte
I would doubt it's possible, considering the methods that we use to detect
primes come down to brute force. It's hard to build an algorithm when we don't
have a formal proof of how primes work/can be detected.

~~~
nimih
Modern prime testing is quite far from brute force. Tests such as AKS[1],
ECPP[2], and APR[3] can determine whether a number is prime in polynomial time
(in the number of bits/digits), whereas a true brute force search would be
exponential.

[1][https://en.wikipedia.org/wiki/AKS_primality_test](https://en.wikipedia.org/wiki/AKS_primality_test)

[2][https://en.wikipedia.org/wiki/Elliptic_curve_primality_provi...](https://en.wikipedia.org/wiki/Elliptic_curve_primality_proving)

[3][https://en.wikipedia.org/wiki/Adleman%E2%80%93Pomerance%E2%8...](https://en.wikipedia.org/wiki/Adleman%E2%80%93Pomerance%E2%80%93Rumely_primality_test)

~~~
burnte
You're right, I misspoke I should have been more precise and said that out way
of finding primes isn't based on a specific theorem or algorithm in that we
still have to take a number and demonstrate its primeness.

------
gvx
So this is something I found interesting:

The number of rules is listed in the TFA as O(sqrt(n)/log(sqrt(n)), which is
the same as O(sqrt(n)/log(n)), and slightly better than O(sqrt(n)), which is
the number of rules needed if you have rules for the composites as well. That
means that in this case, the constant factor is much more important than the
complexity, in terms of how many rules we need.

------
tannhaeuser
nth-child()/nth-type-of() coupled with CSS variables and calc() plus some
other CSS ingredient yet to be found should result in Turing completeness soon
enough. Looking forward to 100% pure CSS sites in 2020.

------
libeclipse
> [https://user-
> images.githubusercontent.com/2993947/28248599-d...](https://user-
> images.githubusercontent.com/2993947/28248599-d34bd822-6a79-11e7-8c63-4085d08dbfc2.png)

I see a pattern in this image. There are twelve columns, and most of the
primes seem to occur in 4 of them.

What's the name of this?

~~~
jonreem
In base 12 those are just the columns for 1, 5, 7, and 11, the only numbers
between 1 and 12 that aren't divisible by any of 12s factors. If you do this
for any base the prime numbers will fall in columns like those.

Note that there aren't any prime numbers ending in 2 or 5 in base 10 (except 2
and 5), in base 12 it would be the same for numbers ending in 2, 3, 4, 6, 8, 9
and 10.

------
pbhjpbhj
I don't quite understand the reason to use Xn+2X, don't we just need a Sieve
of Erastothenes (sp?): change the color of all multiples leaving all primes in
the base colour?

~~~
maaaats
That's what it does, but the counting starts from zero. So if we select 7 as a
prime we get 7n. For n=0,1,2 we get 0,7,14, of which only 14 is the one we
want to remove.

------
maaaats
The highlighting I have seen before (maybe in some other form). But the
counting used features of CSS new to me, very interesting.

