Question

In: Computer Science

Write a program in python programming language to implement/simulate a finite automaton that accepts (only): odd...

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

Solutions

Expert Solution

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:


Related Solutions

Write a program in python language, which accepts 2 numbers and a + sign (for addition)...
Write a program in python language, which accepts 2 numbers and a + sign (for addition) A sign - (for subtraction) A sign * (for multiplication), / (for division) Then calculate and to display the result of the operation he chose with the two numbers. Displaying the appropriate message
Use MARS to write and simulate a MIPS assembly language program to implement the strlen function....
Use MARS to write and simulate a MIPS assembly language program to implement the strlen function. The program should ask for a user's input and print the length of the user's input. Write the main function to call strlen. The main function should: - Prompt the user for input - Pass that input to strlen using registers $a0. - Preserve (i.e. push onto the stack) any T registers that the main function uses. The strlen function should: - Preserve any...
DFA Python DFA simulator A deterministic finite automaton (DFA) - also known as deterministic finite state...
DFA Python DFA simulator A deterministic finite automaton (DFA) - also known as deterministic finite state machine - is a finite state machine that accepts/rejects finite strings of symbols and only produces a unique computation (or run) of the automaton for each input string. Write a DFA simulator using the python programming language. Read your DFA from a textfile. First line contains a list of the final states (as integers), separated by a space. Rest of file contains the transitions...
Description: In this assignment, you will implement a deterministic finite automata (DFA) using C++ programming language...
Description: In this assignment, you will implement a deterministic finite automata (DFA) using C++ programming language to extract all matching patterns (substrings) from a given input DNA sequence string. The alphabet for generating DNA sequences is {A, T, G, C}. Write a regular expression that represents all DNA strings that begin with ‘A’ and end with ‘T’. Note: assume empty string is not a valid string. Design a deterministic finite automaton to recognize the regular expression. Write a program which...
Create a Deterministic finite automaton that takes in binary strings and accepts them which has both...
Create a Deterministic finite automaton that takes in binary strings and accepts them which has both an odd number of zeros and a sum that is divisible by 3 (but no others). For example, 0111 should be accepted, but not 011 or 111.
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that...
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that sorts the array below in ascending order.  LISP is a recursive language so the program will use recursion to sort. Since there will be no loops, you will not need the variables i, j, and temp, but still use the variable name array for the array to be sorted.             Array to be sorted is 34, 56, 4, 10, 77, 51, 93, 30, 5, 52 The...
Programming Assignment No. 5 Write a program that asks the user to enter a positive odd...
Programming Assignment No. 5 Write a program that asks the user to enter a positive odd number less than 20. If the number is 5, 11 or 15, draw a square whose width is the same as the number entered, if 3, 9, or 17, draw a box (a box is a hollowed out square) with the width the same as the number entered, otherwise just present an message saying "To be determined". Write a method for the square that...
You are using ONLY Programming Language C for this: In this program you will calculate the...
You are using ONLY Programming Language C for this: In this program you will calculate the average of x students’ grades (grades will be stored in an array). Here are some guidelines to follow to help you out: 1. In your program, be sure to ask the user for the number of students that are in the class. The number will help in declaring your array. 2. Use the function to scan the grades of the array. To say another...
1. Specification Write a C program to implement a simple calculator that accepts input in the...
1. Specification Write a C program to implement a simple calculator that accepts input in the following format and displays the result of the computation: calc [operand_1] [operator] [operand_2] The operands operand_1 and operand_2 are non-negative integers. The operator is one of the following: addition (+), subtraction (-), multiplication (x), division (/) and modulo (%). Note: For the multiplication operator, use letter ‘x’. If you use the asterisk ‘*’, your program will not work properly 2. Implementation • The program...
Write a program in Python to simulate a Craps game: 1. When you bet on the...
Write a program in Python to simulate a Craps game: 1. When you bet on the Pass Line, you win (double your money) if the FIRST roll (a pair of dice) is a 7 or 11, you lose if it is ”craps” (2, 3, or 12). Otherwise, if it is x ∈ {4, 5, 6, 8, 9, 10}, then your point x is established, and you win when that number is rolled again before ’7’ comes up. The game is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT