Download code

Jump to: navigation, search

Back to Turing_machine_simulator_(LaTeX)

Download for Windows: single file, zip

Download for UNIX: single file, zip, tar.gz, tar.bz2

turing.tex

 1 % The authors of this work have released all rights to it and placed it
 2 % in the public domain under the Creative Commons CC0 1.0 waiver
 3 % (http://creativecommons.org/publicdomain/zero/1.0/).
 4 % 
 5 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 % 
13 % Retrieved from: http://en.literateprograms.org/Turing_machine_simulator_(LaTeX)?oldid=10889
14 
15 \documentclass[12pt]{article}
16 
17 \newcounter{headpos}
18 \setcounter{headpos}{0}
19 \newcommand{\Moveleft}{\addtocounter{headpos}{-1}%
20   moved one position to the \textbf{left}}
21 \newcommand{\Moveright}{\addtocounter{headpos}{1}%
22   moved one position to the \textbf{right}}
23 \newcommand{\ReadTape}[1]{%
24 \expandafter\let\expandafter\TapeAtHead\expandafter=%
25 \csname TapeAt\arabic{headpos}\endcsname%
26 \ifx\TapeAtHead\relax\expandafter\def\TapeAtHead{zero}\fi
27 \def#1{\TapeAtHead}
28 }
29 \newcommand{\Write}[1]{%
30 \expandafter\def\csname TapeAt\arabic{headpos}\endcsname{#1}%
31 wrote a \textbf{#1} at this position, }
32 \newcommand{\StateInitialText}{Initially the busy beaver was in state }
33 \newcounter{step}
34 \setcounter{step}{0}
35 \newcommand{\State}[1]{\ReadTape{\Symbol}%
36   \StateInitialText \textbf{#1}.%
37   \renewcommand{\StateInitialText}{and switched to state }
38 
39   \addtocounter{step}{1}%
40   At the beginning of step \textbf{\arabic{step}}, the busy beaver was
41   in state \textbf{#1}, sitting at position \textbf{\arabic{headpos}}
42   of the tape. The tape at this position contained a \textbf{\Symbol}.
43   The beaver \csname#1\Symbol\endcsname}
44 \newcommand{\RunTuringMachine}{\State{A}}
45 \newcommand{\Azero}{\Write{one}\Moveright\State{B}}
46 \newcommand{\Aone}{\Write{one}\Moveleft\State{C}}
47 \newcommand{\Bzero}{\Write{one}\Moveleft\State{A}}
48 \newcommand{\Bone}{\Write{one}\Moveright\State{B}}
49 \newcommand{\Czero}{\Write{one}\Moveleft\State{B}}
50 \newcommand{\Cone}{\Write{one}\Moveleft\State{Halt}}
51 \newcommand{\Haltzero}{\Halt}
52 \newcommand{\Haltone}{\Halt}
53 
54 \newcommand{\Halt}{stopped any activity.}
55 
56 \begin{document}
57 \title{The Tale of the Busy Beaver}
58 \maketitle
59 \RunTuringMachine
60 \end{document}
61 


hijacker
hijacker
hijacker
hijacker