# Problem Description
This is a binary array manipulation problem where we need to:
1. Take a binary array (containing only 0s and 1s) and a chosen index position
2. Perform some operation on all elements except the chosen position
3. Return the transformed array maintaining the same length as input

# Visual Facts
1. Two examples are shown in the image
2. Example 1:
   - Input array: [1,0,1,0,1,1]
   - Chosen index has value 0
   - Output array: [0,0,1,0,1,1]

3. Example 2:
   - Input array: [1,1,0,1,0,1,0,1]
   - Chosen index has value 1
   - Output array: [0,0,1,1,1,0,1,0]

4. The word "XOR CHOSEN" appears in both examples with arrows pointing down
5. The chosen position is highlighted in orange
6. The chosen element remains unchanged in the output

# Visual Patterns
1. Element Preservation:
   - The value at the chosen index remains unchanged in the output array

2. XOR Operation Pattern:
   - For all positions except the chosen index, the output is calculated as:
   output[i] = input[i] XOR input[chosen_index]
   
3. Mathematical Rules:
   - When chosen value is 0:
     * 1 XOR 0 = 1
     * 0 XOR 0 = 0
   - When chosen value is 1:
     * 1 XOR 1 = 0
     * 0 XOR 1 = 1


# Solution
from typing import List

def solution(bin_array: List[int], chosen: int) -> List[int]:
    """
    Manipulates a binary array based on the selected index position.

    Parameters:
        bin_array (List[int]): A binary array containing only 0s and 1s
        chosen (int): Zero-based index of the chosen cell

    Returns:
        List[int]: The manipulated binary array
    """
    chosen_value = bin_array[chosen]
    result = []
    for i in range(len(bin_array)):
        if i == chosen:
            result.append(chosen_value)
        else:
            result.append(bin_array[i] ^ chosen_value)
    return result


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

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

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

test()