function delta(q, c) { // (1|0)*10 if (q=='a' && c=='0') return 'a' if (q=='a' && c=='1') return 'ab' if (q=='b' && c=='0') return 'c' return ''; //default -- no transition } function accept(w, F='c', Q='a') { //w: input String //F: final state(s) //Q: current state(s) let i = 0, txt = Q while (i < w.length) { let c = w[i], T='' for (let q of Q) T = union(T, delta(q, c)) Q = T if (Q == '') break i++; txt += ", "+c+" -> "+Q+'\n'+Q } input.selectionStart = i input.selectionEnd = i+1 let a = intersect(Q, F).length > 0 return txt+' '+(a? "Accept" : "Reject") }