-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiplyMachine.html
164 lines (139 loc) · 3.18 KB
/
multiplyMachine.html
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<html>
<head>
<script type="text/javascript" src="js/jquery.min.js" /></script>
<script type="text/javascript">
var stateTable = {
//SETUP
//right to b
"A": {
1: [ 1, "right", "A" ],
0: [ 0, "right", "B" ]
},
//right to c
"B": {
1: [ 1, "right", "B" ],
0: [ 0, "right", "C" ]
},
//print bottom mark in c
"C": {
1: [ 1, "left", "D" ],
0: [ 1, "left", "D" ]
},
//left to bottom of b
"D": {
1: [ 1, "left", "E" ],
0: [ 0, "left", "D" ]
},
//left to bottom of a
"E": {
1: [ 1, "left", "E" ],
0: [ 0, "left", "F" ]
},
//A LOOP ( do B LOOP for each a )
//seek to top of a
"F": {
1: [ 1, "left", "F" ],
0: [ 0, "right", "G" ]
},
//decrement a
"G": {
1: [ 0, "right", "H" ],
0: [ 0, "right", "H" ]
},
//test if a is blank, if so then done.
"H": {
1: [ 1, "right", "I" ],
0: [ 0, "right", "Halt" ]
},
//right to b
"I": {
1: [ 1, "right", "I" ],
0: [ 0, "right", "J" ]
},
//move to inside b
"J": {
1: [ 1, "right", "K" ],
0: [ 0, "right", "K" ]
},
//B LOOP ( COPY B to C )
//mark b
"K": {
1: [ 0, "right", "L" ],
0: [ 0, "left", "P" ] //if b is empty, back to A-loop
},
//right to c
"L": {
1: [ 1, "right", "L" ],
0: [ 0, "right", "M" ]
},
//right past c, mark 1, back to b
"M": {
1: [ 1, "right", "M" ],
0: [ 1, "left", "N" ]
},
//back to b
"N": {
1: [ 1, "left", "N" ],
0: [ 0, "left", "O" ]
},
//back to pointer, repair
"O": {
1: [ 1, "left", "O" ],
0: [ 1, "right", "K" ]
},
//move from Bloop to Aloop
//left to a
"P": {
1: [ 1, "left", "P" ],
0: [ 0, "left", "F" ] //enter A loop
}
};
var transitionStates = {
"F": "A loop",
"K": "B loop"
};
$(document).ready(function(){
var m = new TuringMachine(stateTable);
$("#setup").click(function(){
$("#outputTable").html("");
m = new TuringMachine(stateTable);
});
$("#step").click(function(){
m.step();
});
$("#run").click(function(){
m.run();
});
$("#pause").click(function(){
m.pause();
});
drawStateTable();
});
</script>
<script type="text/javascript" src="js/turingMachine.js" /></script>
<style type="text/css">
table {border:1px solid black;}
table td {border:1px solid black;}
#stateTable {float:left;}
#outputTable {float:left;margin-left:20px;}
div.step {border:1px solid #ccc;float:left;}
div.state {border:1px solid #ccc;float:left;width:20px;}
div.tapeRow {clear:left;}
div.tapeItem {border:1px solid #ccc;float:left;}
#result {background-color:red;}
</style>
</head>
<body>
<h3>multiply</h3>
A:<input id="a" type="text" value="3">
B:<input id="b" type="text" value="4">
<button type="button" id="setup">setup tape</button>
<button type="button" id="step">step</button>
<button type="button" id="run">run</button>
<button type="button" id="pause">pause</button>
<div id="result"></div>
<div id="currentState">Step: - Current State: A Read: - Write: -</div>
<div id="stateTable"></div>
<div id="outputTable"></div>
</body>
</html>