Last active
April 3, 2022 05:13
-
-
Save padawanR0k/87b66fda0d669bc466a2702b37496dc6 to your computer and use it in GitHub Desktop.
NFA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [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