# Problem Description
The problem involves calculating the speed of a truck at a given time `t` based on its changing weight as it stops at various barns. The truck starts with an initial velocity `v_0` and an initial weight `w_0`. At each barn, the truck's weight changes by a specified amount, and this change affects the truck's velocity. The goal is to determine the truck's velocity at time `t`.

# Visual Facts
1. The truck starts at time `t = 0` with initial weight `w_0` and initial velocity `v_0`.
2. At each barn (Barn 1, Barn 2, Barn 3, etc.), the truck's weight changes by a specific amount `b_i`.
3. The weight of the truck at time `t = i` is given by the formula: `w_i = w_(i-1) + b_i`.
4. The velocity of the truck at time `t = i` is given by the formula: `V_i = V_0 * w_0 / w_i`.

# Visual Patterns
1. The weight of the truck at each barn is cumulative, meaning it is the sum of the initial weight and all the weight changes up to that barn.
2. The velocity of the truck is inversely proportional to its weight at any given time. As the weight increases, the velocity decreases.
3. The formula for the velocity at any time `t = i` can be derived from the initial velocity and weight, adjusted by the cumulative weight changes up to that time.

# Solution
def solution(v_0: int, w_0: int, t: int, barns: list[int]) -> int:
    """
    Calculates the value of v at time t based on the given pattern.

    Parameters:
        v_0 (int): Initial value of v
        w_0 (int): Initial value of w
        t (int): Target time at which to calculate v
        barns (list[int]): Points in time where changes occur

    Returns:
        int: Value of v at time t (v_t)
    """
    left_weight = w_0
    velocity = v_0
    for i in range(1,t+1):
        weight = barns[i-1]
        left_weight += weight
        velocity = int(v_0 * w_0 / left_weight)
    return velocity


# Test Script
def test():
    test_cases = [
        (10, 15, 0, [3,2,1,6], 10),
        (10, 15, 1, [3,2,1,6], 8),
        (10, 15, 2, [3,2,1,6], 7),
        (10, 15, 3, [3,2,1,6], 7),
        (10, 15, 4, [3,2,1,6], 5),
        (10, 15, 5, [3,2,1,6, 2], 5),
        (15, 25, 0, [4,5,3], 15),
        (15, 25, 1, [4,5,3], 12),
        (15, 25, 2, [4,5,3], 11),
        (15, 25, 3, [4,5,3], 10),
    ]
    for v_0, w_0, t, barns, expected_output in test_cases:
        try:
            output = solution(v_0, w_0, t, barns)
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`v_0`: {v_0}\n"
                f"`w_0`: {w_0}\n" 
                f"`t`: {t}\n"
                f"`barns`: {barns}\n\n"
                f"Exception: '{str(e)}'"
            )
            assert False, error_message
            
        if output != expected_output:
            error_message = (
                f"The following Test Case failed:\n"
                f"`v_0`: {v_0}\n"
                f"`w_0`: {w_0}\n"
                f"`t`: {t}\n" 
                f"`barns`: {barns}\n\n"
                f"Actual Output: {output}\n"
                f"Expected Output: {expected_output}"
            )
            assert False, error_message

test()