Reliability algorithms
When the circuit opens
Locate the first point at which consecutive failures would open a simplified circuit breaker.
In production
Circuit breakers open on consecutive failures, not lifetime totals. Counting the wrong thing trips early or never.
What it must return
Return the index where the consecutive failure streak first reaches threshold, or the refusal the examples use when it never does.
- outcomes contains booleans: True is success, False is failure. threshold is a positive integer. Return the zero-based index of the first threshold-length failure streak, or None. Success resets the streak.
- Do not mutate input values. Use the Python standard library only.
Edge cases
- A success resets the streak to zero.
- Total failure count is not the streak.
- Threshold is consecutive outcomes.
Signature
opening_index(outcomes, threshold)Hints
Second hint
A partial sketch
The reference solution opens after the last hint.
Loading editor…
Consecutive failures
outcomes
[ false, true, false, false ]
threshold
2
Expected
3
Each run uses a fresh Python runtime in this browser, with a 3-second limit and a Stop button. The first run downloads the runtime. 0 of 10 in Reliability algorithms passed in Python on this device.