E N D
0 6 1 2 5 3 4 Division Mod 7 FSM Input is a number (decimal sequence of numerals). Ends up at the state whose name indicates the remainder when the input number is divided by 7. The key intuition is that if a number x has remainder of r when divided by 7, then the remainder of the number obtained by appending numeral n at the end of x must have remainder of 10r + n mod 7. For example, 66 has remainder 3 when divided by 7, so 668 should have remainder 30 + 8 mod 7, or 38 mod 7, or simply 3. (And indeed, 668 = 7 x 95 + 3.) This observation is true because if x mod 7 = r, then x = 7q + r for some quotient q. Then the number obtained by appending the numeral n to the end of x results in multiplying x by 10, and then adding n, is 10x + n = 10(7q+r) + n = 70q + 10r + n, which has remainder of 10r+n mod 7, since the first term is divisible by 7. This observation dictates that from state r (indicating that current remainder is r), the next state on input n should be to state 10r+n mod 7. (The remainder when 10r + n) is divided by 7. These transitions are drawn above.
Division Mod 7 FSM 0 0 1 6 4 5 5 2 3 6 1 4 2 3 1 6 2 5 3 4