# Problem Description
This is a color transformation problem where we need to apply a set of combination rules to transform a sequence of colors into a final single color. The program takes a list of color codes (R, G, B) as input and should return the final color (W, R, G, or B) after applying all possible transformations according to the given rules.

# Visual Facts
1. There are three sets of combination rules:
   - Left set: Same color combinations (B+B→W, R+R→W, G+G→W)
   - Middle set: White combinations (W+B→B, W+R→R, W+G→G)
   - Right set: Different color combinations (B+R→G, R+G→B, G+B→R)

2. Two examples are provided:
   Example 1: [R,G,B,B] → [B,B,B] → [W,B] → [B]
   Example 2: [B,G,R,R,R] → [R,B,R,R] → [G,R,R] → [B,R] → [G]

3. The color codes used are:
   - R (Red)
   - G (Green)
   - B (Blue)
   - W (White)

# Visual Patterns
1. Transformation Rules:
   - Adjacent identical colors transform to White (W)
   - White combines with any color to produce that same color
   - Different adjacent colors transform according to specific rules:
     * Blue + Red = Green
     * Red + Green = Blue
     * Green + Blue = Red

2. Processing Patterns:
   - Transformations are applied from left to right
   - Rules are applied iteratively until no more transformations are possible
   - Each transformation reduces the sequence length by one
   - The process continues until only one color remains

3. Logical Patterns:
   - The final result will always be a single color
   - The transformations are deterministic (same input always produces same output)
   - The order of applying transformations matters (left-to-right priority)
   - Each step must apply the leftmost possible transformation


# Solution
from typing import List

def solution(colors: List[str]) -> str:
    """
    Determines the final color by applying transformation rules to a sequence of colors.

    Args:
        colors: A list of strings, where each string is a single uppercase character representing a color.

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

    arr = colors[:]
    
    while len(arr) > 1:
        first = arr[0]
        second = arr[1]

        if first == second:
            if len(arr) == 2:
                return 'W'
            else:
                arr = arr[2:]
        else:
            new_color = get_third_color(first, second)
            arr = [new_color] + arr[2:]
    return arr[0]


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

    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()