forked from amirbawab/Turing-Machine-simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAcceptReject.java
More file actions
40 lines (34 loc) · 1.13 KB
/
Copy pathAcceptReject.java
File metadata and controls
40 lines (34 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import turingMachine.State;
import turingMachine.Transition;
import turingMachine.TuringMachine;
/**
* Turing Machine
* Coded by Amir El Bawab
* Date: 3 January 2015
* License: MIT License ~ Please read License.txt for more information about the usage of this software
* */
public class AcceptReject {
public static void main(String[] args) {
// Create the machine that will only accept 1's
TuringMachine tm = new TuringMachine('q');
// Create the states
State[] q = new State[3];
q[0] = tm.addState(State.INITIAL);
q[1] = tm.addState(State.FINAL);
q[2] = tm.addState(State.NORMAL);
// Add transition
tm.addTransition(q[0], q[0], '1', '1', Transition.RIGHT);
tm.addTransition(q[0], q[1], Transition.BLANK, Transition.BLANK, Transition.LEFT);
tm.addTransition(q[0], q[2], '0', '0', Transition.RIGHT);
// Process input 111
if(tm.process("111")) // Accept because only 1's
System.out.println("Accept 111");
else
System.out.println("Reject 111");
// Process input 1011
if(tm.process("1011")) // Reject because there's a 0
System.out.println("Accept 1011");
else
System.out.println("Reject 1011");
}
}