# https://www.codewars.com/kata/521c2db8ddc89b9b7a0000c1/train/python

def snail(snail_map):
    compression = sum(snail_map, [])
    if len(compression) <= 1:
        return compression

    result = []
    n = len(snail_map)
    step = 1
    x = -1
    y = 0

    while n:
        for _ in range(n):
            x += step
            result.append(snail_map[y][x])
        n -= 1

        for _ in range(n):
            y += step
            result.append(snail_map[y][x])
        step = -step

    return result


def main():
    test_cases = [
        {
            "input":
                [[1, 2, 3],
                 [4, 5, 6],
                 [7, 8, 9]],
            "output":
                [1, 2, 3, 6, 9, 8, 7, 4, 5]
        },
        {
            "input":
                [[1, 2, 3],
                 [8, 9, 4],
                 [7, 6, 5]],
            "output":
                [1, 2, 3, 4, 5, 6, 7, 8, 9]
        },
        {
            "input":
                [[]],
            "output":
                []
        },
        {
            "input":
                [[1]],
            "output":
                [1]
        }
    ]

    for test_case in test_cases:
        result = snail(test_case["input"])
        if test_case["output"] == result:
            print(f"Result: {result} - correct")
        else:
            print(f"Result: {result} - wrong")


if __name__ == '__main__':
    main()

# https://www.codewars.com/kata/521c2db8ddc89b9b7a0000c1/train/python

def snail(snail_map):
    compression = sum(snail_map, [])
    if len(compression) <= 1:
        return compression

    result = []
    n = len(snail_map)
    step = 1
    x = -1
    y = 0

    while n:
        for _ in range(n):
            x += step
            result.append(snail_map[y][x])
        n -= 1

        for _ in range(n):
            y += step
            result.append(snail_map[y][x])
        step = -step

    return result


def main():
    test_cases = [
        {
            "input":
                [[1, 2, 3],
                 [4, 5, 6],
                 [7, 8, 9]],
            "output":
                [1, 2, 3, 6, 9, 8, 7, 4, 5]
        },
        {
            "input":
                [[1, 2, 3],
                 [8, 9, 4],
                 [7, 6, 5]],
            "output":
                [1, 2, 3, 4, 5, 6, 7, 8, 9]
        },
        {
            "input":
                [[]],
            "output":
                []
        },
        {
            "input":
                [[1]],
            "output":
                [1]
        }
    ]

    for test_case in test_cases:
        result = snail(test_case["input"])
        if test_case["output"] == result:
            print(f"Result: {result} - correct")
        else:
            print(f"Result: {result} - wrong")


if __name__ == '__main__':
    main()

# https://www.codewars.com/kata/521c2db8ddc89b9b7a0000c1/train/python