POSIX reg. exp to test the divisibility by 9

-1

Write the shortest POSIX-form regular expression that matches only non-negative integers divisible by 9. The non-negative integer should be given in base 10.

selfstudying

Posted 2014-03-06T20:04:18.953

Reputation: 7

Is this too similar to the regex challenge to check divisibility by 7? I am inclined to think yes, but I am not going to flag it. – Tim Seguine – 2014-03-06T20:15:37.983

3

You can do it just like you do for 3. 9 has a similar rule; any integer divisible by 9 has digits summing to another multiple of 9. It makes the state machine more complex, but the same principle applies.

– Geobits – 2014-03-06T20:28:19.287

Are there a free Linux program to make the conversion from finite state machine to reg. exp.? – selfstudying – 2014-03-06T20:45:00.047

1this seem to be a bit code-bowling... – V-X – 2014-03-06T22:56:56.577

Answers

1

202,071 bytes

Obviously, the solution is too large to be included in this post.

I use JFLAP to draw the DFA, then generate regex from it. The output is then processed in a text editor to replace (0+9) with [09] and + with |.

Here is the whole gist, with some testing code in Java.

n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳

Posted 2014-03-06T20:04:18.953

Reputation: 5 683