function deltaNFA(q, c) { // (1|0)*00 if (q=='a' && c=='0') return 'ab' if (q=='a' && c=='1') return 'a' if (q=='b' && c=='0') return 'c' return ''; //default -- no transition } function acceptNFA(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, deltaNFA(q, c)) Q = T if (Q == '') break i++; txt += ", "+c+" -> "+Q+'\n'+Q } return intersect(Q, F).length > 0 } function deltaDFA(q, c) { // (1|0)*00 if (q=='a' && c=='0') return 'ab' if ((q=='a' || q=='b' || q=='c') && c=='1') return 'a' if ((q=='b' || q=='c') && c=='0') return 'c' return ''; //default -- no transition } function acceptDFA(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, deltaDFA(q, c)) Q = T if (Q == '') break i++; txt += ", "+c+" -> "+Q+'\n'+Q } return intersect(Q, F).length > 0 }