Regular expression of length n divisible by 2 or 3

2.6k Views Asked by At

I have an alphabet $\sum=\{o,g\}$ and I need to write a regular expression for arbitrary sequences of length $n$ where $n$ is divisible by 2 or 3.

My guess would be [og][og]* | [og][og][og]*, but I am not certain if this is correct or incorrect.

1

There are 1 best solutions below

0
On

Your guess is almost correct, but you should change $[og]$ to $\{o,g\}$. You could also write it as $(\Sigma^2)^* \cup (\Sigma^3)^*$.