Your question is Simulate State Transitions With Current Time. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Applied Intuition simulation components may need to model a binary vehicle or sensor signal that alternates between 0 and 1. Implement a deterministic simulation of the signal states observed from the current system time through a requested duration.
Use the current system time in milliseconds as the simulation anchor, equivalent to Java's System.currentTimeMillis(). Do not sleep or wait in the function. Instead, calculate which state is active at each transition instant.
A transition occurs every interval_ms, beginning at offset 0. Include the state at offset 0 and every transition whose offset is at most duration_ms. The state toggles after each interval. Return only the sequence of states, in chronological order.
Implement simulate_binary_signal(duration_ms, interval_ms, initial_state). The inputs are nonnegative integer duration and positive integer interval values, plus an initial state of 0 or 1. Return a list of integers containing the signal state at each transition instant.
def simulate_binary_signal(duration_ms, interval_ms, initial_state):