HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Regular expression for words containing single 1 and even number of 0s

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
expressioncontainingnumberwordsregularsingleforandeven

Problem

What would be a regular expression for the language of words containing a single 1 and an even number of 0s?

Solution

If a word contains exactly one 1 and an even number of zeroes, then we can decompose it in one of two different ways:

  • An even number of 0s, followed by 1, followed by an even number of 0s.



  • An odd number of 0s, followed by 1, followed by an odd number of 0s.



You take it from here.

Context

StackExchange Computer Science Q#101603, answer score: 3

Revisions (0)

No revisions yet.