Ejemplo n.º 1
0
def test_move_head_stay():
    tape = Tape('B', ['a', 'b', 'X', 'B'], ['a', 'b'])
    tape.move_head('S')
    assert tape.get_content() == 'a'
Ejemplo n.º 2
0
def test_move_head_right_left():
    tape = Tape('B', ['a', 'b', 'X', 'B'], ['a', 'b'])
    tape.move_head('R')
    tape.move_head('L')
    assert tape.get_content() == 'a'
Ejemplo n.º 3
0
import sys
from tape import Direction
from tape import Tape

if __name__ == '__main__':
    if len(sys.argv) == 1:
        print('usage: {} <palindrome>'.format(sys.argv[0]))
        print('where the format of a palindrome is L = { ww^R | w = (0+1)^* }')
        sys.exit(0)

    tape = Tape(sys.argv[1])

    while True:
        if tape.read() == '0':
            tape.write('x')
            tape.move_head(Direction.RIGHT)

            if tape.read() in ['0', '1']:
                tape.move_head(Direction.RIGHT)
            elif tape.read() in ['d', 'x', 'y']:
                break

            while tape.read() in ['0', '1']:
                tape.move_head(Direction.RIGHT)

            if tape.read() in ['d', 'x', 'y']:
                tape.move_head(Direction.LEFT)

            if tape.read() == '0':
                tape.write('x')
                tape.move_head(Direction.LEFT)