4 ms·
That's too optimistic. Here's a challenge for you: write a (grep) regular expression that checks a decimal number for divisibility by 7. That's totally a regu
by eru 11y ago
That's too optimistic. Here's a challenge for you: write a (grep) regular expression that checks a decimal number for divisibility by 7.
That's totally a regular language, but I doubt you'll find a legible way to express it.
- hacker_9 11y agoWhat does that have to do with the language syntax..
- TeMPOraL 11y agoRegexes we use are an extended form of so-called "regular expressions", which describe regular languages and finite automata, and in that part of maths, a language that accepts binary numbers divisible by N is a very common toy problem.
- 3dfan 11y agoIf the number N can be converted to a string of length N, this regex checks if it's divisible by 7: ^(.......)+$
- meric 11y agoThat would work, use base 1 representation.
- eru 11y agoThat's not a solution. I asked for a something that checks decimal numbers. A real solution looks uglier: check out https://github.com/matthiasgoergens/Div7 https://github.com/matthiasgoergens/Div7, it starts ((((((6(2|9)8|6(2|9)1|5)(5(2|9)8|5(2|9)1|4)(5(2|9)7 [...] (Unless you can convert from decimal to unary in regex, too. I doubt you can, regular languages are too weak for that.)
- agumonkey 11y agoObligatory prime regex link: http://www.catonmat.net/blog/perl-regex-that-matches-prime-numbers/ http://www.catonmat.net/blog/perl-regex-that-matches-prime-n...
- eru 11y agoThat's not a regular language, like the grandfather comment by wonnage talked about.