# Problem Description
- The task involves transforming a 1d array of colors based on a given "vertical axis" (specified by the line_position). The input list contains integer values representing colors:
    0 for white
    1 for light blue
    2 for dark blue
- The transformation involves folding the 1d array around the vertical axis (line_position) and merging values on either side of the axis using a specific rule. The output is a new 1D list with transformed values.

# Visual Facts
- Each example starts with an input 1d array and a specified line_position (indicated by a dashed vertical line).
- The 1d array is folded along the line_position. Values to the left of the axis are flipped (mirrored) and merged with the corresponding values to the right.
- The output 1d array has fewer columns than the input 1d array.
- The merging process appears to follow a rule where overlapping values are combined:
    - Values to the left of the axis are flipped (mirrored) and added to the corresponding values on the right.
        1. If the sum equals 0, the result is white.
        2. If the sum equals 1, the result is light blue.
        3. If the sum equals 2, the result is dark blue.
        4. There will never be a result greater than 2.
        5. If the mirrored values on the left have no corresponding values on the right, it is assumed that the corresponding values on the right are 0, and the addition is performed accordingly.
- Examples
    Example 1: Input: [1, 0, 1], line_position = 1 Transformation:
    Fold [1] (left of axis) onto [0] (right of axis).
    Merge: 1 + 0 = 1 Output: [1, 1]

    Example 2: Input: [0, 1, 1, 0, 1], line_position = 3 Transformation:
    Fold [0, 1, 1] onto [0, 1].
    Merge: 1 + 0 = 1, 1 + 1 = 2, 0 + 0 = 0 Output: [1, 2, 0]

    Example 3: Input: [0, 1, 0, 0], line_position = 3 Transformation:
    Fold [0, 1, 0] onto [0].
    Merge: 0 + 0 = 0, 1 + 0 = 1, 0 + 0 = 0 Output: [0, 1, 0]

# Visual Patterns
1. 1d array Folding
    Values on the left of the line_position are reversed and folded over to overlap with values on the right.
    The length of the output list is determined by the maximum distance between line_position and either end of the input list.
2. Output Length
    For an input list of length n and a line_position of p, The output length is max(p, n - p).


# Solution
from typing import List

def solution(colors: List[int], line_position: int) -> List[int]:
    """
    Transforms a 1D color array based on a given dashed line position.

    Args:
        colors (List[int]): A 1D array representing colors where:
            - 0 = white
            - 1 = light blue  
            - 2 = dark blue
        line_position (int): The position of the dashed line used for transformation

    Returns:
        List[int]: A new 1D array with transformed colors where:
            - 0 = white
            - 1 = light blue
            - 2 = dark blue
    """
    n = len(colors)
    left_part = colors[:line_position][::-1]
    right_part = colors[line_position:]
    
    max_length = max(len(left_part), len(right_part))
    result = []
    
    for i in range(max_length):
        left_value = left_part[i] if i < len(left_part) else 0
        right_value = right_part[i] if i < len(right_part) else 0
        merged_value = left_value + right_value
        result.append(min(merged_value, 2))  # Ensure the value does not exceed 2
    
    return result


# Test Script
def test():
    test_cases = [
        ([0, 1, 0, 1], 2, [1, 1]),
        ([0, 1, 0, 1], 1, [1, 0, 1]), 
        ([1, 1, 0, 1], 2, [1, 2]),
        ([1, 1, 1, 1], 2, [2, 2]),
        ([0, 1, 0, 0], 3, [0, 1, 0]),
        ([0, 1, 1, 1, 0, 1], 2, [2, 1, 0, 1]),
        ([0, 1, 1, 1, 0, 1], 1, [1, 1, 1, 0, 1]),
        ([1, 1, 1, 0, 1, 1], 1, [2, 1, 0, 1, 1]),
        ([1, 0, 1, 1, 0, 1], 4, [1, 2, 0, 1])
    ]

    for i, (colors, line_position, expected_output) in enumerate(test_cases):
        try:
            output = solution(colors, line_position)
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`colors`: {colors}\n" 
                f"`line_position`: {line_position}\n\n"
                f"Exception: '{str(e)}'"
            )
            assert False, error_message

        if output != expected_output:
            error_message = (
                f"The following Test Case failed:\n"
                f"`colors`: {colors}\n"
                f"`line_position`: {line_position}\n\n"
                f"Actual Output: {output}\n"
                f"Expected Output: {expected_output}"
            )
            assert False, error_message

test()