Acme-Turing

 view release on metacpan or  search on metacpan

Turing.pm  view on Meta::CPAN

  'START: '            state START; tape contains a single blank
  'OUTOFCONTROL:junk'  state OUTOFCONTROL; tape contains 'junk'
  'COMATOSE:'          invalid; tape must contain a non-empty string

There is one reserved tape symbol: ANY (which really means "any
other").  For instance, if the machine is in the BEHIND state,
you can specify both 'BEHIND:time' and 'BEHIND:ANY'.  If the tape
contains 'time', the actions for 'BEHIND:time' will be executed; if
it contains anything else, 'BEHIND:ANY' will be used.

The second argument must contain two elements separated by colons
(:).  These specify
the actions to be taken by the machine
and the next state to be assumed by the machine (any alphanumeric
string).
The first field may contain any combination of these commands,
separated by commas:

  Px  print symbol <x> (character string without blanks) on the tape
  R   move the tape one square to the right
  L   move the tape one square to the left

test.pl  view on Meta::CPAN

#--- 010101....
$m1 = Acme::Turing->new(steps=>100);
$m1->add_spec('START:ANY', "P0,R:C");
$m1->add_spec('C:ANY', "R:E");
$m1->add_spec('E:ANY', "P1, R:Z");
$m1->add_spec('Z:ANY', "R :START");
$m1->run(8,1);

was_it_ok(2, 1);

#--- Turing's second example: 001011011101111...
$m2 = Acme::Turing->new();
$m2->add_spec('START:ANY', "P~,R,P~,R,P0,R,R,P0,L,L:O");
$m2->add_spec('O:1', "R,Px,L,L,L:O");
$m2->add_spec('O:0', ":Q");
$m2->add_spec('Q:ANY', "R,R:Q");
$m2->add_spec('Q: ', "P1,L:P");
$m2->add_spec('P:x', "E,R:Q");
$m2->add_spec('P:~', "R:F");
$m2->add_spec('P: ', "L,L:P");
$m2->add_spec('F:ANY', "R,R:F");



( run in 0.955 second using v1.01-cache-2.11-cpan-39bf76dae61 )