0

I have a task and I really have no idea how to solve it.

Build deterministic finite automata such that it can detect numbers divisible by $7$.

So our alphabet is $\left\{0,1,2,3,4,5,6,7,8,9\right\}$

Our input is for example: $700$ - out automata should detect it.

Could you help me?

iadvd
  • 8,961
  • 11
  • 39
  • 75
  • 6
    Very relevant: http://math.stackexchange.com/questions/413296/how-does-the-divisibility-graphs-work – MJD Mar 03 '15 at 15:12
  • 1
    It's solved here; I wouldn't use the regex directly, but Griffin's diagram should be helpful. http://codegolf.stackexchange.com/q/3503/2605 – Charles Mar 03 '15 at 15:16
  • Ok I understand it. What about situation when digits of number are inserted to automat in reverse order ? For example $49$ - our automat should accept it. But let's assume that it is in reverse order - $94$ - How to construct automat ? – user220688 Mar 03 '15 at 23:14

1 Answers1

1

Hint:

If input string is in reverse order, you had better make use of the following property: $$n^{\phi(m)}\equiv 1\pmod{m}, \quad \mathrm{if}\ (m,n)=1,$$ where $\phi(m)$ stands for the Euler's totient function.

In this specific case, $(10,7)=1$. Let the nodes of your DFA represent 2-tuples of current positions (mod $\phi(7)$ of course) and residue classes (mod $10$).

More:

In a general sense, it is easier to build a NFA that reads numbers from the most insignificant digit, since the base $n$ (in this case, $10$) and the divisor $m$ (in this case, $7$) do not necessarily coprime.