# Problem Description:
The problem involves transforming a sequence of colored blocks (represented by 'R', 'G', and 'B') into a single final color by repeatedly applying a set of combination rules. The transformation rules dictate how pairs of blocks combine, either turning into a single block of the same color if they are identical or transforming into a different color if they are different. The goal is to determine the final color after all possible transformations have been applied.

# Visual Facts:
1. **Combination Rules**:
   - B + B -> B
   - R + R -> R
   - G + G -> G
   - B + R -> G
   - R + G -> B
   - G + B -> R

2. **Example 1**:
   - Initial sequence: R G B B
   - Step 1: R + G -> B, resulting in B B B
   - Step 2: B + B -> B, resulting in B B
   - Step 3: B + B -> B, resulting in B
   - Final color: B

3. **Example 2**:
   - Initial sequence: B G R R R
   - Step 1: B + G -> R, resulting in R R R R
   - Step 2: R + R -> R, resulting in R R R
   - Step 3: R + R -> R, resulting in R R
   - Step 4: R + R -> R, resulting in R
   - Final color: R

# Visual Patterns:
1. **Transformation Process**:
   - The transformation is applied from left to right.
   - Each step involves combining the first two blocks according to the rules and replacing them with the resulting block.
   - This process is repeated until only one block remains.

2. **Combination Outcomes**:
   - Identical colors combine to form the same color.
   - Different colors combine to form a third color, which is determined by the specific pair of colors.

3. **Reduction to Single Block**:
   - The sequence is progressively reduced in length by one block at each step until only one block remains.
   - The final color is the result of all intermediate transformations.


# Solution
from typing import List

def solution(colors: List[str]) -> str:
    """
    Determines the resulting color when combining multiple colors.

    Args:
        colors: A list of single uppercase characters, each representing a color.

    Returns:
        A single uppercase character representing the final combined color.
    """
    def get_third_color(a, b):
        all_colors = {'R', 'G', 'B'}
        return (all_colors - {a, b}).pop()

    arr = colors[:]  # Create a copy of the input list to avoid modifying it directly
    
    # Process the list from left to right
    i = 0
    while i < len(arr) - 1:
        first = arr[i]
        second = arr[i + 1]

        if first == second:
            # If two adjacent colors are the same, merge them into one
            arr.pop(i + 1)  # Remove the second element
        else:
            # If two adjacent colors are different, replace them with the third color
            new_color = get_third_color(first, second)
            arr[i] = new_color  # Replace the first element with the new color
            arr.pop(i + 1)  # Remove the second element
        # Reset i to 0 after each transformation to reprocess the list from the beginning
        i = 0

    return arr[0] if arr else 'W'  # Return the final color or 'W' if the list is empty


# Test Script
def test():
    test_cases = [
            (['R','R'], 'R'),
            (['R','G'], 'B'),
            (['B','B'], 'B'),
            (['G','G'], 'G'), 
            (['R','R','R'], 'R'),
            (['R','G','B'], 'B'),
            (['R','B','R'], 'B'),
            (['R','G','G','G'], 'B'),
            (['R','G','B','B'], 'B'),
            (['R','G','B','R','R'], 'B')
        ]

    for colors, expected_output in test_cases:
        try:
            output = solution(colors)
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`colors`: {colors}\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\n"
                f"Actual Output: {output}\n"
                f"Expected Output: {expected_output}"
            )
            assert False, error_message

test()