Highlighting prime numbers with CSS
github.com
github.com
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?
CSS4, let's do it.
[0]: https://en.wikipedia.org/wiki/Primitive_recursive_function#C...
Rule110 (After setting first row requires alternation of tab/space to run): https://codepen.io/elrumordelaluz/pen/wqLyH?editors=010
stackoverflow discussion: https://stackoverflow.com/questions/2497146/is-css-turing-co...
[1]https://en.wikipedia.org/wiki/AKS_primality_test
[2]https://en.wikipedia.org/wiki/Elliptic_curve_primality_provi...
[3]https://en.wikipedia.org/wiki/Adleman%E2%80%93Pomerance%E2%8...
You can replace
li:first-child,
li:nth-child(2n + 4),
li:nth-child(3n + 6),
li:nth-child(5n + 10),
li:nth-child(7n + 14) {
color: grey;
counter-increment: nature-count nonprime-count;
}
with li:first-child,
li:nth-child(2n + 4),
li:nth-child(3n + 6),
li:nth-child(4n + 8),
li:nth-child(5n + 10),
li:nth-child(6n + 12),
li:nth-child(7n + 14)
li:nth-child(8n + 16)
li:nth-child(9n + 18)
li:nth-child(10n + 20) {
color: grey;
counter-increment: nature-count nonprime-count;
}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.
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?
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.
Primes will only appear in columns whose index is coprime with 12. That's because 12n+2 is divisible by 2. 12n+3 by 3, etc for 12n+4, 12n+6, 12n+8, 12n+9, 12n+10. (For n>0. that's why there are primes on the first line)
12 factors into 2, 2 and 3. If a column is index 2n or 3n it will never contain a prime after the first row. The columns that match that here are: 2, 3, 4, 6, 8, 10, 12. The columns that don't are 1, 5, 7, 11 - your four.