-2

I am trying to solve a problem set to practice for an exam. How can I approach questions like these ? Is there a way to verify solutions or is it just trial and error ?

Ash Rivers
  • 121
  • 4
  • What's your question – BattleCalls Feb 24 '22 at 14:33
  • I am trying to find the regex that represents " All binary numbers greater than 110011" – Ash Rivers Feb 24 '22 at 14:34
  • SO is a site for *programming* questions, so you are going to get answers about programming from programmers, most of whom have experience with regex libraries. I think you are looking for an answer related to mathematical regular expressions, so the typical responses you will get here might not be that useful to you. Consider asking in [math.se] or [cs.se] but make sure to read the help pages on each site about appropriate questions. – rici Feb 24 '22 at 14:56

1 Answers1

0

This one seems quite simple: the string has to be one of:

  • 1 followed by at least six more characters.
  • 111 followed by at least (or exactly) three characters
  • 1111 followed by at least (or exactly) two characters.

If the input can start with leading 0s, change all the leading "1"s to "0*1". In any case, it can be factored out.

The answer to your question, "is there a simple algorithm which can do that for me?" is probably "no". But the above is more simple logic than trial-and-error. Writing down random regular expressions until you find one which works is not a good way to solve the problem, given the difficulty of algorithmically proving correctness.

rici
  • 234,347
  • 28
  • 237
  • 341