1 ended automation
w = F =0 1 0 0 1 0 1 A -> A -> B -> C -> A -> B -> C -> B Accept
0 | 1 | |
---|---|---|
> A | A | B |
* B | C | B |
* C | A | B |
function delta(q, c) { // (1|0)*10 if (q=='A' && c=='0') return 'A' if (q=='B' && c=='0') return 'C' if (q=='C' && c=='0') return 'A' if (c=='1') return 'B' return ''; //default -- no transition } function accept(w, F='C', 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") }