4 ms·
I find this to be an interesting side effect of computer science as a branch of mathematics vs applied computer science in "programming" and "development". I r
by Fripplebubby 8y ago
I find this to be an interesting side effect of computer science as a branch of mathematics vs applied computer science in "programming" and "development".
I remember touring the computer science building at the university I would end up attending before I had enrolled there - some students in one room were discussing whether there was a regular expression for detecting prime numbers. I laughed to myself - because in my mind, that's not at all what a regular expression was.
Sure enough, there is in fact such a regular expression (or "regex pattern", if you prefer)[1]. Regular expressions in practice encompass BOTH the academic level-3 regular grammar stuff, and a bunch of other stuff that's been tacked on because it's useful in real-world applications.
[1] - This has been posted on HN before, probably a bunch of times: https://iluxonchik.github.io/regular-expression-check-if-number-is-prime/ https://iluxonchik.github.io/regular-expression-check-if-num...
- bsdetector 8y agoThis regex doesn't tell whether a number is prime, it tells whether the length of a specially crafted string is prime. Kind of a big difference as you can make a regex that answers any yes/no question if you preprocess the input enough.
- Fripplebubby 8y agoWell, saying that a number presented as unary isn't a number, to me, is the same as saying that a number presented as decimal isn't a number. But you're right that it is "specially crafted" rather than a general solution.