-
Notifications
You must be signed in to change notification settings - Fork 0
/
CW1.html
94 lines (82 loc) · 2.2 KB
/
CW1.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
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>CW 1</title>
<script>
"use strict";
function delta(q, c) {
if (q=='A' && c=='0') return 'B'
if (q=='A' && c=='1') return 'A'
if (q=='B' && c=='0') return 'C'
if (q=='B' && c=='1') return 'A'
if (q=='C' && c=='0' || c=='1') return 'C'
return ''; //default -- no transition
}
function accept(w, F='A'||'B', q='A') {
//w: input String
//F: final state(s)
//q: current state
let i = 0, txt = q
while (i < w.length) {
q = delta(q, w[i])
if (q == '') break
i++; txt += " -> "+q
}
input.selectionStart = i
input.selectionEnd = i+1
let a = (q!='' && F.includes(q))
return txt+' '+(a? "Accept" : "Reject")
}
function test() {
let w = input.value, s = " "
for (let c of w) s += c+" "
s += '\n'+accept(w, final.value)
console.log(s); out.innerHTML = s
}
</script>
</head>
<body>
<h2 id=title></h2>
<p>
<b>1.soru:</b><br> alphabet= string<br><br>empty string= " "<br><br>length= a.length<br><br>concatenation=<br>var a = "Fatih";<br>var b= "Sultan";<br> var c = a.concat(b);<br><br><b>2.soru:</b><br>01101 kabul eder<br>00101 kabul etmez, ardarda -iki sıfır- '00' geldikten sonra C'ye girer ve bu makine C'ye girdikten sonra çıkamaz.</p>
w = <input id=input type=text value=01101
onChange="test()">  
F = <input id=final type=text value=A,B
onChange="test()" style="width:30px">
<pre id=out></pre>
<hr />
<b>Logic</b>
<style>
table {
border-collapse: collapse;
margin: 0 50px;
}
th {
color: blue;
padding: 5px 12px;
}
td {
border: 1px solid blue;
padding: 5px 12px;
text-align: center;
}
</style>
<table>
<tr><th></th><th>0</th><th>1</th></tr>
<tr><th>> *A</th><td>B</td><td>A</td></tr>
<tr><th> *B</th><td>C</td><td>A</td></tr>
<tr><th> C</th><td>C</td><td>C</td></tr>
</table>
<pre id=sample></pre>
<hr />
<!--p>Ref: <a href="https:xxx"
target="ExternalDocument">xxx</a>
</p-->
<script>
title.innerText = document.title
sample.innerText = delta
test()
</script>
</body>