0

Finite state machine that accepts if sum of digits divisible by 3 .

enter image description here

I am trying to construct a finite state machine the accepts if the sum of digits is divisible by n. So far I was able to do for n=2 and n=3 but dint find any generalized steps that I could follow. Any help is appreciated.

Am_I_Helpful
  • 18,735
  • 7
  • 49
  • 73

2 Answers2

0

This question is a little vague but it seems like you are trying to accept a stream of numbers if they are divisible by n.

If this is the case I would suggest you gathering input, separating by digit, summing the digits and using a mod. Some clarification would help my answer though.

0

It seems like your alphabet is ternary and that it consists of 0, 1, and 2. For any n, you must have an n-state machine with each state representing the remainder when dividing by n. The transition for any x equal to 0, 1, or 2 from state z will go to state (z+x)%n where "%" represents the remainder operator.

SwiftMatt
  • 949
  • 1
  • 9
  • 19