Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# Usage: # python 3 dfa.py 0 1 1 0 0 1 0 # Write a dimulator of a deterministic finite automata import numpy as

# Usage:
# python3 dfa.py 0110010
# Write a dimulator of a deterministic finite automata
import numpy as np
import sys
alphabet =['0','1']
states =['q','r']
accepting_states ={'q'}
transition = np.empty((len(states),len(alphabet)), dtype='U1')
transition[states.index('q'),alphabet.index('0')]='r'
transition[states.index('q'),alphabet.index('1')]='q'
transition[states.index('r'),alphabet.index('0')]='q'
transition[states.index('r'),alphabet.index('1')]='r'
def DFA(input):
current_state = states[0]
for symbol in input:
current_state = transition[states.index(current_state),alphabet.index(symbol)]
return current_state
def main():
input_string = input()
final_state = DFA(input_string)
if final_state in accepting_states:
print("Accept")
else:
print("Reject")
if __name__=="__main__":
main()
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 15th International Conference Dexa 2004 Zaragoza Spain August 30 September 3 2004 Proceedings Lncs 3180

Authors: Fernando Galindo ,Makoto Takizawa ,Roland Traunmuller

2004th Edition

3540229361, 978-3540229360

More Books

Students also viewed these Databases questions