Skip to content

Instantly share code, notes, and snippets.

@padawanR0k
Last active April 3, 2022 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save padawanR0k/87b66fda0d669bc466a2702b37496dc6 to your computer and use it in GitHub Desktop.
Save padawanR0k/87b66fda0d669bc466a2702b37496dc6 to your computer and use it in GitHub Desktop.
NFA
// [ab]*a[ab][ab]
f = {
'0':{'a':[0,1], 'b':[0]},
'1':{'a':[2], 'b':[2]},
'2':{'a':[3], 'b':[3]},
}
// f[theta][sigma]
const final = new Set([3])
let state = 0;
let result = false;
const str = "baaba";
for (let j=0; j<str.length;j++){
const it = str[j];
for (let i=0; i<f[state][it].length;i++){
if(final.has(f[state][it][i])) {
result = true;
break;
}
state = f[state][it][i]
}
if (result) {
break;
}
}
console.log('result: ', result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment