111 points · by ingve · 10y ago · 60 comments
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.
--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.
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_______ /____\____