1%-----------------------------------------------------------------------------%
    2% vim: ft=prolog ts=4 sw=4 et wm=0 tw=0
    3%-----------------------------------------------------------------------------%
    4:- use_module(turing).    5
    6%-----------------------------------------------------------------------------%
    7% Sample Turing machines.
    8%-----------------------------------------------------------------------------%
    9
   10% A tape with a string of 1 will have a 1 appended.
   11% Input tape: [1, 1, 1]
   12% Output tape: [1, 1, 1, 1]
   13% Uses the default configuration from the turing module.
   14incrementer(q0, 1, 1, right, q0).
   15incrementer(q0, b, 1, stay,  qf).
   16
   17% A three-state busy beaver
   18% http://en.wikipedia.org/wiki/Busy_beaver
   19busy_beaver_config(IS, FS, RS, B, S) :-
   20    IS = 'A',               % initial state
   21    FS = ['HALT'],          % halting states
   22    RS = [IS, 'B', 'C'],    % running states
   23    B  = 0,                 % blank symbol
   24    S  = [B, 1].            % valid symbols
   25busy_beaver('A', 0, 1, right, 'B').
   26busy_beaver('A', 1, 1, left,  'C').
   27busy_beaver('B', 0, 1, left,  'A').
   28busy_beaver('B', 1, 1, right, 'B').
   29busy_beaver('C', 0, 1, left,  'B').
   30busy_beaver('C', 1, 1, stay,  'HALT').
   31
   32
   33go :-
   34    turing(default_config, incrementer, [1, 1, 1], T1),
   35    write(T1), nl,
   36    turing(busy_beaver_config, busy_beaver, [], T2),
   37    write(T2), nl