broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    C = x['cycle']
    sp = x['splits']
    y, r = x['yellow'], x['red']
    if sum(s for _, s in sp) != C:
        return 'bad-splits'
    lc = (x['master'] - x['offset']) % C
    if x['ref'] == 'end':
        lc = (lc + sp[0][1] - y - r) % C
    start = 0
    for ph, s in sp:
        ge = start + s - y - r
        if lc < ge:
            return [ph, 'green', ge - lc]
        if lc < ge + y:
            return [ph, 'yellow', ge + y - lc]
        if lc < start + s:
            return [ph, 'red', start + s - lc]
        start = s
    return ['free', 'dark', 0]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 80, 'offset': 70, 'master': 10, 'splits': [[2, 50], [4, 30]], 'yellow': 3, 'red': 2, 'ref': 'begin'}, [2, 'green', 25]), ({'cycle': 75, 'offset': 33, 'master': 335, 'splits': [[2, 35], [4, 40]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, [2, 'green', 27]), ({'cycle': 58, 'offset': 7, 'master': 869, 'splits': [[2, 13], [4, 31], [6, 14]], 'yellow': 4, 'red': 2, 'ref': 'end'}, [6, 'red', 1]), ({'cycle': 90, 'offset': 30, 'master': 45, 'splits': [[2, 40], [4, 25], [6, 25]], 'yellow': 4, 'red': 1, 'ref': 'end'}, [4, 'green', 10]), ({'cycle': 100, 'offset': 5, 'master': 3, 'splits': [[2, 50], [4, 30], [8, 25]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, 'bad-splits'), ({'cycle': 97, 'offset': 19, 'master': 312, 'splits': [[2, 36], [4, 31], [6, 35]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, 'bad-splits'), ({'cycle': 104, 'offset': 12, 'master': 419, 'splits': [[2, 35], [4, 31], [6, 38]], 'yellow': 3, 'red': 2, 'ref': 'begin'}, [6, 'green', 4]), ({'cycle': 112, 'offset': 58, 'master': 105, 'splits': [[2, 36], [4, 16], [6, 28], [8, 32]], 'yellow': 3, 'red': 2, 'ref': 'end'}, [6, 'red', 2])], [({'cycle': 55, 'offset': 54, 'master': 609, 'splits': [[2, 33], [4, 22]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, [2, 'green', 22]), ({'cycle': 101, 'offset': 40, 'master': 329, 'splits': [[2, 22], [4, 28], [6, 38], [8, 13]], 'yellow': 3, 'red': 2, 'ref': 'begin'}, [6, 'red', 1]), ({'cycle': 125, 'offset': 85, 'master': 573, 'splits': [[2, 29], [4, 23], [6, 40], [8, 33]], 'yellow': 4, 'red': 1, 'ref': 'begin'}, [8, 'green', 7]), ({'cycle': 100, 'offset': 5, 'master': 3, 'splits': [[2, 50], [4, 30], [8, 25]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, 'bad-splits'), ({'cycle': 80, 'offset': 70, 'master': 10, 'splits': [[2, 50], [4, 30]], 'yellow': 3, 'red': 2, 'ref': 'begin'}, [2, 'green', 25]), ({'cycle': 115, 'offset': 109, 'master': 857, 'splits': [[2, 24], [4, 29], [6, 39], [8, 23]], 'yellow': 3, 'red': 1, 'ref': 'end'}, [6, 'green', 10]), ({'cycle': 90, 'offset': 30, 'master': 45, 'splits': [[2, 40], [4, 25], [6, 25]], 'yellow': 4, 'red': 1, 'ref': 'end'}, [4, 'green', 10]), ({'cycle': 78, 'offset': 52, 'master': 624, 'splits': [[2, 18], [4, 32], [6, 28]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, [4, 'green', 18])], [({'cycle': 63, 'offset': 10, 'master': 656, 'splits': [[2, 34], [4, 29]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, [2, 'green', 12]), ({'cycle': 93, 'offset': 24, 'master': 66, 'splits': [[2, 32], [4, 23], [6, 38]], 'yellow': 3, 'red': 1, 'ref': 'end'}, [6, 'green', 19]), ({'cycle': 92, 'offset': 24, 'master': 289, 'splits': [[2, 19], [4, 20], [6, 39], [8, 14]], 'yellow': 3, 'red': 2, 'ref': 'begin'}, [8, 'green', 6]), ({'cycle': 58, 'offset': 12, 'master': 441, 'splits': [[2, 15], [4, 38]], 'yellow': 3, 'red': 1, 'ref': 'begin'}, 'bad-splits'), ({'cycle': 90, 'offset': 30, 'master': 45, 'splits': [[2, 40], [4, 25], [6, 25]], 'yellow': 4, 'red': 1, 'ref': 'end'}, [4, 'green', 10]), ({'cycle': 100, 'offset': 5, 'master': 3, 'splits': [[2, 50], [4, 30], [8, 25]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, 'bad-splits'), ({'cycle': 82, 'offset': 23, 'master': 673, 'splits': [[2, 38], [4, 28], [6, 16]], 'yellow': 4, 'red': 1, 'ref': 'begin'}, [6, 'green', 1]), ({'cycle': 80, 'offset': 70, 'master': 10, 'splits': [[2, 50], [4, 30]], 'yellow': 3, 'red': 2, 'ref': 'begin'}, [2, 'green', 25])], [({'cycle': 96, 'offset': 42, 'master': 942, 'splits': [[2, 39], [4, 25], [6, 22], [8, 15]], 'yellow': 3, 'red': 1, 'ref': 'end'}, 'bad-splits'), ({'cycle': 90, 'offset': 30, 'master': 45, 'splits': [[2, 40], [4, 25], [6, 25]], 'yellow': 4, 'red': 1, 'ref': 'end'}, [4, 'green', 10]), ({'cycle': 67, 'offset': 65, 'master': 64, 'splits': [[2, 21], [4, 33], [6, 13]], 'yellow': 4, 'red': 1, 'ref': 'begin'}, [6, 'red', 1]), ({'cycle': 132, 'offset': 4, 'master': 870, 'splits': [[2, 27], [4, 35], [6, 39], [8, 31]], 'yellow': 4, 'red': 1, 'ref': 'begin'}, [6, 'green', 22]), ({'cycle': 64, 'offset': 6, 'master': 411, 'splits': [[2, 22], [4, 16], [6, 13], [8, 13]], 'yellow': 3, 'red': 2, 'ref': 'begin'}, [2, 'red', 1]), ({'cycle': 100, 'offset': 5, 'master': 3, 'splits': [[2, 50], [4, 30], [8, 25]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, 'bad-splits'), ({'cycle': 58, 'offset': 42, 'master': 894, 'splits': [[2, 16], [4, 17], [6, 25]], 'yellow': 4, 'red': 1, 'ref': 'begin'}, [6, 'green', 13]), ({'cycle': 80, 'offset': 70, 'master': 10, 'splits': [[2, 50], [4, 30]], 'yellow': 3, 'red': 2, 'ref': 'begin'}, [2, 'green', 25])], [({'cycle': 99, 'offset': 85, 'master': 843, 'splits': [[2, 25], [4, 40], [6, 34]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, [6, 'green', 28]), ({'cycle': 80, 'offset': 70, 'master': 10, 'splits': [[2, 50], [4, 30]], 'yellow': 3, 'red': 2, 'ref': 'begin'}, [2, 'green', 25]), ({'cycle': 120, 'offset': 49, 'master': 612, 'splits': [[2, 34], [4, 36], [6, 26], [8, 24]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, [6, 'green', 7]), ({'cycle': 100, 'offset': 5, 'master': 3, 'splits': [[2, 50], [4, 30], [8, 25]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, 'bad-splits'), ({'cycle': 40, 'offset': 17, 'master': 388, 'splits': [[2, 24], [4, 16]], 'yellow': 4, 'red': 2, 'ref': 'end'}, [4, 'green', 5]), ({'cycle': 90, 'offset': 30, 'master': 45, 'splits': [[2, 40], [4, 25], [6, 25]], 'yellow': 4, 'red': 1, 'ref': 'end'}, [4, 'green', 10]), ({'cycle': 63, 'offset': 11, 'master': 608, 'splits': [[2, 35], [4, 12], [6, 16]], 'yellow': 3, 'red': 1, 'ref': 'begin'}, [2, 'green', 1]), ({'cycle': 99, 'offset': 65, 'master': 228, 'splits': [[2, 22], [4, 29], [6, 15], [8, 33]], 'yellow': 4, 'red': 1, 'ref': 'begin'}, [6, 'yellow', 1])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    C = x['cycle']
    sp = x['splits']
    y, r = x['yellow'], x['red']
    if sum(s for _, s in sp) != C:
        return 'bad-splits'
    lc = (x['master'] - x['offset']) % C
    if x['ref'] == 'end':
        lc = (lc + sp[0][1] - y - r) % C
    start = 0
    for ph, s in sp:
        ge = start + s - y - r
        if lc < ge:
            return [ph, 'green', ge - lc]
        if lc < ge + y:
            return [ph, 'yellow', ge + y - lc]
        if lc < start + s:
            return [ph, 'red', start + s - lc]
        start += s - y - r
    return ['free', 'dark', 0]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 80, 'offset': 70, 'master': 10, 'splits': [[2, 50], [4, 30]], 'yellow': 3, 'red': 2, 'ref': 'begin'}, [2, 'green', 25]), ({'cycle': 75, 'offset': 33, 'master': 335, 'splits': [[2, 35], [4, 40]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, [2, 'green', 27]), ({'cycle': 58, 'offset': 7, 'master': 869, 'splits': [[2, 13], [4, 31], [6, 14]], 'yellow': 4, 'red': 2, 'ref': 'end'}, [6, 'red', 1]), ({'cycle': 90, 'offset': 30, 'master': 45, 'splits': [[2, 40], [4, 25], [6, 25]], 'yellow': 4, 'red': 1, 'ref': 'end'}, [4, 'green', 10]), ({'cycle': 100, 'offset': 5, 'master': 3, 'splits': [[2, 50], [4, 30], [8, 25]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, 'bad-splits'), ({'cycle': 97, 'offset': 19, 'master': 312, 'splits': [[2, 36], [4, 31], [6, 35]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, 'bad-splits'), ({'cycle': 104, 'offset': 12, 'master': 419, 'splits': [[2, 35], [4, 31], [6, 38]], 'yellow': 3, 'red': 2, 'ref': 'begin'}, [6, 'green', 4]), ({'cycle': 112, 'offset': 58, 'master': 105, 'splits': [[2, 36], [4, 16], [6, 28], [8, 32]], 'yellow': 3, 'red': 2, 'ref': 'end'}, [6, 'red', 2])], [({'cycle': 55, 'offset': 54, 'master': 609, 'splits': [[2, 33], [4, 22]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, [2, 'green', 22]), ({'cycle': 101, 'offset': 40, 'master': 329, 'splits': [[2, 22], [4, 28], [6, 38], [8, 13]], 'yellow': 3, 'red': 2, 'ref': 'begin'}, [6, 'red', 1]), ({'cycle': 125, 'offset': 85, 'master': 573, 'splits': [[2, 29], [4, 23], [6, 40], [8, 33]], 'yellow': 4, 'red': 1, 'ref': 'begin'}, [8, 'green', 7]), ({'cycle': 100, 'offset': 5, 'master': 3, 'splits': [[2, 50], [4, 30], [8, 25]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, 'bad-splits'), ({'cycle': 80, 'offset': 70, 'master': 10, 'splits': [[2, 50], [4, 30]], 'yellow': 3, 'red': 2, 'ref': 'begin'}, [2, 'green', 25]), ({'cycle': 115, 'offset': 109, 'master': 857, 'splits': [[2, 24], [4, 29], [6, 39], [8, 23]], 'yellow': 3, 'red': 1, 'ref': 'end'}, [6, 'green', 10]), ({'cycle': 90, 'offset': 30, 'master': 45, 'splits': [[2, 40], [4, 25], [6, 25]], 'yellow': 4, 'red': 1, 'ref': 'end'}, [4, 'green', 10]), ({'cycle': 78, 'offset': 52, 'master': 624, 'splits': [[2, 18], [4, 32], [6, 28]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, [4, 'green', 18])], [({'cycle': 63, 'offset': 10, 'master': 656, 'splits': [[2, 34], [4, 29]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, [2, 'green', 12]), ({'cycle': 93, 'offset': 24, 'master': 66, 'splits': [[2, 32], [4, 23], [6, 38]], 'yellow': 3, 'red': 1, 'ref': 'end'}, [6, 'green', 19]), ({'cycle': 92, 'offset': 24, 'master': 289, 'splits': [[2, 19], [4, 20], [6, 39], [8, 14]], 'yellow': 3, 'red': 2, 'ref': 'begin'}, [8, 'green', 6]), ({'cycle': 58, 'offset': 12, 'master': 441, 'splits': [[2, 15], [4, 38]], 'yellow': 3, 'red': 1, 'ref': 'begin'}, 'bad-splits'), ({'cycle': 90, 'offset': 30, 'master': 45, 'splits': [[2, 40], [4, 25], [6, 25]], 'yellow': 4, 'red': 1, 'ref': 'end'}, [4, 'green', 10]), ({'cycle': 100, 'offset': 5, 'master': 3, 'splits': [[2, 50], [4, 30], [8, 25]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, 'bad-splits'), ({'cycle': 82, 'offset': 23, 'master': 673, 'splits': [[2, 38], [4, 28], [6, 16]], 'yellow': 4, 'red': 1, 'ref': 'begin'}, [6, 'green', 1]), ({'cycle': 80, 'offset': 70, 'master': 10, 'splits': [[2, 50], [4, 30]], 'yellow': 3, 'red': 2, 'ref': 'begin'}, [2, 'green', 25])], [({'cycle': 96, 'offset': 42, 'master': 942, 'splits': [[2, 39], [4, 25], [6, 22], [8, 15]], 'yellow': 3, 'red': 1, 'ref': 'end'}, 'bad-splits'), ({'cycle': 90, 'offset': 30, 'master': 45, 'splits': [[2, 40], [4, 25], [6, 25]], 'yellow': 4, 'red': 1, 'ref': 'end'}, [4, 'green', 10]), ({'cycle': 67, 'offset': 65, 'master': 64, 'splits': [[2, 21], [4, 33], [6, 13]], 'yellow': 4, 'red': 1, 'ref': 'begin'}, [6, 'red', 1]), ({'cycle': 132, 'offset': 4, 'master': 870, 'splits': [[2, 27], [4, 35], [6, 39], [8, 31]], 'yellow': 4, 'red': 1, 'ref': 'begin'}, [6, 'green', 22]), ({'cycle': 64, 'offset': 6, 'master': 411, 'splits': [[2, 22], [4, 16], [6, 13], [8, 13]], 'yellow': 3, 'red': 2, 'ref': 'begin'}, [2, 'red', 1]), ({'cycle': 100, 'offset': 5, 'master': 3, 'splits': [[2, 50], [4, 30], [8, 25]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, 'bad-splits'), ({'cycle': 58, 'offset': 42, 'master': 894, 'splits': [[2, 16], [4, 17], [6, 25]], 'yellow': 4, 'red': 1, 'ref': 'begin'}, [6, 'green', 13]), ({'cycle': 80, 'offset': 70, 'master': 10, 'splits': [[2, 50], [4, 30]], 'yellow': 3, 'red': 2, 'ref': 'begin'}, [2, 'green', 25])], [({'cycle': 99, 'offset': 85, 'master': 843, 'splits': [[2, 25], [4, 40], [6, 34]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, [6, 'green', 28]), ({'cycle': 80, 'offset': 70, 'master': 10, 'splits': [[2, 50], [4, 30]], 'yellow': 3, 'red': 2, 'ref': 'begin'}, [2, 'green', 25]), ({'cycle': 120, 'offset': 49, 'master': 612, 'splits': [[2, 34], [4, 36], [6, 26], [8, 24]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, [6, 'green', 7]), ({'cycle': 100, 'offset': 5, 'master': 3, 'splits': [[2, 50], [4, 30], [8, 25]], 'yellow': 4, 'red': 2, 'ref': 'begin'}, 'bad-splits'), ({'cycle': 40, 'offset': 17, 'master': 388, 'splits': [[2, 24], [4, 16]], 'yellow': 4, 'red': 2, 'ref': 'end'}, [4, 'green', 5]), ({'cycle': 90, 'offset': 30, 'master': 45, 'splits': [[2, 40], [4, 25], [6, 25]], 'yellow': 4, 'red': 1, 'ref': 'end'}, [4, 'green', 10]), ({'cycle': 63, 'offset': 11, 'master': 608, 'splits': [[2, 35], [4, 12], [6, 16]], 'yellow': 3, 'red': 1, 'ref': 'begin'}, [2, 'green', 1]), ({'cycle': 99, 'offset': 65, 'master': 228, 'splits': [[2, 22], [4, 29], [6, 15], [8, 33]], 'yellow': 4, 'red': 1, 'ref': 'begin'}, [6, 'yellow', 1])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Coordinated local cycle timer returns a wrong result when split start accumulates green only.

Input {cycle, offset, master, splits: [[phase, split s]] in sequence starting with the coordinated phase, yellow, red, ref}. Splits must sum to the cycle, else 'bad-splits'. Local time = (master - offset) mod cycle, where the offset marks the start of coordinated green (ref 'begin') or the end of coordinated green (ref 'end'). Each split is green then yellow then all-red. Return [phase, interval, seconds remaining].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    C = x['cycle']
    e = (x['current_offset'] - x['target_offset']) % C
    if e == 0:
        return []
    L = C * x['lengthen_pct'] // 100
    S = C * x['shorten_pct'] // 100
    nl = -(-e // L)
    ns = -(-(C - e) // S)
    if nl <= ns:
        amt, step, sign = e, L, 1
    else:
        amt, step, sign = C - e, S, -1
    out = []
    while amt > 0:
        d = min(step, amt)
        out.append(C + sign * d)
        amt -= d
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 80, 'current_offset': 13, 'target_offset': 43, 'lengthen_pct': 10, 'shorten_pct': 20}, [88, 88, 88, 86]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 90, 'current_offset': 57, 'target_offset': 57, 'lengthen_pct': 25, 'shorten_pct': 17}, []), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 120, 'current_offset': 50, 'target_offset': 46, 'lengthen_pct': 10, 'shorten_pct': 17}, [116]), ({'cycle': 110, 'current_offset': 65, 'target_offset': 65, 'lengthen_pct': 25, 'shorten_pct': 20}, []), ({'cycle': 90, 'current_offset': 3, 'target_offset': 3, 'lengthen_pct': 20, 'shorten_pct': 20}, [])], [({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 90, 'current_offset': 60, 'target_offset': 15, 'lengthen_pct': 20, 'shorten_pct': 13}, [108, 108, 99]), ({'cycle': 150, 'current_offset': 87, 'target_offset': 6, 'lengthen_pct': 20, 'shorten_pct': 17}, [180, 180, 159]), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 150, 'current_offset': 116, 'target_offset': 41, 'lengthen_pct': 25, 'shorten_pct': 17}, [187, 187, 151]), ({'cycle': 60, 'current_offset': 49, 'target_offset': 49, 'lengthen_pct': 10, 'shorten_pct': 10}, []), ({'cycle': 60, 'current_offset': 29, 'target_offset': 36, 'lengthen_pct': 25, 'shorten_pct': 17}, [67])], [({'cycle': 140, 'current_offset': 36, 'target_offset': 36, 'lengthen_pct': 10, 'shorten_pct': 10}, []), ({'cycle': 100, 'current_offset': 57, 'target_offset': 57, 'lengthen_pct': 25, 'shorten_pct': 20}, []), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 140, 'current_offset': 17, 'target_offset': 133, 'lengthen_pct': 10, 'shorten_pct': 17}, [117, 139]), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 140, 'current_offset': 98, 'target_offset': 45, 'lengthen_pct': 17, 'shorten_pct': 13}, [122, 122, 123]), ({'cycle': 140, 'current_offset': 87, 'target_offset': 17, 'lengthen_pct': 10, 'shorten_pct': 17}, [117, 117, 117, 139])], [({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 110, 'current_offset': 75, 'target_offset': 20, 'lengthen_pct': 10, 'shorten_pct': 10}, [121, 121, 121, 121, 121]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 150, 'current_offset': 79, 'target_offset': 79, 'lengthen_pct': 17, 'shorten_pct': 20}, []), ({'cycle': 150, 'current_offset': 127, 'target_offset': 28, 'lengthen_pct': 10, 'shorten_pct': 13}, [165, 165, 165, 156]), ({'cycle': 130, 'current_offset': 28, 'target_offset': 93, 'lengthen_pct': 20, 'shorten_pct': 17}, [156, 156, 143]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 150, 'current_offset': 107, 'target_offset': 141, 'lengthen_pct': 17, 'shorten_pct': 20}, [175, 159])], [({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 100, 'current_offset': 71, 'target_offset': 71, 'lengthen_pct': 10, 'shorten_pct': 10}, []), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 150, 'current_offset': 86, 'target_offset': 11, 'lengthen_pct': 20, 'shorten_pct': 20}, [180, 180, 165]), ({'cycle': 110, 'current_offset': 1, 'target_offset': 55, 'lengthen_pct': 25, 'shorten_pct': 13}, [137, 137]), ({'cycle': 90, 'current_offset': 46, 'target_offset': 8, 'lengthen_pct': 20, 'shorten_pct': 13}, [108, 108, 106]), ({'cycle': 90, 'current_offset': 88, 'target_offset': 43, 'lengthen_pct': 17, 'shorten_pct': 10}, [105, 105, 105])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    C = x['cycle']
    e = abs(x['target_offset'] - x['current_offset'])
    if e == 0:
        return []
    L = C * x['lengthen_pct'] // 100
    S = C * x['shorten_pct'] // 100
    nl = -(-e // L)
    ns = -(-(C - e) // S)
    if nl <= ns:
        amt, step, sign = e, L, 1
    else:
        amt, step, sign = C - e, S, -1
    out = []
    while amt > 0:
        d = min(step, amt)
        out.append(C + sign * d)
        amt -= d
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 80, 'current_offset': 13, 'target_offset': 43, 'lengthen_pct': 10, 'shorten_pct': 20}, [88, 88, 88, 86]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 90, 'current_offset': 57, 'target_offset': 57, 'lengthen_pct': 25, 'shorten_pct': 17}, []), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 120, 'current_offset': 50, 'target_offset': 46, 'lengthen_pct': 10, 'shorten_pct': 17}, [116]), ({'cycle': 110, 'current_offset': 65, 'target_offset': 65, 'lengthen_pct': 25, 'shorten_pct': 20}, []), ({'cycle': 90, 'current_offset': 3, 'target_offset': 3, 'lengthen_pct': 20, 'shorten_pct': 20}, [])], [({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 90, 'current_offset': 60, 'target_offset': 15, 'lengthen_pct': 20, 'shorten_pct': 13}, [108, 108, 99]), ({'cycle': 150, 'current_offset': 87, 'target_offset': 6, 'lengthen_pct': 20, 'shorten_pct': 17}, [180, 180, 159]), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 150, 'current_offset': 116, 'target_offset': 41, 'lengthen_pct': 25, 'shorten_pct': 17}, [187, 187, 151]), ({'cycle': 60, 'current_offset': 49, 'target_offset': 49, 'lengthen_pct': 10, 'shorten_pct': 10}, []), ({'cycle': 60, 'current_offset': 29, 'target_offset': 36, 'lengthen_pct': 25, 'shorten_pct': 17}, [67])], [({'cycle': 140, 'current_offset': 36, 'target_offset': 36, 'lengthen_pct': 10, 'shorten_pct': 10}, []), ({'cycle': 100, 'current_offset': 57, 'target_offset': 57, 'lengthen_pct': 25, 'shorten_pct': 20}, []), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 140, 'current_offset': 17, 'target_offset': 133, 'lengthen_pct': 10, 'shorten_pct': 17}, [117, 139]), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 140, 'current_offset': 98, 'target_offset': 45, 'lengthen_pct': 17, 'shorten_pct': 13}, [122, 122, 123]), ({'cycle': 140, 'current_offset': 87, 'target_offset': 17, 'lengthen_pct': 10, 'shorten_pct': 17}, [117, 117, 117, 139])], [({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 110, 'current_offset': 75, 'target_offset': 20, 'lengthen_pct': 10, 'shorten_pct': 10}, [121, 121, 121, 121, 121]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 150, 'current_offset': 79, 'target_offset': 79, 'lengthen_pct': 17, 'shorten_pct': 20}, []), ({'cycle': 150, 'current_offset': 127, 'target_offset': 28, 'lengthen_pct': 10, 'shorten_pct': 13}, [165, 165, 165, 156]), ({'cycle': 130, 'current_offset': 28, 'target_offset': 93, 'lengthen_pct': 20, 'shorten_pct': 17}, [156, 156, 143]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 150, 'current_offset': 107, 'target_offset': 141, 'lengthen_pct': 17, 'shorten_pct': 20}, [175, 159])], [({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 100, 'current_offset': 71, 'target_offset': 71, 'lengthen_pct': 10, 'shorten_pct': 10}, []), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 150, 'current_offset': 86, 'target_offset': 11, 'lengthen_pct': 20, 'shorten_pct': 20}, [180, 180, 165]), ({'cycle': 110, 'current_offset': 1, 'target_offset': 55, 'lengthen_pct': 25, 'shorten_pct': 13}, [137, 137]), ({'cycle': 90, 'current_offset': 46, 'target_offset': 8, 'lengthen_pct': 20, 'shorten_pct': 13}, [108, 108, 106]), ({'cycle': 90, 'current_offset': 88, 'target_offset': 43, 'lengthen_pct': 17, 'shorten_pct': 10}, [105, 105, 105])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Shortway offset transition returns a wrong result when the offset error is computed current minus target.

Input {cycle, current_offset, target_offset, lengthen_pct, shorten_pct}. The needed correction e = (target - current) mod cycle can be made by lengthening cycles by a total of e or shortening them by cycle - e. Per-cycle limits are floor(cycle*pct/100). Choose the direction needing fewer cycles (ties lengthen) and front-load the maximum adjustment each cycle. Return the list of transition cycle lengths ([] when already in step).

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    C = x['cycle']
    e = (x['target_offset'] - x['current_offset']) % C
    if e == 0:
        return []
    L = C * x['lengthen_pct'] // 100
    S = C * x['shorten_pct'] // 100
    nl = -(-e // L)
    ns = -(-e // S)
    if nl <= ns:
        amt, step, sign = e, L, 1
    else:
        amt, step, sign = C - e, S, -1
    out = []
    while amt > 0:
        d = min(step, amt)
        out.append(C + sign * d)
        amt -= d
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 70, 'current_offset': 19, 'target_offset': 63, 'lengthen_pct': 20, 'shorten_pct': 10}, [84, 84, 84, 72]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 80, 'current_offset': 71, 'target_offset': 22, 'lengthen_pct': 10, 'shorten_pct': 17}, [88, 88, 88, 87]), ({'cycle': 140, 'current_offset': 46, 'target_offset': 28, 'lengthen_pct': 10, 'shorten_pct': 10}, [126, 136]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 110, 'current_offset': 59, 'target_offset': 33, 'lengthen_pct': 20, 'shorten_pct': 20}, [88, 106]), ({'cycle': 80, 'current_offset': 2, 'target_offset': 61, 'lengthen_pct': 25, 'shorten_pct': 13}, [100, 100, 99])], [({'cycle': 130, 'current_offset': 69, 'target_offset': 17, 'lengthen_pct': 25, 'shorten_pct': 13}, [162, 162, 144]), ({'cycle': 100, 'current_offset': 76, 'target_offset': 99, 'lengthen_pct': 10, 'shorten_pct': 13}, [110, 110, 103]), ({'cycle': 80, 'current_offset': 35, 'target_offset': 9, 'lengthen_pct': 10, 'shorten_pct': 10}, [72, 72, 72, 78]), ({'cycle': 90, 'current_offset': 56, 'target_offset': 42, 'lengthen_pct': 25, 'shorten_pct': 17}, [76]), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 80, 'current_offset': 38, 'target_offset': 3, 'lengthen_pct': 17, 'shorten_pct': 13}, [93, 93, 93, 86])], [({'cycle': 70, 'current_offset': 19, 'target_offset': 15, 'lengthen_pct': 20, 'shorten_pct': 20}, [66]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 120, 'current_offset': 78, 'target_offset': 10, 'lengthen_pct': 10, 'shorten_pct': 17}, [100, 100, 100, 112]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 110, 'current_offset': 65, 'target_offset': 28, 'lengthen_pct': 17, 'shorten_pct': 13}, [96, 96, 101]), ({'cycle': 80, 'current_offset': 21, 'target_offset': 2, 'lengthen_pct': 17, 'shorten_pct': 17}, [67, 74]), ({'cycle': 140, 'current_offset': 139, 'target_offset': 94, 'lengthen_pct': 25, 'shorten_pct': 13}, [175, 175, 165])], [({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 80, 'current_offset': 73, 'target_offset': 46, 'lengthen_pct': 17, 'shorten_pct': 10}, [72, 72, 72, 77]), ({'cycle': 70, 'current_offset': 29, 'target_offset': 68, 'lengthen_pct': 17, 'shorten_pct': 13}, [81, 81, 81, 76]), ({'cycle': 140, 'current_offset': 9, 'target_offset': 97, 'lengthen_pct': 25, 'shorten_pct': 10}, [175, 175, 158]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 150, 'current_offset': 81, 'target_offset': 103, 'lengthen_pct': 10, 'shorten_pct': 20}, [165, 157]), ({'cycle': 60, 'current_offset': 39, 'target_offset': 31, 'lengthen_pct': 25, 'shorten_pct': 17}, [52])], [({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 110, 'current_offset': 10, 'target_offset': 39, 'lengthen_pct': 10, 'shorten_pct': 20}, [121, 121, 117]), ({'cycle': 90, 'current_offset': 85, 'target_offset': 51, 'lengthen_pct': 25, 'shorten_pct': 10}, [112, 112, 102]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 60, 'current_offset': 31, 'target_offset': 24, 'lengthen_pct': 17, 'shorten_pct': 17}, [53]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 60, 'current_offset': 0, 'target_offset': 34, 'lengthen_pct': 17, 'shorten_pct': 13}, [70, 70, 70, 64]), ({'cycle': 150, 'current_offset': 135, 'target_offset': 114, 'lengthen_pct': 17, 'shorten_pct': 13}, [131, 148])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    C = x['cycle']
    e = (x['target_offset'] - x['current_offset']) % C
    if e == 0:
        return []
    L = C * x['lengthen_pct'] // 100
    S = C * x['shorten_pct'] // 100
    nl = -(-e // L)
    ns = -(-(C - e) // L)
    if nl <= ns:
        amt, step, sign = e, L, 1
    else:
        amt, step, sign = C - e, S, -1
    out = []
    while amt > 0:
        d = min(step, amt)
        out.append(C + sign * d)
        amt -= d
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 70, 'current_offset': 19, 'target_offset': 63, 'lengthen_pct': 20, 'shorten_pct': 10}, [84, 84, 84, 72]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 80, 'current_offset': 71, 'target_offset': 22, 'lengthen_pct': 10, 'shorten_pct': 17}, [88, 88, 88, 87]), ({'cycle': 140, 'current_offset': 46, 'target_offset': 28, 'lengthen_pct': 10, 'shorten_pct': 10}, [126, 136]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 110, 'current_offset': 59, 'target_offset': 33, 'lengthen_pct': 20, 'shorten_pct': 20}, [88, 106]), ({'cycle': 80, 'current_offset': 2, 'target_offset': 61, 'lengthen_pct': 25, 'shorten_pct': 13}, [100, 100, 99])], [({'cycle': 130, 'current_offset': 69, 'target_offset': 17, 'lengthen_pct': 25, 'shorten_pct': 13}, [162, 162, 144]), ({'cycle': 100, 'current_offset': 76, 'target_offset': 99, 'lengthen_pct': 10, 'shorten_pct': 13}, [110, 110, 103]), ({'cycle': 80, 'current_offset': 35, 'target_offset': 9, 'lengthen_pct': 10, 'shorten_pct': 10}, [72, 72, 72, 78]), ({'cycle': 90, 'current_offset': 56, 'target_offset': 42, 'lengthen_pct': 25, 'shorten_pct': 17}, [76]), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 80, 'current_offset': 38, 'target_offset': 3, 'lengthen_pct': 17, 'shorten_pct': 13}, [93, 93, 93, 86])], [({'cycle': 70, 'current_offset': 19, 'target_offset': 15, 'lengthen_pct': 20, 'shorten_pct': 20}, [66]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 120, 'current_offset': 78, 'target_offset': 10, 'lengthen_pct': 10, 'shorten_pct': 17}, [100, 100, 100, 112]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 110, 'current_offset': 65, 'target_offset': 28, 'lengthen_pct': 17, 'shorten_pct': 13}, [96, 96, 101]), ({'cycle': 80, 'current_offset': 21, 'target_offset': 2, 'lengthen_pct': 17, 'shorten_pct': 17}, [67, 74]), ({'cycle': 140, 'current_offset': 139, 'target_offset': 94, 'lengthen_pct': 25, 'shorten_pct': 13}, [175, 175, 165])], [({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 80, 'current_offset': 73, 'target_offset': 46, 'lengthen_pct': 17, 'shorten_pct': 10}, [72, 72, 72, 77]), ({'cycle': 70, 'current_offset': 29, 'target_offset': 68, 'lengthen_pct': 17, 'shorten_pct': 13}, [81, 81, 81, 76]), ({'cycle': 140, 'current_offset': 9, 'target_offset': 97, 'lengthen_pct': 25, 'shorten_pct': 10}, [175, 175, 158]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 150, 'current_offset': 81, 'target_offset': 103, 'lengthen_pct': 10, 'shorten_pct': 20}, [165, 157]), ({'cycle': 60, 'current_offset': 39, 'target_offset': 31, 'lengthen_pct': 25, 'shorten_pct': 17}, [52])], [({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 110, 'current_offset': 10, 'target_offset': 39, 'lengthen_pct': 10, 'shorten_pct': 20}, [121, 121, 117]), ({'cycle': 90, 'current_offset': 85, 'target_offset': 51, 'lengthen_pct': 25, 'shorten_pct': 10}, [112, 112, 102]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 60, 'current_offset': 31, 'target_offset': 24, 'lengthen_pct': 17, 'shorten_pct': 17}, [53]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 60, 'current_offset': 0, 'target_offset': 34, 'lengthen_pct': 17, 'shorten_pct': 13}, [70, 70, 70, 64]), ({'cycle': 150, 'current_offset': 135, 'target_offset': 114, 'lengthen_pct': 17, 'shorten_pct': 13}, [131, 148])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Shortway offset transition returns a wrong result when shortening cycles are counted against the lengthening distance.

Input {cycle, current_offset, target_offset, lengthen_pct, shorten_pct}. The needed correction e = (target - current) mod cycle can be made by lengthening cycles by a total of e or shortening them by cycle - e. Per-cycle limits are floor(cycle*pct/100). Choose the direction needing fewer cycles (ties lengthen) and front-load the maximum adjustment each cycle. Return the list of transition cycle lengths ([] when already in step).

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    C = x['cycle']
    e = (x['target_offset'] - x['current_offset']) % C
    if e == 0:
        return []
    L = C * x['lengthen_pct'] // 100
    S = C * x['shorten_pct'] // 100
    nl = -(-e // L)
    ns = -(-(C - e) // S)
    if nl < ns:
        amt, step, sign = e, L, 1
    else:
        amt, step, sign = C - e, S, -1
    out = []
    while amt > 0:
        d = min(step, amt)
        out.append(C + sign * d)
        amt -= d
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 60, 'current_offset': 49, 'target_offset': 26, 'lengthen_pct': 20, 'shorten_pct': 13}, [72, 72, 72, 61]), ({'cycle': 150, 'current_offset': 76, 'target_offset': 139, 'lengthen_pct': 20, 'shorten_pct': 20}, [180, 180, 153]), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 100, 'current_offset': 95, 'target_offset': 74, 'lengthen_pct': 10, 'shorten_pct': 10}, [90, 90, 99]), ({'cycle': 140, 'current_offset': 130, 'target_offset': 73, 'lengthen_pct': 20, 'shorten_pct': 17}, [168, 168, 167]), ({'cycle': 60, 'current_offset': 28, 'target_offset': 31, 'lengthen_pct': 17, 'shorten_pct': 13}, [63]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130])], [({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 70, 'current_offset': 5, 'target_offset': 46, 'lengthen_pct': 20, 'shorten_pct': 10}, [84, 84, 83]), ({'cycle': 120, 'current_offset': 24, 'target_offset': 105, 'lengthen_pct': 20, 'shorten_pct': 10}, [144, 144, 144, 129]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 150, 'current_offset': 78, 'target_offset': 16, 'lengthen_pct': 17, 'shorten_pct': 13}, [175, 175, 175, 163]), ({'cycle': 90, 'current_offset': 74, 'target_offset': 23, 'lengthen_pct': 17, 'shorten_pct': 20}, [105, 105, 99]), ({'cycle': 90, 'current_offset': 77, 'target_offset': 35, 'lengthen_pct': 25, 'shorten_pct': 13}, [112, 112, 94])], [({'cycle': 100, 'current_offset': 96, 'target_offset': 58, 'lengthen_pct': 25, 'shorten_pct': 10}, [125, 125, 112]), ({'cycle': 120, 'current_offset': 110, 'target_offset': 48, 'lengthen_pct': 10, 'shorten_pct': 13}, [132, 132, 132, 132, 130]), ({'cycle': 110, 'current_offset': 4, 'target_offset': 71, 'lengthen_pct': 25, 'shorten_pct': 13}, [137, 137, 123]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 150, 'current_offset': 34, 'target_offset': 105, 'lengthen_pct': 17, 'shorten_pct': 20}, [175, 175, 171]), ({'cycle': 90, 'current_offset': 33, 'target_offset': 78, 'lengthen_pct': 25, 'shorten_pct': 17}, [112, 112, 91]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120])], [({'cycle': 90, 'current_offset': 57, 'target_offset': 2, 'lengthen_pct': 10, 'shorten_pct': 20}, [99, 99, 99, 98]), ({'cycle': 110, 'current_offset': 14, 'target_offset': 86, 'lengthen_pct': 25, 'shorten_pct': 10}, [137, 137, 128]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 90, 'current_offset': 13, 'target_offset': 68, 'lengthen_pct': 25, 'shorten_pct': 17}, [112, 112, 101]), ({'cycle': 140, 'current_offset': 52, 'target_offset': 120, 'lengthen_pct': 17, 'shorten_pct': 20}, [163, 163, 162]), ({'cycle': 60, 'current_offset': 16, 'target_offset': 18, 'lengthen_pct': 10, 'shorten_pct': 20}, [62])], [({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 90, 'current_offset': 26, 'target_offset': 75, 'lengthen_pct': 20, 'shorten_pct': 13}, [108, 108, 103]), ({'cycle': 70, 'current_offset': 20, 'target_offset': 49, 'lengthen_pct': 10, 'shorten_pct': 20}, [56, 56, 57]), ({'cycle': 80, 'current_offset': 58, 'target_offset': 37, 'lengthen_pct': 25, 'shorten_pct': 10}, [100, 100, 99]), ({'cycle': 100, 'current_offset': 66, 'target_offset': 1, 'lengthen_pct': 10, 'shorten_pct': 17}, [110, 110, 110, 105]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 60, 'current_offset': 11, 'target_offset': 44, 'lengthen_pct': 17, 'shorten_pct': 13}, [70, 70, 70, 63])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    C = x['cycle']
    e = (x['target_offset'] - x['current_offset']) % C
    if e == 0:
        return []
    L = C * x['lengthen_pct'] // 100
    S = C * x['shorten_pct'] // 100
    nl = -(-e // L)
    ns = -(-(C - e) // S)
    if e <= C - e:
        amt, step, sign = e, L, 1
    else:
        amt, step, sign = C - e, S, -1
    out = []
    while amt > 0:
        d = min(step, amt)
        out.append(C + sign * d)
        amt -= d
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 60, 'current_offset': 49, 'target_offset': 26, 'lengthen_pct': 20, 'shorten_pct': 13}, [72, 72, 72, 61]), ({'cycle': 150, 'current_offset': 76, 'target_offset': 139, 'lengthen_pct': 20, 'shorten_pct': 20}, [180, 180, 153]), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 100, 'current_offset': 95, 'target_offset': 74, 'lengthen_pct': 10, 'shorten_pct': 10}, [90, 90, 99]), ({'cycle': 140, 'current_offset': 130, 'target_offset': 73, 'lengthen_pct': 20, 'shorten_pct': 17}, [168, 168, 167]), ({'cycle': 60, 'current_offset': 28, 'target_offset': 31, 'lengthen_pct': 17, 'shorten_pct': 13}, [63]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130])], [({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 70, 'current_offset': 5, 'target_offset': 46, 'lengthen_pct': 20, 'shorten_pct': 10}, [84, 84, 83]), ({'cycle': 120, 'current_offset': 24, 'target_offset': 105, 'lengthen_pct': 20, 'shorten_pct': 10}, [144, 144, 144, 129]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 150, 'current_offset': 78, 'target_offset': 16, 'lengthen_pct': 17, 'shorten_pct': 13}, [175, 175, 175, 163]), ({'cycle': 90, 'current_offset': 74, 'target_offset': 23, 'lengthen_pct': 17, 'shorten_pct': 20}, [105, 105, 99]), ({'cycle': 90, 'current_offset': 77, 'target_offset': 35, 'lengthen_pct': 25, 'shorten_pct': 13}, [112, 112, 94])], [({'cycle': 100, 'current_offset': 96, 'target_offset': 58, 'lengthen_pct': 25, 'shorten_pct': 10}, [125, 125, 112]), ({'cycle': 120, 'current_offset': 110, 'target_offset': 48, 'lengthen_pct': 10, 'shorten_pct': 13}, [132, 132, 132, 132, 130]), ({'cycle': 110, 'current_offset': 4, 'target_offset': 71, 'lengthen_pct': 25, 'shorten_pct': 13}, [137, 137, 123]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 150, 'current_offset': 34, 'target_offset': 105, 'lengthen_pct': 17, 'shorten_pct': 20}, [175, 175, 171]), ({'cycle': 90, 'current_offset': 33, 'target_offset': 78, 'lengthen_pct': 25, 'shorten_pct': 17}, [112, 112, 91]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120])], [({'cycle': 90, 'current_offset': 57, 'target_offset': 2, 'lengthen_pct': 10, 'shorten_pct': 20}, [99, 99, 99, 98]), ({'cycle': 110, 'current_offset': 14, 'target_offset': 86, 'lengthen_pct': 25, 'shorten_pct': 10}, [137, 137, 128]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 90, 'current_offset': 13, 'target_offset': 68, 'lengthen_pct': 25, 'shorten_pct': 17}, [112, 112, 101]), ({'cycle': 140, 'current_offset': 52, 'target_offset': 120, 'lengthen_pct': 17, 'shorten_pct': 20}, [163, 163, 162]), ({'cycle': 60, 'current_offset': 16, 'target_offset': 18, 'lengthen_pct': 10, 'shorten_pct': 20}, [62])], [({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 90, 'current_offset': 26, 'target_offset': 75, 'lengthen_pct': 20, 'shorten_pct': 13}, [108, 108, 103]), ({'cycle': 70, 'current_offset': 20, 'target_offset': 49, 'lengthen_pct': 10, 'shorten_pct': 20}, [56, 56, 57]), ({'cycle': 80, 'current_offset': 58, 'target_offset': 37, 'lengthen_pct': 25, 'shorten_pct': 10}, [100, 100, 99]), ({'cycle': 100, 'current_offset': 66, 'target_offset': 1, 'lengthen_pct': 10, 'shorten_pct': 17}, [110, 110, 110, 105]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 60, 'current_offset': 11, 'target_offset': 44, 'lengthen_pct': 17, 'shorten_pct': 13}, [70, 70, 70, 63])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Shortway offset transition returns a wrong result when ties between directions pick shortening.

Input {cycle, current_offset, target_offset, lengthen_pct, shorten_pct}. The needed correction e = (target - current) mod cycle can be made by lengthening cycles by a total of e or shortening them by cycle - e. Per-cycle limits are floor(cycle*pct/100). Choose the direction needing fewer cycles (ties lengthen) and front-load the maximum adjustment each cycle. Return the list of transition cycle lengths ([] when already in step).

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    C = x['cycle']
    e = (x['target_offset'] - x['current_offset']) % C
    if e == 0:
        return []
    L = C * x['lengthen_pct'] // 100
    S = -(-C * x['shorten_pct'] // 100)
    nl = -(-e // L)
    ns = -(-(C - e) // S)
    if nl <= ns:
        amt, step, sign = e, L, 1
    else:
        amt, step, sign = C - e, S, -1
    out = []
    while amt > 0:
        d = min(step, amt)
        out.append(C + sign * d)
        amt -= d
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 70, 'current_offset': 47, 'target_offset': 25, 'lengthen_pct': 10, 'shorten_pct': 17}, [59, 59]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 90, 'current_offset': 78, 'target_offset': 67, 'lengthen_pct': 25, 'shorten_pct': 13}, [79]), ({'cycle': 110, 'current_offset': 48, 'target_offset': 34, 'lengthen_pct': 25, 'shorten_pct': 13}, [96]), ({'cycle': 80, 'current_offset': 54, 'target_offset': 32, 'lengthen_pct': 10, 'shorten_pct': 13}, [70, 70, 78]), ({'cycle': 80, 'current_offset': 2, 'target_offset': 66, 'lengthen_pct': 20, 'shorten_pct': 17}, [67, 77]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130])], [({'cycle': 150, 'current_offset': 93, 'target_offset': 41, 'lengthen_pct': 20, 'shorten_pct': 13}, [131, 131, 136]), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 70, 'current_offset': 3, 'target_offset': 56, 'lengthen_pct': 10, 'shorten_pct': 13}, [61, 62]), ({'cycle': 140, 'current_offset': 132, 'target_offset': 106, 'lengthen_pct': 10, 'shorten_pct': 13}, [122, 132]), ({'cycle': 150, 'current_offset': 73, 'target_offset': 8, 'lengthen_pct': 10, 'shorten_pct': 13}, [131, 131, 131, 142]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 90, 'current_offset': 25, 'target_offset': 12, 'lengthen_pct': 20, 'shorten_pct': 20}, [77]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, [])], [({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 130, 'current_offset': 45, 'target_offset': 22, 'lengthen_pct': 25, 'shorten_pct': 17}, [108, 129]), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 140, 'current_offset': 49, 'target_offset': 7, 'lengthen_pct': 20, 'shorten_pct': 13}, [122, 122, 134]), ({'cycle': 130, 'current_offset': 11, 'target_offset': 106, 'lengthen_pct': 20, 'shorten_pct': 13}, [114, 114, 127]), ({'cycle': 70, 'current_offset': 25, 'target_offset': 64, 'lengthen_pct': 10, 'shorten_pct': 17}, [59, 59, 61]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 90, 'current_offset': 40, 'target_offset': 20, 'lengthen_pct': 10, 'shorten_pct': 17}, [75, 85])], [({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 70, 'current_offset': 2, 'target_offset': 34, 'lengthen_pct': 10, 'shorten_pct': 10}, [77, 77, 77, 77, 74]), ({'cycle': 80, 'current_offset': 13, 'target_offset': 76, 'lengthen_pct': 17, 'shorten_pct': 17}, [67, 76]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 120, 'current_offset': 74, 'target_offset': 53, 'lengthen_pct': 20, 'shorten_pct': 13}, [105, 114]), ({'cycle': 90, 'current_offset': 52, 'target_offset': 61, 'lengthen_pct': 20, 'shorten_pct': 13}, [99]), ({'cycle': 130, 'current_offset': 40, 'target_offset': 93, 'lengthen_pct': 10, 'shorten_pct': 17}, [108, 108, 108, 119])], [({'cycle': 70, 'current_offset': 61, 'target_offset': 45, 'lengthen_pct': 20, 'shorten_pct': 17}, [59, 65]), ({'cycle': 150, 'current_offset': 106, 'target_offset': 139, 'lengthen_pct': 10, 'shorten_pct': 10}, [165, 165, 153]), ({'cycle': 140, 'current_offset': 12, 'target_offset': 108, 'lengthen_pct': 25, 'shorten_pct': 17}, [117, 119]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 80, 'current_offset': 12, 'target_offset': 23, 'lengthen_pct': 25, 'shorten_pct': 10}, [91]), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 80, 'current_offset': 56, 'target_offset': 28, 'lengthen_pct': 10, 'shorten_pct': 17}, [67, 67, 78])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    C = x['cycle']
    e = (x['target_offset'] - x['current_offset']) % C
    if e == 0:
        return []
    L = C * x['lengthen_pct'] // 100
    S = round(C * x['shorten_pct'] / 100)
    nl = -(-e // L)
    ns = -(-(C - e) // S)
    if nl <= ns:
        amt, step, sign = e, L, 1
    else:
        amt, step, sign = C - e, S, -1
    out = []
    while amt > 0:
        d = min(step, amt)
        out.append(C + sign * d)
        amt -= d
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 70, 'current_offset': 47, 'target_offset': 25, 'lengthen_pct': 10, 'shorten_pct': 17}, [59, 59]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 90, 'current_offset': 78, 'target_offset': 67, 'lengthen_pct': 25, 'shorten_pct': 13}, [79]), ({'cycle': 110, 'current_offset': 48, 'target_offset': 34, 'lengthen_pct': 25, 'shorten_pct': 13}, [96]), ({'cycle': 80, 'current_offset': 54, 'target_offset': 32, 'lengthen_pct': 10, 'shorten_pct': 13}, [70, 70, 78]), ({'cycle': 80, 'current_offset': 2, 'target_offset': 66, 'lengthen_pct': 20, 'shorten_pct': 17}, [67, 77]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130])], [({'cycle': 150, 'current_offset': 93, 'target_offset': 41, 'lengthen_pct': 20, 'shorten_pct': 13}, [131, 131, 136]), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 70, 'current_offset': 3, 'target_offset': 56, 'lengthen_pct': 10, 'shorten_pct': 13}, [61, 62]), ({'cycle': 140, 'current_offset': 132, 'target_offset': 106, 'lengthen_pct': 10, 'shorten_pct': 13}, [122, 132]), ({'cycle': 150, 'current_offset': 73, 'target_offset': 8, 'lengthen_pct': 10, 'shorten_pct': 13}, [131, 131, 131, 142]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 90, 'current_offset': 25, 'target_offset': 12, 'lengthen_pct': 20, 'shorten_pct': 20}, [77]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, [])], [({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 130, 'current_offset': 45, 'target_offset': 22, 'lengthen_pct': 25, 'shorten_pct': 17}, [108, 129]), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 140, 'current_offset': 49, 'target_offset': 7, 'lengthen_pct': 20, 'shorten_pct': 13}, [122, 122, 134]), ({'cycle': 130, 'current_offset': 11, 'target_offset': 106, 'lengthen_pct': 20, 'shorten_pct': 13}, [114, 114, 127]), ({'cycle': 70, 'current_offset': 25, 'target_offset': 64, 'lengthen_pct': 10, 'shorten_pct': 17}, [59, 59, 61]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 90, 'current_offset': 40, 'target_offset': 20, 'lengthen_pct': 10, 'shorten_pct': 17}, [75, 85])], [({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 70, 'current_offset': 2, 'target_offset': 34, 'lengthen_pct': 10, 'shorten_pct': 10}, [77, 77, 77, 77, 74]), ({'cycle': 80, 'current_offset': 13, 'target_offset': 76, 'lengthen_pct': 17, 'shorten_pct': 17}, [67, 76]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 120, 'current_offset': 74, 'target_offset': 53, 'lengthen_pct': 20, 'shorten_pct': 13}, [105, 114]), ({'cycle': 90, 'current_offset': 52, 'target_offset': 61, 'lengthen_pct': 20, 'shorten_pct': 13}, [99]), ({'cycle': 130, 'current_offset': 40, 'target_offset': 93, 'lengthen_pct': 10, 'shorten_pct': 17}, [108, 108, 108, 119])], [({'cycle': 70, 'current_offset': 61, 'target_offset': 45, 'lengthen_pct': 20, 'shorten_pct': 17}, [59, 65]), ({'cycle': 150, 'current_offset': 106, 'target_offset': 139, 'lengthen_pct': 10, 'shorten_pct': 10}, [165, 165, 153]), ({'cycle': 140, 'current_offset': 12, 'target_offset': 108, 'lengthen_pct': 25, 'shorten_pct': 17}, [117, 119]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 80, 'current_offset': 12, 'target_offset': 23, 'lengthen_pct': 25, 'shorten_pct': 10}, [91]), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 80, 'current_offset': 56, 'target_offset': 28, 'lengthen_pct': 10, 'shorten_pct': 17}, [67, 67, 78])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Shortway offset transition returns a wrong result when the per-cycle shortening limit is rounded up.

Input {cycle, current_offset, target_offset, lengthen_pct, shorten_pct}. The needed correction e = (target - current) mod cycle can be made by lengthening cycles by a total of e or shortening them by cycle - e. Per-cycle limits are floor(cycle*pct/100). Choose the direction needing fewer cycles (ties lengthen) and front-load the maximum adjustment each cycle. Return the list of transition cycle lengths ([] when already in step).

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    C = x['cycle']
    e = (x['target_offset'] - x['current_offset']) % C
    if e == 0:
        return []
    L = C * x['lengthen_pct'] // 100
    S = C * x['shorten_pct'] // 100
    nl = -(-e // L)
    ns = -(-(C - e) // S)
    if nl <= ns:
        amt, step, sign = e, L, 1
    else:
        amt, step, sign = C - e, S, -1
    out = []
    while amt > 0:
        d = step
        out.append(C + sign * d)
        amt -= d
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 90, 'current_offset': 10, 'target_offset': 82, 'lengthen_pct': 17, 'shorten_pct': 20}, [72]), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 90, 'current_offset': 7, 'target_offset': 6, 'lengthen_pct': 25, 'shorten_pct': 20}, [89]), ({'cycle': 80, 'current_offset': 27, 'target_offset': 75, 'lengthen_pct': 20, 'shorten_pct': 17}, [96, 96, 96]), ({'cycle': 130, 'current_offset': 59, 'target_offset': 25, 'lengthen_pct': 17, 'shorten_pct': 10}, [117, 117, 122]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 130, 'current_offset': 77, 'target_offset': 32, 'lengthen_pct': 20, 'shorten_pct': 20}, [104, 111])], [({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 90, 'current_offset': 56, 'target_offset': 74, 'lengthen_pct': 10, 'shorten_pct': 20}, [99, 99]), ({'cycle': 150, 'current_offset': 42, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 10}, [135, 143]), ({'cycle': 70, 'current_offset': 20, 'target_offset': 48, 'lengthen_pct': 17, 'shorten_pct': 13}, [81, 81, 76]), ({'cycle': 140, 'current_offset': 32, 'target_offset': 8, 'lengthen_pct': 25, 'shorten_pct': 13}, [122, 134]), ({'cycle': 60, 'current_offset': 31, 'target_offset': 31, 'lengthen_pct': 25, 'shorten_pct': 20}, []), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130])], [({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 60, 'current_offset': 4, 'target_offset': 57, 'lengthen_pct': 10, 'shorten_pct': 13}, [53]), ({'cycle': 60, 'current_offset': 12, 'target_offset': 14, 'lengthen_pct': 25, 'shorten_pct': 10}, [62]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 100, 'current_offset': 12, 'target_offset': 12, 'lengthen_pct': 17, 'shorten_pct': 20}, []), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 70, 'current_offset': 55, 'target_offset': 56, 'lengthen_pct': 20, 'shorten_pct': 17}, [71]), ({'cycle': 70, 'current_offset': 17, 'target_offset': 4, 'lengthen_pct': 25, 'shorten_pct': 13}, [61, 66])], [({'cycle': 70, 'current_offset': 65, 'target_offset': 12, 'lengthen_pct': 25, 'shorten_pct': 10}, [87]), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 100, 'current_offset': 90, 'target_offset': 89, 'lengthen_pct': 17, 'shorten_pct': 20}, [99]), ({'cycle': 110, 'current_offset': 51, 'target_offset': 51, 'lengthen_pct': 20, 'shorten_pct': 13}, []), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 60, 'current_offset': 47, 'target_offset': 39, 'lengthen_pct': 10, 'shorten_pct': 13}, [53, 59]), ({'cycle': 90, 'current_offset': 25, 'target_offset': 13, 'lengthen_pct': 17, 'shorten_pct': 10}, [81, 87])], [({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 90, 'current_offset': 54, 'target_offset': 43, 'lengthen_pct': 10, 'shorten_pct': 13}, [79]), ({'cycle': 130, 'current_offset': 41, 'target_offset': 22, 'lengthen_pct': 20, 'shorten_pct': 17}, [111]), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 140, 'current_offset': 46, 'target_offset': 86, 'lengthen_pct': 25, 'shorten_pct': 13}, [175, 145]), ({'cycle': 120, 'current_offset': 55, 'target_offset': 69, 'lengthen_pct': 20, 'shorten_pct': 17}, [134]), ({'cycle': 100, 'current_offset': 74, 'target_offset': 84, 'lengthen_pct': 10, 'shorten_pct': 17}, [110]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    C = x['cycle']
    e = (x['target_offset'] - x['current_offset']) % C
    if e == 0:
        return []
    L = C * x['lengthen_pct'] // 100
    S = C * x['shorten_pct'] // 100
    nl = -(-e // L)
    ns = -(-(C - e) // S)
    if nl <= ns:
        amt, step, sign = e, L, 1
    else:
        amt, step, sign = C - e, S, -1
    out = []
    while amt > 0:
        d = -(-amt // -(-amt // step))
        out.append(C + sign * d)
        amt -= d
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 90, 'current_offset': 10, 'target_offset': 82, 'lengthen_pct': 17, 'shorten_pct': 20}, [72]), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 90, 'current_offset': 7, 'target_offset': 6, 'lengthen_pct': 25, 'shorten_pct': 20}, [89]), ({'cycle': 80, 'current_offset': 27, 'target_offset': 75, 'lengthen_pct': 20, 'shorten_pct': 17}, [96, 96, 96]), ({'cycle': 130, 'current_offset': 59, 'target_offset': 25, 'lengthen_pct': 17, 'shorten_pct': 10}, [117, 117, 122]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 130, 'current_offset': 77, 'target_offset': 32, 'lengthen_pct': 20, 'shorten_pct': 20}, [104, 111])], [({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 90, 'current_offset': 56, 'target_offset': 74, 'lengthen_pct': 10, 'shorten_pct': 20}, [99, 99]), ({'cycle': 150, 'current_offset': 42, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 10}, [135, 143]), ({'cycle': 70, 'current_offset': 20, 'target_offset': 48, 'lengthen_pct': 17, 'shorten_pct': 13}, [81, 81, 76]), ({'cycle': 140, 'current_offset': 32, 'target_offset': 8, 'lengthen_pct': 25, 'shorten_pct': 13}, [122, 134]), ({'cycle': 60, 'current_offset': 31, 'target_offset': 31, 'lengthen_pct': 25, 'shorten_pct': 20}, []), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130])], [({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 60, 'current_offset': 4, 'target_offset': 57, 'lengthen_pct': 10, 'shorten_pct': 13}, [53]), ({'cycle': 60, 'current_offset': 12, 'target_offset': 14, 'lengthen_pct': 25, 'shorten_pct': 10}, [62]), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 100, 'current_offset': 12, 'target_offset': 12, 'lengthen_pct': 17, 'shorten_pct': 20}, []), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 70, 'current_offset': 55, 'target_offset': 56, 'lengthen_pct': 20, 'shorten_pct': 17}, [71]), ({'cycle': 70, 'current_offset': 17, 'target_offset': 4, 'lengthen_pct': 25, 'shorten_pct': 13}, [61, 66])], [({'cycle': 70, 'current_offset': 65, 'target_offset': 12, 'lengthen_pct': 25, 'shorten_pct': 10}, [87]), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 100, 'current_offset': 90, 'target_offset': 89, 'lengthen_pct': 17, 'shorten_pct': 20}, [99]), ({'cycle': 110, 'current_offset': 51, 'target_offset': 51, 'lengthen_pct': 20, 'shorten_pct': 13}, []), ({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130]), ({'cycle': 60, 'current_offset': 47, 'target_offset': 39, 'lengthen_pct': 10, 'shorten_pct': 13}, [53, 59]), ({'cycle': 90, 'current_offset': 25, 'target_offset': 13, 'lengthen_pct': 17, 'shorten_pct': 10}, [81, 87])], [({'cycle': 90, 'current_offset': 30, 'target_offset': 30, 'lengthen_pct': 20, 'shorten_pct': 17}, []), ({'cycle': 90, 'current_offset': 54, 'target_offset': 43, 'lengthen_pct': 10, 'shorten_pct': 13}, [79]), ({'cycle': 130, 'current_offset': 41, 'target_offset': 22, 'lengthen_pct': 20, 'shorten_pct': 17}, [111]), ({'cycle': 100, 'current_offset': 10, 'target_offset': 50, 'lengthen_pct': 20, 'shorten_pct': 20}, [120, 120]), ({'cycle': 140, 'current_offset': 46, 'target_offset': 86, 'lengthen_pct': 25, 'shorten_pct': 13}, [175, 145]), ({'cycle': 120, 'current_offset': 55, 'target_offset': 69, 'lengthen_pct': 20, 'shorten_pct': 17}, [134]), ({'cycle': 100, 'current_offset': 74, 'target_offset': 84, 'lengthen_pct': 10, 'shorten_pct': 17}, [110]), ({'cycle': 120, 'current_offset': 90, 'target_offset': 20, 'lengthen_pct': 17, 'shorten_pct': 13}, [140, 140, 130])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Shortway offset transition returns a wrong result when the adjustment is spread evenly instead of front-loaded.

Input {cycle, current_offset, target_offset, lengthen_pct, shorten_pct}. The needed correction e = (target - current) mod cycle can be made by lengthening cycles by a total of e or shortening them by cycle - e. Per-cycle limits are floor(cycle*pct/100). Choose the direction needing fewer cycles (ties lengthen) and front-load the maximum adjustment each cycle. Return the list of transition cycle lengths ([] when already in step).

split: open-access


prompt:
Time-of-day plan schedule returns a wrong result when events are compared at hour granularity.

Input {events: [[day mask (bit0 = Sunday), 'HH:MM', plan]], holidays: [[month, day, as_dow]], now: [dow, 'HH:MM', month, day]}. A holiday makes today's events come from its as_dow day type. The active plan is the event for today with the latest start <= now (later-listed wins at equal start). If none, the latest event of the most recent earlier real weekday that has events (up to 7 days back, same tie rule). Otherwise 'free'.

split: open-access


prompt:
Time-of-day plan schedule returns a wrong result when the day mask is read with Monday as bit zero.

Input {events: [[day mask (bit0 = Sunday), 'HH:MM', plan]], holidays: [[month, day, as_dow]], now: [dow, 'HH:MM', month, day]}. A holiday makes today's events come from its as_dow day type. The active plan is the event for today with the latest start <= now (later-listed wins at equal start). If none, the latest event of the most recent earlier real weekday that has events (up to 7 days back, same tie rule). Otherwise 'free'.

split: open-access


prompt:
Time-of-day plan schedule returns a wrong result when carryover after a holiday uses the holiday day type.

Input {events: [[day mask (bit0 = Sunday), 'HH:MM', plan]], holidays: [[month, day, as_dow]], now: [dow, 'HH:MM', month, day]}. A holiday makes today's events come from its as_dow day type. The active plan is the event for today with the latest start <= now (later-listed wins at equal start). If none, the latest event of the most recent earlier real weekday that has events (up to 7 days back, same tie rule). Otherwise 'free'.

split: open-access


prompt:
Time-of-day plan schedule returns a wrong result when holidays are matched by day of month alone.

Input {events: [[day mask (bit0 = Sunday), 'HH:MM', plan]], holidays: [[month, day, as_dow]], now: [dow, 'HH:MM', month, day]}. A holiday makes today's events come from its as_dow day type. The active plan is the event for today with the latest start <= now (later-listed wins at equal start). If none, the latest event of the most recent earlier real weekday that has events (up to 7 days back, same tie rule). Otherwise 'free'.

split: open-access


prompt:
Time-of-day plan schedule returns a wrong result when carryover takes the earliest event of the previous day.

Input {events: [[day mask (bit0 = Sunday), 'HH:MM', plan]], holidays: [[month, day, as_dow]], now: [dow, 'HH:MM', month, day]}. A holiday makes today's events come from its as_dow day type. The active plan is the event for today with the latest start <= now (later-listed wins at equal start). If none, the latest event of the most recent earlier real weekday that has events (up to 7 days back, same tie rule). Otherwise 'free'.

split: open-access


prompt:
Time-of-day plan schedule returns a wrong result when the carryover search looks back only one day.

Input {events: [[day mask (bit0 = Sunday), 'HH:MM', plan]], holidays: [[month, day, as_dow]], now: [dow, 'HH:MM', month, day]}. A holiday makes today's events come from its as_dow day type. The active plan is the event for today with the latest start <= now (later-listed wins at equal start). If none, the latest event of the most recent earlier real weekday that has events (up to 7 days back, same tie rule). Otherwise 'free'.

split: open-access


prompt:
Dual-ring barrier sequencing returns a wrong result when ring 1 alone decides when the barrier is crossed.

Input {ring1: [[1,d],[2,d],[3,d],[4,d]], ring2: [[5,d],[6,d],[7,d],[8,d]] with durations including clearance, calls, lag}. Phases 1-2/5-6 are left of the barrier and 3-4/7-8 right of it. On each side both rings start together at the barrier; if the first phase of a ring's pair is in lag the pair is swapped. Phases without calls are skipped and take no time. Both rings cross a barrier together when the slower ring finishes. Return {starts: sorted [phase, start], cycle}.

split: open-access


prompt:
Dual-ring barrier sequencing returns a wrong result when skipped phases still consume their duration.

Input {ring1: [[1,d],[2,d],[3,d],[4,d]], ring2: [[5,d],[6,d],[7,d],[8,d]] with durations including clearance, calls, lag}. Phases 1-2/5-6 are left of the barrier and 3-4/7-8 right of it. On each side both rings start together at the barrier; if the first phase of a ring's pair is in lag the pair is swapped. Phases without calls are skipped and take no time. Both rings cross a barrier together when the slower ring finishes. Return {starts: sorted [phase, start], cycle}.

split: open-access


prompt:
Dual-ring barrier sequencing returns a wrong result when lead-lag is keyed on the second phase of the pair.

Input {ring1: [[1,d],[2,d],[3,d],[4,d]], ring2: [[5,d],[6,d],[7,d],[8,d]] with durations including clearance, calls, lag}. Phases 1-2/5-6 are left of the barrier and 3-4/7-8 right of it. On each side both rings start together at the barrier; if the first phase of a ring's pair is in lag the pair is swapped. Phases without calls are skipped and take no time. Both rings cross a barrier together when the slower ring finishes. Return {starts: sorted [phase, start], cycle}.

split: open-access


prompt:
Dual-ring barrier sequencing returns a wrong result when ring 2 starts when ring 1 ends.

Input {ring1: [[1,d],[2,d],[3,d],[4,d]], ring2: [[5,d],[6,d],[7,d],[8,d]] with durations including clearance, calls, lag}. Phases 1-2/5-6 are left of the barrier and 3-4/7-8 right of it. On each side both rings start together at the barrier; if the first phase of a ring's pair is in lag the pair is swapped. Phases without calls are skipped and take no time. Both rings cross a barrier together when the slower ring finishes. Return {starts: sorted [phase, start], cycle}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(x):
    C, g = x['cycle'], x['green']
    lam = Fraction(g, C)
    cap = x['sat_per_lane'] * lam
    X = Fraction(x['volume']) / cap
    d = Fraction(1, 2) * C * (1 - lam) ** 2 / (1 - min(1, X) * lam)
    tenths = int(d * 10 + Fraction(1, 2))
    if X > 1:
        los = 'F'
    else:
        los = 'F'
        for lim, lab in ((100, 'A'), (200, 'B'), (350, 'C'), (550, 'D'), (800, 'E')):
            if tenths <= lim:
                los = lab
                break
    return {'vc_milli': int(X * 1000), 'delay_tenths': tenths, 'los': los}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 90, 'green': 39, 'volume': 1363, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1747, 'delay_tenths': 255, 'los': 'F'}), ({'cycle': 110, 'green': 28, 'volume': 242, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 500, 'delay_tenths': 350, 'los': 'C'}), ({'cycle': 90, 'green': 53, 'volume': 1841, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1838, 'delay_tenths': 185, 'los': 'F'}), ({'cycle': 60, 'green': 43, 'volume': 5888, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1610, 'delay_tenths': 85, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 60, 'green': 13, 'volume': 1105, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1000, 'delay_tenths': 235, 'los': 'C'})], [({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 120, 'green': 65, 'volume': 959, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1041, 'delay_tenths': 275, 'los': 'F'}), ({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 90, 'green': 40, 'volume': 2870, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1899, 'delay_tenths': 250, 'los': 'F'}), ({'cycle': 80, 'green': 36, 'volume': 1197, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 1400, 'delay_tenths': 220, 'los': 'F'}), ({'cycle': 110, 'green': 87, 'volume': 3733, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 925, 'delay_tenths': 90, 'los': 'A'}), ({'cycle': 100, 'green': 65, 'volume': 4446, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 1266, 'delay_tenths': 175, 'los': 'F'})], [({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 110, 'green': 53, 'volume': 2572, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1404, 'delay_tenths': 285, 'los': 'F'}), ({'cycle': 130, 'green': 50, 'volume': 2066, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 1492, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 60, 'green': 33, 'volume': 2090, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1000, 'delay_tenths': 135, 'los': 'B'}), ({'cycle': 60, 'green': 30, 'volume': 1709, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 632, 'delay_tenths': 110, 'los': 'B'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 90, 'green': 31, 'volume': 2169, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 1166, 'delay_tenths': 295, 'los': 'F'})], [({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 150, 'green': 128, 'volume': 8698, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1998, 'delay_tenths': 110, 'los': 'F'}), ({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 100, 'green': 12, 'volume': 741, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 1083, 'delay_tenths': 440, 'los': 'F'}), ({'cycle': 90, 'green': 34, 'volume': 468, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 326, 'delay_tenths': 199, 'los': 'B'}), ({'cycle': 60, 'green': 20, 'volume': 609, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 480, 'delay_tenths': 159, 'los': 'B'}), ({'cycle': 60, 'green': 20, 'volume': 1312, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1157, 'delay_tenths': 200, 'los': 'F'}), ({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'})], [({'cycle': 60, 'green': 39, 'volume': 799, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 227, 'delay_tenths': 43, 'los': 'A'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 60, 'green': 18, 'volume': 334, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 618, 'delay_tenths': 180, 'los': 'B'}), ({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 110, 'green': 42, 'volume': 3430, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1761, 'delay_tenths': 340, 'los': 'F'}), ({'cycle': 150, 'green': 123, 'volume': 8406, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 1898, 'delay_tenths': 135, 'los': 'F'}), ({'cycle': 90, 'green': 15, 'volume': 411, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1450, 'delay_tenths': 375, 'los': 'F'})]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(x):
    C, g = x['cycle'], x['green']
    lam = Fraction(g, C)
    cap = x['sat_per_lane'] * x['lanes']
    X = Fraction(x['volume']) / cap
    d = Fraction(1, 2) * C * (1 - lam) ** 2 / (1 - min(1, X) * lam)
    tenths = int(d * 10 + Fraction(1, 2))
    if X > 1:
        los = 'F'
    else:
        los = 'F'
        for lim, lab in ((100, 'A'), (200, 'B'), (350, 'C'), (550, 'D'), (800, 'E')):
            if tenths <= lim:
                los = lab
                break
    return {'vc_milli': int(X * 1000), 'delay_tenths': tenths, 'los': los}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 90, 'green': 39, 'volume': 1363, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1747, 'delay_tenths': 255, 'los': 'F'}), ({'cycle': 110, 'green': 28, 'volume': 242, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 500, 'delay_tenths': 350, 'los': 'C'}), ({'cycle': 90, 'green': 53, 'volume': 1841, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1838, 'delay_tenths': 185, 'los': 'F'}), ({'cycle': 60, 'green': 43, 'volume': 5888, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1610, 'delay_tenths': 85, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 60, 'green': 13, 'volume': 1105, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1000, 'delay_tenths': 235, 'los': 'C'})], [({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 120, 'green': 65, 'volume': 959, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1041, 'delay_tenths': 275, 'los': 'F'}), ({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 90, 'green': 40, 'volume': 2870, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1899, 'delay_tenths': 250, 'los': 'F'}), ({'cycle': 80, 'green': 36, 'volume': 1197, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 1400, 'delay_tenths': 220, 'los': 'F'}), ({'cycle': 110, 'green': 87, 'volume': 3733, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 925, 'delay_tenths': 90, 'los': 'A'}), ({'cycle': 100, 'green': 65, 'volume': 4446, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 1266, 'delay_tenths': 175, 'los': 'F'})], [({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 110, 'green': 53, 'volume': 2572, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1404, 'delay_tenths': 285, 'los': 'F'}), ({'cycle': 130, 'green': 50, 'volume': 2066, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 1492, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 60, 'green': 33, 'volume': 2090, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1000, 'delay_tenths': 135, 'los': 'B'}), ({'cycle': 60, 'green': 30, 'volume': 1709, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 632, 'delay_tenths': 110, 'los': 'B'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 90, 'green': 31, 'volume': 2169, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 1166, 'delay_tenths': 295, 'los': 'F'})], [({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 150, 'green': 128, 'volume': 8698, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1998, 'delay_tenths': 110, 'los': 'F'}), ({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 100, 'green': 12, 'volume': 741, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 1083, 'delay_tenths': 440, 'los': 'F'}), ({'cycle': 90, 'green': 34, 'volume': 468, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 326, 'delay_tenths': 199, 'los': 'B'}), ({'cycle': 60, 'green': 20, 'volume': 609, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 480, 'delay_tenths': 159, 'los': 'B'}), ({'cycle': 60, 'green': 20, 'volume': 1312, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1157, 'delay_tenths': 200, 'los': 'F'}), ({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'})], [({'cycle': 60, 'green': 39, 'volume': 799, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 227, 'delay_tenths': 43, 'los': 'A'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 60, 'green': 18, 'volume': 334, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 618, 'delay_tenths': 180, 'los': 'B'}), ({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 110, 'green': 42, 'volume': 3430, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1761, 'delay_tenths': 340, 'los': 'F'}), ({'cycle': 150, 'green': 123, 'volume': 8406, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 1898, 'delay_tenths': 135, 'los': 'F'}), ({'cycle': 90, 'green': 15, 'volume': 411, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1450, 'delay_tenths': 375, 'los': 'F'})]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Uniform delay level of service returns a wrong result when capacity ignores the number of lanes.

Input {cycle, green, volume, sat_per_lane, lanes}. lam = green/cycle, capacity = sat*lanes*lam, X = volume/capacity, uniform delay d = 0.5*C*(1-lam)^2/(1 - min(1,X)*lam) rounded half up to tenths. LOS thresholds on tenths: <=100 A, <=200 B, <=350 C, <=550 D, <=800 E, else F; any X > 1 is F. Return {vc_milli: floor(1000X), delay_tenths, los}.

split: open-access