diff options
author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-10-24 23:43:21 -0600 |
---|---|---|
committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-10-24 23:43:21 -0600 |
commit | 7f8392f6294f415b7c223bd831db5082ca614db4 (patch) | |
tree | 583b2dd6ba8f4e8c88c84a6dfc74e8b95def7309 /turing-machine/js/turing_machine.js | |
parent | 4ce505b125950521860f0d2170409719927f3f85 (diff) | |
download | simponic.xyz-7f8392f6294f415b7c223bd831db5082ca614db4.tar.gz simponic.xyz-7f8392f6294f415b7c223bd831db5082ca614db4.zip |
add favicon, turing machine bug fixes and finishing touches
Diffstat (limited to 'turing-machine/js/turing_machine.js')
-rw-r--r-- | turing-machine/js/turing_machine.js | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/turing-machine/js/turing_machine.js b/turing-machine/js/turing_machine.js index 9c21983..a61b43a 100644 --- a/turing-machine/js/turing_machine.js +++ b/turing-machine/js/turing_machine.js @@ -1,16 +1,9 @@ class TuringMachine { - constructor( - tape = [], - rules = [], - initialState = "q0", - blankSymbol = "B", - acceptState = "f" - ) { + constructor(tape = [], rules = [], initialState = "q0", acceptState = "f") { this.tape = tape; this.rules = this.parseRules(rules); this.state = initialState; this.head = 0; - this.blankSymbol = blankSymbol; this.acceptState = acceptState; this.iteration = 0; @@ -51,7 +44,7 @@ class TuringMachine { } step() { - const currentSymbol = this.tape[this.head] || this.blankSymbol; + const currentSymbol = this.tape[this.head]; const key = `${this.state},${currentSymbol}`; if (!(key in this.rules)) { return false; @@ -60,6 +53,7 @@ class TuringMachine { const [newState, action] = rule.split(","); this.state = newState; + this.iteration++; if (action === "R") { this.head += 1; @@ -73,10 +67,6 @@ class TuringMachine { return false; } - if (this.head >= 0 && this.head < this.tape.length) { - this.iteration++; - return true; - } - return false; + return this.head >= 0 && this.head < this.tape.length; } } |