Last active
January 2, 2016 02:49
-
-
Save mrogaski/8239722 to your computer and use it in GitHub Desktop.
Turing Machine JAPH
This file contains hidden or 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
#!/usr/local/bin/perl -nl | |
@a=map{s/##//;s/CM/,/;$_}split(",",$_);$s->[$a[0]]{$a[1]}=[@a[2..4]];}continue{ | |
eof&&last;}$q=$i=0;@t=split(//,shift);while("!!"ne$q){($q,$t[$i],$_)=@{$s->[$q] | |
{$t[$i]}||die};$i+=(/R/?1:-1);if($i<0){$i++;unshift(@t,"");}}print@t;{ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The first argument is the name of a file containing a comma delimited list of finite-state control instructions representing
curr_state,read_symbol,new_state,write_symbol,head_direction
The second argument is a character string representing the initial contents of the tape.
The states are encoded as integers >= 0 or '!!' for the halt state.
The symbols may be any printable ASCII character. An empty square is encoded as '##' and a comma is encoded as 'CM'.
Head direction is either 'L' or 'R'.
If the TM encounters a transition for which no finite-state control instruction exists, the simulator dies.
The TM starts with the tape head at the leftmost position.
Attempting a solution to the halting problem is not recommended. ;)
An example program to increment a binary string: