turing(State,[Letter|Left]-Right,FinalTape):-
c
(State
,Letter
,NewState
,Write,Move
), move
(Move
,[Write|Left
]-Right
,NewTape
), turing(NewState,NewTape,FinalTape).
turing(State,Tape,Tape):-
f(State).
move(none,Tape,Tape).
move(left,[X|Left]-Right,NewLeft-NewRight):-
(Left=[] -> NewLeft=[free] ; NewLeft=Left),
(Right=[free] -> NewRight=[X] ; NewRight=[X|Right]).
move(right,Left-[X|Right],NewLeft-Right):-
Left=[free] -> NewLeft=[X] ; NewLeft=[X|Left].
move(right,Left-[],NewLeft-[]):-
Left=[free] -> NewLeft=Left ; NewLeft=[free|Left].
dHVyaW5nKFN0YXRlLFtMZXR0ZXJ8TGVmdF0tUmlnaHQsRmluYWxUYXBlKTotIApjKFN0YXRlLExldHRlcixOZXdTdGF0ZSxXcml0ZSxNb3ZlKSwgCm1vdmUoTW92ZSxbV3JpdGV8TGVmdF0tUmlnaHQsTmV3VGFwZSksIAp0dXJpbmcoTmV3U3RhdGUsTmV3VGFwZSxGaW5hbFRhcGUpLiAKdHVyaW5nKFN0YXRlLFRhcGUsVGFwZSk6LSAKZihTdGF0ZSkuIAogIAptb3ZlKG5vbmUsVGFwZSxUYXBlKS4gCm1vdmUobGVmdCxbWHxMZWZ0XS1SaWdodCxOZXdMZWZ0LU5ld1JpZ2h0KTotIAooTGVmdD1bXSAtPiBOZXdMZWZ0PVtmcmVlXSA7IE5ld0xlZnQ9TGVmdCksIAooUmlnaHQ9W2ZyZWVdIC0+IE5ld1JpZ2h0PVtYXSA7IE5ld1JpZ2h0PVtYfFJpZ2h0XSkuIAptb3ZlKHJpZ2h0LExlZnQtW1h8UmlnaHRdLE5ld0xlZnQtUmlnaHQpOi0gCkxlZnQ9W2ZyZWVdIC0+IE5ld0xlZnQ9W1hdIDsgTmV3TGVmdD1bWHxMZWZ0XS4gCm1vdmUocmlnaHQsTGVmdC1bXSxOZXdMZWZ0LVtdKTotIApMZWZ0PVtmcmVlXSAtPiBOZXdMZWZ0PUxlZnQgOyBOZXdMZWZ0PVtmcmVlfExlZnRdLiAK