Daniel B. answered 02/04/22
PhD in Computer Science with 42 years in Computer Research
I assume that the input is presented starting from the most significant digit.
And I assume $ marking the end of input.
The dfa has the following 7 states with their interpretation:
accept (final state, if entered then the string is divisible by 5)
reject (final state, if entered then the string is not divisible by 5)
s0 (all the digits seen so far represent a number that is 0 mod 5)
s1 (all the digits seen so far represent a number that is 1 mod 5)
s2 (all the digits seen so far represent a number that is 2 mod 5)
s3 (all the digits seen so far represent a number that is 3 mod 5)
s4 (all the digits seen so far represent a number that is 4 mod 5)
The initial state is s0 .
The transitions are:
Input $:
The current state sr means that the number seen so far is r mod 5,
so depending on r, we accept or reject.
s0 -- $ --> accept
s1 -- $ --> reject
s2 -- $ --> reject
s3 -- $ --> reject
s4 -- $ --> reject
Input 0:
The number represented by the digits seen so far is being multiplied by 2.
And therefore so is the remainder.
s0 -- 0 --> s0
s1 -- 0 --> s2
s2 -- 0 --> s4
s3 -- 0 --> s1
s4 -- 0 --> s3
Input 1:
Like input 0, but 1 is being added as well.
s0 -- 1 --> s1
s1 -- 1 --> s3
s2 -- 1 --> s0
s3 -- 1 --> s2
s4 -- 1 --> s4