In: Computer Science
Write a program in python programming language to implement/simulate a finite automaton that accepts (only): odd Binary numbers // 00000000, 0101, 111111, etc. Show: Finite Automaton Definition, Graph, Table
Solution(s):
GRAPH and TABLE:
CODE:
def DFA(sigma,start,table,final,s): state = start for i in s: if i in sigma: state = table[state][i] else: state = 'D' if(state in final): return "Accepted" else: return "Rejected" table = {'q0':{'0':'q1','1':'q1'},'q1':{'0':'q1','1':'q1'},'D':{'0':'D','1':'D'}} sigma = ['0','1'] start = 'q0' final = ['q1'] s1 = '00000000' s2 = '0101210' #contains 2 s3 = ' 01 0' #contains space s4 = '01 011' #contains space s5 = '111111111' s6 = '0101010011' s7 = '001True001' s8 = '10/n011' s9 = '1011/t' print("String-->Accepted/Rejected ") print(s1,"-->",DFA(sigma,start,table,final,s1)) print(s2,"-->",DFA(sigma,start,table,final,s2)) print(s3,"-->",DFA(sigma,start,table,final,s3)) print(s4,"-->",DFA(sigma,start,table,final,s4)) print(s5,"-->",DFA(sigma,start,table,final,s5)) print(s6,"-->",DFA(sigma,start,table,final,s6)) print(s7,"-->",DFA(sigma,start,table,final,s7)) print(s8,"-->",DFA(sigma,start,table,final,s8)) print(s9,"-->",DFA(sigma,start,table,final,s9))
OUTPUT: