Computing primes with CSS
nedbatchelder.com
nedbatchelder.com
https://github.com/SLaks/Silon#implementation-details
"Silon is implemented using LESS to generate CSS selectors for every combination of inputs that will turn each gate on. In effect, I created a LESS-based DSL that expresses (almost-)arbitrary boolean expressions."
It's still cooler than the OP.
Actually, I'm interested in philosophy in general, especially early Wittgenstein & Gödel.
So I'm biased.
--Dr. Ian Malcolm (Jurassic Park)
If you wanted to find the first 100.000 prime numbers, you'd need to add all the prime numbers up to 313 in the css file.
Imho, the code should not grow. So in my view, the article is cheating.
I agree that the title is somewhat misleading - it is (to me) as much a 'computation of prime numbers' as a lookup table would be.
It would just do some things on the fly that the author did with python.
So I'd say it's definitely a valid hack.
By which I mean that looking up values in a table is actually a part of computation. That's pretty much how anything with a trigonometric function works [we've just replaced books with integrated circuits]. Back in the days of using a slide rule, there was a looking it up in a table element as well, it's just that the table was in a flexible form.
Practically, speaking if the easiest way to calculate the first fifty million primes might be: https://primes.utm.edu/lists/small/millions/
Philosophically, I don't have the same feeling querying for some nth prime at https://primes.utm.edu/nthprime/index.php but it's probably doing all its calculations for mundane things like network packets and none of it sieving natural numbers.
But when using lookup tables, I consider the computation of the lookup table a part of the algorithm - after all, a lookup table is essentially an optimization: You extract a sub-computation and store it, paying with space for better time complexity.
1. The only thing that matters about a function 'nth-prime' is that it maps 1->2, 2->3, 3->5 etc.
2. To be useful in practical applications, a function `is-prime` is unlikely to use the sieve of Eratosthenes and more likely to use something like Fermat's Primality Test [1] and hence will be mistaken over Carmichael Numbers and so hard coding the first few into the function via looking might be a good way to do what people expect...though at some point:
Numbers that fool the Fermat test are called Carmichael numbers, and little is known about them other than that they are extremely rare. There are 255 Carmichael numbers below 100,000,000. The smallest few are 561, 1105, 1729, 2465, 2821, and 6601. In testing primality of very large numbers chosen at random, the chance of stumbling upon a value that fools the Fermat test is less than the chance that cosmic radiation will cause the computer to make an error in carrying out a “correct” algorithm. Considering an algorithm to be inadequate for the first reason but not for the second illustrates the difference between mathematics and engineering. Abelson, Sussman, Sussman https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.htm...
So, to be precise, the code does not compute 'primes', the code lists every number that is not devisable by any number from 2 to 32.
This sort of explains how I feel: http://lukeplant.me.uk/blog/posts/less-powerful-languages/
That's why my reactionary instinct to "neat hacks" like this is usually one of revulsion (at the language for making it possible).
The link also mentions a way of doing the same in plain TeX that is taken from Donald Knuth's "The TeXbook".
[0] http://tex.stackexchange.com/questions/134305/how-to-produce...
span:nth-child(2n+4), span:nth-child(3n+6), span:nth-child(5n+10), span:nth-child(7n+14), span:nth-child(11n+22), span:nth-child(13n+26), span:nth-child(17n+34), span:nth-child(19n+38), span:nth-child(23n+46), span:nth-child(29n+58), span:nth-child(31n+62),
But don't take my word for it: http://www.stringtemplate.org/about.html
(Don't pay too much attention to me: I still haven't adopted the .format() method! Heh.)
Very nice project sir!
#####
#### _\_ ________
##=-[.].]| \ \
#( _\ | |------|
# __| | ||||||||
\ _/ | ||||||||
.--'--'-. | | ____ |
/ __ `|__|[o__o]|
_(____nm_______ /____\____