Checking some Regular Expression problems

78 Views Asked by At

I'm given the alphabet $$ \Sigma = {\{a,b}\} $$ I tried to write a regular expressions for presenting the following sets:

All strings in $$\Sigma ^ *$$ with:

a-) number of 2s divisible by 4

b-) exactly one occurrence of 122

c-) exactly one or two 1s

Well I tried to find their solutions, but I am afraid they might be incomplete. So it goes like:

$$ (1^*(22)^*1^*)^* $$ $$ 2^*1222^* $$ $$ 2^*(1 | 11)2^* $$

respectively for a, b and c parts.

1

There are 1 best solutions below

0
On BEST ANSWER

a). Words with number of $2$s divisible by 4 are words made of subwords that contain exactly 4 $2$s with arbitrary number of $1$s between them.

$$(1^*21^*21^*21^*21^*)^*$$

b). Note that $(21^*+11(1+2)+121)^*$ is the complementary of $122$. $$(21^*+11(1+2)+121)^*122(21^*+11(1+2)+121)^*$$

c). In a similar concept as in case (a), $$2^*12^*+2^*12^*12^*$$