@@ -0,0 +1,1924 @@
+from itertools import permutations%0A%0A%0Adef test_single_digit_move():%0A    assert %5B2, 0, 0, 0%5D == move(%5B0, 0, 2, 0%5D)%0A%0A%0Adef test_multi_digit_move():%0A    assert %5B2, 4, 0, 0%5D == move(%5B0, 0, 2, 4%5D)%0A%0A%0Adef test_idempotent_move():%0A    assert %5B2, 4, 8, 0%5D == move(%5B2, 4, 8, 0%5D)%0A%0A%0Adef test_move_closes_small_gap():%0A    assert %5B4, 2, 8, 0%5D == move(%5B4, 0, 2, 8%5D)%0A%0A%0Adef test_move_closes_big_gap():%0A    assert %5B2, 8, 0, 0%5D == move(%5B2, 0, 0, 8%5D)%0A%0A%0Adef test_move_with_simple_merge():%0A    for permutation in permutations(%5B2, 2, 0, 0%5D):%0A        assert %5B4, 0, 0, 0%5D == move(list(permutation))%0A%0A%0Adef test_left_padded_merge_move():%0A    assert %5B4, 0, 0, 0%5D == move(%5B0, 0, 2, 2%5D)%0A%0A%0Adef test_simple_merge():%0A    assert %5B4%5D == merge(%5B2, 2%5D)%0A    assert %5B4, 2%5D == merge(%5B2, 2, 2%5D)%0A    assert %5B2, 8%5D == merge(%5B2, 4, 4%5D)%0A    assert %5B4, 4%5D == merge(%5B2, 2, 2, 2%5D)%0A    assert %5B4, 4, 4%5D == merge(%5B4, 2, 2, 4%5D)%0A%0A%0Adef test_right_pad_empty_list_to_four():%0A    assert %5B0, 0, 0, 0%5D == right_pad(%5B%5D)%0A%0A%0Adef test_right_pad_list_to_four():%0A    assert %5B2, 4, 0, 0%5D == right_pad(%5B2, 4%5D)%0A%0A%0Adef test_right_pad_list_to_defined_length():%0A    assert %5B2, 4, 0%5D == right_pad(%5B2, 4%5D, size=3)%0A%0A%0Adef test_idempotent_right_pad():%0A    assert %5B2, 4%5D == right_pad(%5B2, 4%5D, size=2)%0A    assert %5B2, 4, 8%5D == right_pad(%5B2, 4, 8%5D, size=2)%0A%0A%0Adef move(row):%0A    without_zeroes = filter(bool, row)%0A    return right_pad(merge(without_zeroes))%0A%0A%0Adef merge(row):%0A    result = %5B%5D%0A    digit_stack = list(reversed(row))%0A    while digit_stack:%0A        if len(digit_stack) == 1:%0A            result.append(digit_stack.pop())%0A            break%0A        a = digit_stack.pop()%0A        b = digit_stack.pop()%0A        if a == b:%0A            result.append(a+b)%0A        else:%0A            result.append(a)%0A            digit_stack.append(b)%0A    return result%0A%0A%0Adef right_pad(input_list, size=4):%0A    result = input_list%5B:%5D%0A    extension = %5B0,%5D * (size - len(result))%0A    result.extend(extension)%0A    return result%0A

add move, merge and right_pad