예제 #1
0
def test_move():
    assert Scrambler.do('move position 2 to position 4', 'abcde') == 'abdec'
    assert Scrambler.do('move position 4 to position 2', 'abcde') == 'abecd'

    assert Scrambler.do('move position 2 to position 4', 'abdec',
                        reverse=True) == 'abcde'
    assert Scrambler.do('move position 4 to position 2', 'abecd',
                        reverse=True) == 'abcde'
예제 #2
0
def test_do_all():
    operations = [
        'swap position 4 with position 0', 'swap letter d with letter b',
        'reverse positions 0 through 4', 'rotate left 1 step',
        'move position 1 to position 4', 'move position 3 to position 0',
        'rotate based on pposition of letter b',
        'rotate based on position of letter d'
    ]
    assert Scrambler.do_all(operations, 'abcde') == 'decab'
    assert Scrambler.do_all(operations, 'decab', reverse=True) == 'abcde'
예제 #3
0
def test_rotate_based_on_position():
    assert Scrambler.do('rotate based on position of letter a',
                        'abcde') == 'eabcd'
    assert Scrambler.do('rotate based on position of letter b',
                        'abcde') == 'deabc'
    assert Scrambler.do('rotate based on position of letter e',
                        'abcde') == 'eabcd'

    assert Scrambler.do('rotate based on position of letter a',
                        'eabcd',
                        reverse=True) == 'abcde'
    assert Scrambler.do('rotate based on position of letter b',
                        'deabc',
                        reverse=True) == 'abcde'
    assert Scrambler.do('rotate based on position of letter e',
                        'eabcd',
                        reverse=True) == 'abcde'
예제 #4
0
def test_rotate_left():
    assert Scrambler.do('rotate left 3 steps', 'abcde') == 'deabc'
    assert Scrambler.do('rotate left 4 steps', 'abcde') == 'eabcd'
    assert Scrambler.do('rotate left 5 steps', 'abcde') == 'abcde'
    assert Scrambler.do('rotate left 3 steps', 'deabc',
                        reverse=True) == 'abcde'
예제 #5
0
def test_reverse():
    assert Scrambler.do('reverse positions 1 through 3', 'abcde') == 'adcbe'
    assert Scrambler.do('reverse positions 1 through 3', 'abcde',
                        reverse=True) == 'adcbe'
예제 #6
0
def test_swap_letter():
    assert Scrambler.do('swap letter c with letter d', 'abcde') == 'abdce'
    assert Scrambler.do('swap letter c with letter d', 'abdce',
                        reverse=True) == 'abcde'
예제 #7
0
def test_swap_position():
    assert Scrambler.do('swap position 2 with position 0', 'abcde') == 'cbade'
    assert Scrambler.do('swap position 2 with position 0',
                        'cbade',
                        reverse=True) == 'abcde'
예제 #8
0
def test_rotate_right():
    assert Scrambler.do('rotate right 3 steps', 'abcde') == 'cdeab'
    assert Scrambler.do('rotate right 3 steps', 'cdeab',
                        reverse=True) == 'abcde'
예제 #9
0
from day21.scrambler import Scrambler

with open('input.txt') as f:
    operations = [line[:-1] for line in f.readlines() if len(line) > 0]
    print(Scrambler.do_all(operations, 'abcdefgh'))
    print(Scrambler.do_all(operations, 'fbgdceah', reverse=True))