# Problem Description
The problem requires us to determine if an element at a given index in a list of integers is "valid" based on a specific rule. The rule involves performing a modulo operation between the element and another element in the list. If the result of the modulo operation is greater than zero, the element is considered valid; otherwise, it is invalid. The specific rules for selecting the divisor for the modulo operation depend on the position of the element in the list.

# Visual Facts
1. **General Rule**:
   - For the first element (`A[0]`), the divisor is the last element (`A[n]`).
   - For any other element (`A[i]`), the divisor is the previous element (`A[i-1]`).
   - An element is valid if the result of the modulo operation is greater than zero.

2. **Example 1**:
   - List: [3, 1, 4, 2, 2, 7]
   - Validity checks:
     - 3 % 7 > 0 → VALID
     - 1 % 3 > 0 → VALID
     - 4 % 1 = 0 → INVALID
     - 2 % 4 > 0 → VALID
     - 2 % 2 = 0 → INVALID
     - 7 % 2 > 0 → VALID

3. **Example 2**:
   - List: [3, 7, 2, 4, 6, 5, 3]
   - Validity checks:
     - 3 % 3 = 0 → INVALID
     - 7 % 3 > 0 → VALID
     - 2 % 7 > 0 → VALID
     - 4 % 2 = 0 → INVALID
     - 6 % 4 > 0 → VALID
     - 5 % 6 > 0 → VALID
     - 3 % 5 > 0 → VALID

# Visual Patterns
1. **Modulo Operation**:
   - The modulo operation is used to determine the validity of an element.
   - The result of the modulo operation must be greater than zero for the element to be valid.

2. **Divisor Selection**:
   - For the first element in the list, the divisor is the last element.
   - For all other elements, the divisor is the previous element in the list.

3. **Validity Condition**:
   - An element is valid if the result of the modulo operation is greater than zero.
   - An element is invalid if the result of the modulo operation is zero.


# Solution
from typing import List

def solution(nums: List[int], idx: int) -> bool:
    """
    Determines if the element at the given index in the list is valid based on the specified pattern.
    Parameters:
        nums (List[int]): the list of numbers.
        idx (int): Zero-based index of the element to check.

    Returns:
        bool: True if the element is valid, False otherwise.
    """
    if idx != 0:
        return True if nums[idx] % nums[idx - 1] != 0 else False
    else:
        return True if nums[idx] % nums[-1] != 0 else False



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

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

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

test()