Universal Turing machine: Difference between revisions

Content added Content deleted
m (→‎{{header|Java}}: Generics and foreach started in Java 5, more-correct highlighting, no signatures on examples)
Line 576:
 
=={{header|Java}}==
{{works with|Java Virtual Machine|6.05+}}
 
This is an implementation of the universal Turing machine in plain Java using standard libraries only. As generics are used, Java 65 is required. The examples (incrementer and busy beaver) are implemented directly in the main method and executed subsequentiallysequentially. During execution the complete tape and the current state / tape symbol pair are printed out in every step. The state names and tape symbols may contain several characters, so arbitrary strings such as "q1", "q2", ... can be valid state names or tape symbols. The machine is deterministic as the transitions are stored in a HashMap which uses state / tape symbol pairs as keys. This is not a standard implementation, but I coded this on my own, so there is no guarantee of correctness.
 
<lang Java5>import java.util.HashMap;
<lang Java>
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
Line 773 ⟶ 772:
System.out.println("Output (bb): " + machine.runTM());
}
}</lang Java>
}
</lang>
 
{{out}}
 
<pre>[1, 1, 1] --- (q0,1)
<pre>
[1, 1, 1] --- (q0,1)
[1, 1, 1] --- (q0,1)
[1, 1, 1] --- (q0,1)
Line 799 ⟶ 796:
[1, 1, 1, 1, 1, 1] --- (c,1)
[1, 1, 1, 1, 1, 1] --- (halt,1)
Output (bb): [1, 1, 1, 1, 1, 1]</pre>
</pre>
 
--[[User:Coenig|Coenig]] 21:37, 14 February 2013 (UTC)
 
=={{header|Mercury}}==