The problem:
Professor Martinez needs a state machine that will recognize certain base-$3$ numbers. It should read the digits in left-to-right order. That is, if you’ve seen number $x$ and read a new digit $d$, your new number is $3x + d$. The machine should be in a final state whenever the number read so far is congruent to $3 \pmod 5$. For efficiency, the state machine must be deterministic. Specifically, if you look at any state $s$ and any action $\text{a}$, there is exactly one edge labelled $\text{a}$ leaving state $s$. Draw a state diagram that will meet his needs, using no more than $7$ states and, if you can, no more than $5$.
I already know the graphical solution to the problem, but I'm having trouble figuring out the logic behind it. How do I know if a base $3$ number is congruent to $3 \pmod 5$? So far, I have the following algorithm:
for every digit k in number n:
if(3k + d == 5k - 2) {
send to final state //is congruent to 3(mod 5)
}
else {
3k = 3k + d //updates the total value k
}
I'm not sure how to implement this in state diagram form, since any given number can have an arbitrarily large number of digits.
3k = 3k + dmean? – Martin Rosenau Aug 28 '18 at 19:18