4 ms·
You can make a division regex for arbitrary numbers. Turn the number into unary, then see if it matches the divisor (also in unary) repeated N times with no ch
by Natsu 16y ago
You can make a division regex for arbitrary numbers. Turn the number into unary, then see if it matches the divisor (also in unary) repeated N times with no characters left over.
I know someone posted something like that to HN a while ago.
- eru 16y agoYes, but how do you convert from decimal to unary in a regular expression?
- Natsu 16y agoIn Perl, you can use /e which is probably cheating as far as some are concerned. You could also probably do it by repeatedly applying a fairly complex regex that would continually decrement by 1.
- eru 16y agoOh, I was talking about regular expressions in terms of (http://en.wikipedia.org/wiki/Regular_expression#Formal_language_theory http://en.wikipedia.org/wiki/Regular_expression#Formal_langu...). You can't do decrementing in this sense.
- Natsu 16y agoAt least for Perl folks, 'regex' acts as disambiguation, informing people that they're talking about expressions that aren't truly "regular" in the sense you're talking about. But I guess that not everyone uses the term that way.