def merge(line):
    """
    Helper function that merges a single row or column in 2048
    """
    result = list(line)
    head = 0
    i = 1
    while (i < len(result)):
        if (result[i] != 0):
            if (result[head] == result[i]):
                result[head] += result[i]
                result[i] = 0
                head += 1
            elif (result[head] == 0):
                result[head] = result[i]
                result[i] = 0
            else:
                tmp = result[i]
                result[i] = 0
                result[head + 1] = tmp
                head += 1
        i += 1
    return result