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?
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.
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.
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.
Well it's definitely possible unless I'm a moron (correct me if I am). If you have the primes up to √n you can find all primes up to n because everything else will be composite of the primes you know already. This is basically what TFA is doing. What I was suggesting is that it would be cool if you could avoid defining rules explicitly for (3n+6), (5n+10), etc and have them appear from some feedback loop where we go from a sequence of primes up to n, to n^2, to n^4...
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.
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.
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.
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.
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)
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?
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.
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?