I am trying to construct a regular grammar for the following language:
$$L = \{ w \ | \ (na(w) - nb(w))\mod3!= 1 \}.$$
I'm struggling to understand what it is this language produces, and thus struggling to create a grammar for it.
We want a combination of $a$'s and $b$'s such that the difference of the two, $\mod 3$ is not equal to $1$. We know that $1, 4, 7, 10, 13,\dots, \mod 3 = 1$. With that being said, some valid strings would consist of:
- the same amount of $a$'s and $b$'s // $0 \mod 3 = 0$,
- three $a$'s for every 1 $b$ // $3-1 = 2 \mod 3 = 2$.
So I've started with this, but I'm lost on how to include the same amount of $a$'s and $b$'s.
$S \rightarrow aaabS \ | \ \lambda \hspace{1cm}$ (this takes care of the empty string)