Thread livelock detection
Your task
A set of threads is in a livelock if they keep yielding to each other forever without progress. Model each thread's behaviour as a function over a global 'state' integer: transitions is a list of [thread_id, from_state, to_state]. Starting from a given initial state, a deterministic round-robin runtime repeatedly: looks at the current state, finds the FIRST transition (in list order) whose from_state matches, applies it (state := to_state), and continues. Detect whether the system livelocks (enters an infinite loop of state changes) or eventually halts (reaches a state with no applicable transition). Return True if it livelocks, False if it halts.
Examples
detect_livelock(transitions: list[list[int]], initial_state: int) -> boolExample 1
Input
detect_livelock([[0, 1, 2], [1, 2, 1]], 1)Output
True