Anonymous user
Universal Turing machine: Difference between revisions
m
→{{header|Java}}
Line 584:
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.List;
import java.util.Set;
import java.util.Map;
public class UTM {
private
private String blankSymbol;
private ListIterator<String> head;
private
private Set<String> terminalStates;
private String initialState;
public UTM(
this.blankSymbol = blankSymbol;
for (Transition t : transitions) {
this.transitions.put(t.from, t);
Line 609 ⟶ 610:
public StateTapeSymbolPair(String state, String tapeSymbol) {
this.state = state;
this.tapeSymbol = tapeSymbol;
Line 620:
int result = 1;
result = prime * result
+ ((
result = prime
* result
+ ((
.hashCode());
return result;
Line 638:
return false;
StateTapeSymbolPair other = (StateTapeSymbolPair) obj;
if (
if (other.state != null)
return false;
} else if (!
return false;
if (
if (other.tapeSymbol != null)
return false;
} else if (!
return false;
return true;
Line 653:
@Override
public String toString() {
return "(" +
}
}
Line 663:
public Transition(StateTapeSymbolPair from, StateTapeSymbolPair to, int direction) {
this.to = to;
this.direction = direction;
Line 671 ⟶ 670:
@Override
public String toString() {
return
}
}
public void initializeTape(
}
public void initializeTape(String input) { // Uses single characters as symbols.
for (int i = 0; i < input.length(); i++) {
}
}
public
if (
}
StateTapeSymbolPair tsp = new StateTapeSymbolPair(
while (
System.out.println(this + " --- " +
Transition trans =
tsp.state = trans.to.state; // Change state.
if (trans.direction == -1) { // Go left.
if (!
}
tsp.tapeSymbol =
} else if (trans.direction == 1) { // Go right.
if (!
}
tsp.tapeSymbol =
} else {
tsp.tapeSymbol = trans.to.tapeSymbol;
Line 722 ⟶ 721:
System.out.println(this + " --- " + tsp);
if (
return
} else {
return null;
Line 732 ⟶ 731:
public String toString() {
try {
int headPos =
String s = "[ ";
for (int i = 0; i <= headPos; i++) {
s +=
}
s += "[H] ";
for (int i = headPos + 1; i <
s +=
}
Line 756 ⟶ 755:
String blank = "b";
term.add("qf");
trans.add(new Transition(new StateTapeSymbolPair("q0", "1"), new StateTapeSymbolPair("q0", "1"), 1));
|