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

N = 1
observations = []
def solve(x):
    C = x['capacity']
    need = dict(x['demands'])
    alloc = {c: 0 for c in need}
    active = sorted(c for c, d in need.items() if d >= 0)
    left = C
    while active and left > 0:
        share = left // len(active)
        if share == 0:
            for c in active[:left]:
                alloc[c] += 1
            left = 0
            break
        nxt = []
        for c in active:
            give = min(share, need[c] - alloc[c])
            alloc[c] += give
            left -= give
            if alloc[c] < need[c]:
                nxt.append(c)
        active = nxt
    return [sorted([c, a] for c, a in alloc.items()), left]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[['small demand satisfied first',
   {'capacity': 10, 'demands': [['a', 2], ['b', 8], ['c', 8]]},
   [[['a', 2], ['b', 4], ['c', 4]], 0]],
  ['remainder to lowest ids',
   {'capacity': 12, 'demands': [['b', 20], ['a', 20], ['c', 20]]},
   [[['a', 4], ['b', 4], ['c', 4]], 0]],
  ['zero demand ignored',
   {'capacity': 7, 'demands': [['x', 0], ['y', 5], ['z', 6]]},
   [[['x', 0], ['y', 4], ['z', 3]], 0]],
  ['surplus left over',
   {'capacity': 20, 'demands': [['a', 3], ['b', 5]]},
   [[['a', 3], ['b', 5]], 12]],
  ['multi-round water filling',
   {'capacity': 17, 'demands': [['a', 1], ['b', 3], ['c', 7], ['d', 20]]},
   [[['a', 1], ['b', 3], ['c', 7], ['d', 6]], 0]],
  ['random demands',
   {'capacity': 21, 'demands': [['p', 0], ['q', 3], ['r', 5], ['s', 5], ['t', 1]]},
   [[['p', 0], ['q', 3], ['r', 5], ['s', 5], ['t', 1]], 7]],
  ['second round respects unmet demand',
   {'capacity': 18, 'demands': [['a', 2], ['b', 7], ['c', 101]]},
   [[['a', 2], ['b', 7], ['c', 9]], 0]],
  ['tiny capacity with idle client',
   {'capacity': 2, 'demands': [['a', 0], ['b', 5], ['c', 6]]},
   [[['a', 0], ['b', 1], ['c', 1]], 0]],
  ['remainder ignores demand size',
   {'capacity': 2, 'demands': [['a', 9], ['b', 3], ['c', 4]]},
   [[['a', 1], ['b', 1], ['c', 0]], 0]],
  ['exact share satisfies',
   {'capacity': 9, 'demands': [['a', 3], ['b', 3], ['c', 6]]},
   [[['a', 3], ['b', 3], ['c', 3]], 0]]],
 [['small demand satisfied first',
   {'capacity': 10, 'demands': [['a', 2], ['b', 8], ['c', 8]]},
   [[['a', 2], ['b', 4], ['c', 4]], 0]],
  ['remainder to lowest ids',
   {'capacity': 13, 'demands': [['b', 20], ['a', 20], ['c', 20]]},
   [[['a', 5], ['b', 4], ['c', 4]], 0]],
  ['zero demand ignored',
   {'capacity': 7, 'demands': [['x', 0], ['y', 5], ['z', 7]]},
   [[['x', 0], ['y', 4], ['z', 3]], 0]],
  ['surplus left over',
   {'capacity': 20, 'demands': [['a', 3], ['b', 6]]},
   [[['a', 3], ['b', 6]], 11]],
  ['multi-round water filling',
   {'capacity': 17, 'demands': [['a', 1], ['b', 3], ['c', 8], ['d', 20]]},
   [[['a', 1], ['b', 3], ['c', 7], ['d', 6]], 0]],
  ['random demands',
   {'capacity': 21, 'demands': [['p', 2], ['q', 4], ['r', 8], ['s', 8], ['t', 4]]},
   [[['p', 2], ['q', 4], ['r', 6], ['s', 5], ['t', 4]], 0]],
  ['second round respects unmet demand',
   {'capacity': 18, 'demands': [['a', 2], ['b', 7], ['c', 102]]},
   [[['a', 2], ['b', 7], ['c', 9]], 0]],
  ['tiny capacity with idle client',
   {'capacity': 2, 'demands': [['a', 0], ['b', 5], ['c', 7]]},
   [[['a', 0], ['b', 1], ['c', 1]], 0]],
  ['remainder ignores demand size',
   {'capacity': 2, 'demands': [['a', 9], ['b', 3], ['c', 5]]},
   [[['a', 1], ['b', 1], ['c', 0]], 0]],
  ['exact share satisfies',
   {'capacity': 9, 'demands': [['a', 3], ['b', 3], ['c', 7]]},
   [[['a', 3], ['b', 3], ['c', 3]], 0]]],
 [['small demand satisfied first',
   {'capacity': 10, 'demands': [['a', 2], ['b', 8], ['c', 8]]},
   [[['a', 2], ['b', 4], ['c', 4]], 0]],
  ['remainder to lowest ids',
   {'capacity': 14, 'demands': [['b', 20], ['a', 20], ['c', 20]]},
   [[['a', 5], ['b', 5], ['c', 4]], 0]],
  ['zero demand ignored',
   {'capacity': 7, 'demands': [['x', 0], ['y', 5], ['z', 8]]},
   [[['x', 0], ['y', 4], ['z', 3]], 0]],
  ['surplus left over',
   {'capacity': 20, 'demands': [['a', 3], ['b', 7]]},
   [[['a', 3], ['b', 7]], 10]],
  ['multi-round water filling',
   {'capacity': 17, 'demands': [['a', 1], ['b', 3], ['c', 9], ['d', 20]]},
   [[['a', 1], ['b', 3], ['c', 7], ['d', 6]], 0]],
  ['random demands',
   {'capacity': 21, 'demands': [['p', 7], ['q', 8], ['r', 2], ['s', 9], ['t', 1]]},
   [[['p', 6], ['q', 6], ['r', 2], ['s', 6], ['t', 1]], 0]],
  ['second round respects unmet demand',
   {'capacity': 18, 'demands': [['a', 2], ['b', 7], ['c', 103]]},
   [[['a', 2], ['b', 7], ['c', 9]], 0]],
  ['tiny capacity with idle client',
   {'capacity': 2, 'demands': [['a', 0], ['b', 5], ['c', 8]]},
   [[['a', 0], ['b', 1], ['c', 1]], 0]],
  ['remainder ignores demand size',
   {'capacity': 2, 'demands': [['a', 9], ['b', 3], ['c', 6]]},
   [[['a', 1], ['b', 1], ['c', 0]], 0]],
  ['exact share satisfies',
   {'capacity': 9, 'demands': [['a', 3], ['b', 3], ['c', 8]]},
   [[['a', 3], ['b', 3], ['c', 3]], 0]]],
 [['small demand satisfied first',
   {'capacity': 10, 'demands': [['a', 2], ['b', 8], ['c', 8]]},
   [[['a', 2], ['b', 4], ['c', 4]], 0]],
  ['remainder to lowest ids',
   {'capacity': 15, 'demands': [['b', 20], ['a', 20], ['c', 20]]},
   [[['a', 5], ['b', 5], ['c', 5]], 0]],
  ['zero demand ignored',
   {'capacity': 7, 'demands': [['x', 0], ['y', 5], ['z', 9]]},
   [[['x', 0], ['y', 4], ['z', 3]], 0]],
  ['surplus left over',
   {'capacity': 20, 'demands': [['a', 3], ['b', 8]]},
   [[['a', 3], ['b', 8]], 9]],
  ['multi-round water filling',
   {'capacity': 17, 'demands': [['a', 1], ['b', 3], ['c', 10], ['d', 20]]},
   [[['a', 1], ['b', 3], ['c', 7], ['d', 6]], 0]],
  ['random demands',
   {'capacity': 21, 'demands': [['p', 2], ['q', 0], ['r', 5], ['s', 3], ['t', 8]]},
   [[['p', 2], ['q', 0], ['r', 5], ['s', 3], ['t', 8]], 3]],
  ['second round respects unmet demand',
   {'capacity': 18, 'demands': [['a', 2], ['b', 7], ['c', 104]]},
   [[['a', 2], ['b', 7], ['c', 9]], 0]],
  ['tiny capacity with idle client',
   {'capacity': 2, 'demands': [['a', 0], ['b', 5], ['c', 9]]},
   [[['a', 0], ['b', 1], ['c', 1]], 0]],
  ['remainder ignores demand size',
   {'capacity': 2, 'demands': [['a', 9], ['b', 3], ['c', 7]]},
   [[['a', 1], ['b', 1], ['c', 0]], 0]],
  ['exact share satisfies',
   {'capacity': 9, 'demands': [['a', 3], ['b', 3], ['c', 9]]},
   [[['a', 3], ['b', 3], ['c', 3]], 0]]],
 [['small demand satisfied first',
   {'capacity': 10, 'demands': [['a', 2], ['b', 8], ['c', 8]]},
   [[['a', 2], ['b', 4], ['c', 4]], 0]],
  ['remainder to lowest ids',
   {'capacity': 16, 'demands': [['b', 20], ['a', 20], ['c', 20]]},
   [[['a', 6], ['b', 5], ['c', 5]], 0]],
  ['zero demand ignored',
   {'capacity': 7, 'demands': [['x', 0], ['y', 5], ['z', 10]]},
   [[['x', 0], ['y', 4], ['z', 3]], 0]],
  ['surplus left over',
   {'capacity': 20, 'demands': [['a', 3], ['b', 9]]},
   [[['a', 3], ['b', 9]], 8]],
  ['multi-round water filling',
   {'capacity': 17, 'demands': [['a', 1], ['b', 3], ['c', 11], ['d', 20]]},
   [[['a', 1], ['b', 3], ['c', 7], ['d', 6]], 0]],
  ['random demands',
   {'capacity': 21, 'demands': [['p', 1], ['q', 3], ['r', 0], ['s', 6], ['t', 7]]},
   [[['p', 1], ['q', 3], ['r', 0], ['s', 6], ['t', 7]], 4]],
  ['second round respects unmet demand',
   {'capacity': 18, 'demands': [['a', 2], ['b', 7], ['c', 105]]},
   [[['a', 2], ['b', 7], ['c', 9]], 0]],
  ['tiny capacity with idle client',
   {'capacity': 2, 'demands': [['a', 0], ['b', 5], ['c', 10]]},
   [[['a', 0], ['b', 1], ['c', 1]], 0]],
  ['remainder ignores demand size',
   {'capacity': 2, 'demands': [['a', 9], ['b', 3], ['c', 8]]},
   [[['a', 1], ['b', 1], ['c', 0]], 0]],
  ['exact share satisfies',
   {'capacity': 9, 'demands': [['a', 3], ['b', 3], ['c', 10]]},
   [[['a', 3], ['b', 3], ['c', 3]], 0]]]]
for label, args, expected in cases[N - 1]:
    check(label, 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['capacity']
    need = dict(x['demands'])
    alloc = {c: 0 for c in need}
    active = sorted((c for c, d in need.items() if d > 0), key=lambda c: need[c])
    left = C
    while active and left > 0:
        share = left // len(active)
        if share == 0:
            for c in active[:left]:
                alloc[c] += 1
            left = 0
            break
        nxt = []
        for c in active:
            give = min(share, need[c] - alloc[c])
            alloc[c] += give
            left -= give
            if alloc[c] < need[c]:
                nxt.append(c)
        active = nxt
    return [sorted([c, a] for c, a in alloc.items()), left]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[['small demand satisfied first',
   {'capacity': 10, 'demands': [['a', 2], ['b', 8], ['c', 8]]},
   [[['a', 2], ['b', 4], ['c', 4]], 0]],
  ['remainder to lowest ids',
   {'capacity': 12, 'demands': [['b', 20], ['a', 20], ['c', 20]]},
   [[['a', 4], ['b', 4], ['c', 4]], 0]],
  ['zero demand ignored',
   {'capacity': 7, 'demands': [['x', 0], ['y', 5], ['z', 6]]},
   [[['x', 0], ['y', 4], ['z', 3]], 0]],
  ['surplus left over',
   {'capacity': 20, 'demands': [['a', 3], ['b', 5]]},
   [[['a', 3], ['b', 5]], 12]],
  ['multi-round water filling',
   {'capacity': 17, 'demands': [['a', 1], ['b', 3], ['c', 7], ['d', 20]]},
   [[['a', 1], ['b', 3], ['c', 7], ['d', 6]], 0]],
  ['random demands',
   {'capacity': 21, 'demands': [['p', 0], ['q', 3], ['r', 5], ['s', 5], ['t', 1]]},
   [[['p', 0], ['q', 3], ['r', 5], ['s', 5], ['t', 1]], 7]],
  ['second round respects unmet demand',
   {'capacity': 18, 'demands': [['a', 2], ['b', 7], ['c', 101]]},
   [[['a', 2], ['b', 7], ['c', 9]], 0]],
  ['tiny capacity with idle client',
   {'capacity': 2, 'demands': [['a', 0], ['b', 5], ['c', 6]]},
   [[['a', 0], ['b', 1], ['c', 1]], 0]],
  ['remainder ignores demand size',
   {'capacity': 2, 'demands': [['a', 9], ['b', 3], ['c', 4]]},
   [[['a', 1], ['b', 1], ['c', 0]], 0]],
  ['exact share satisfies',
   {'capacity': 9, 'demands': [['a', 3], ['b', 3], ['c', 6]]},
   [[['a', 3], ['b', 3], ['c', 3]], 0]]],
 [['small demand satisfied first',
   {'capacity': 10, 'demands': [['a', 2], ['b', 8], ['c', 8]]},
   [[['a', 2], ['b', 4], ['c', 4]], 0]],
  ['remainder to lowest ids',
   {'capacity': 13, 'demands': [['b', 20], ['a', 20], ['c', 20]]},
   [[['a', 5], ['b', 4], ['c', 4]], 0]],
  ['zero demand ignored',
   {'capacity': 7, 'demands': [['x', 0], ['y', 5], ['z', 7]]},
   [[['x', 0], ['y', 4], ['z', 3]], 0]],
  ['surplus left over',
   {'capacity': 20, 'demands': [['a', 3], ['b', 6]]},
   [[['a', 3], ['b', 6]], 11]],
  ['multi-round water filling',
   {'capacity': 17, 'demands': [['a', 1], ['b', 3], ['c', 8], ['d', 20]]},
   [[['a', 1], ['b', 3], ['c', 7], ['d', 6]], 0]],
  ['random demands',
   {'capacity': 21, 'demands': [['p', 2], ['q', 4], ['r', 8], ['s', 8], ['t', 4]]},
   [[['p', 2], ['q', 4], ['r', 6], ['s', 5], ['t', 4]], 0]],
  ['second round respects unmet demand',
   {'capacity': 18, 'demands': [['a', 2], ['b', 7], ['c', 102]]},
   [[['a', 2], ['b', 7], ['c', 9]], 0]],
  ['tiny capacity with idle client',
   {'capacity': 2, 'demands': [['a', 0], ['b', 5], ['c', 7]]},
   [[['a', 0], ['b', 1], ['c', 1]], 0]],
  ['remainder ignores demand size',
   {'capacity': 2, 'demands': [['a', 9], ['b', 3], ['c', 5]]},
   [[['a', 1], ['b', 1], ['c', 0]], 0]],
  ['exact share satisfies',
   {'capacity': 9, 'demands': [['a', 3], ['b', 3], ['c', 7]]},
   [[['a', 3], ['b', 3], ['c', 3]], 0]]],
 [['small demand satisfied first',
   {'capacity': 10, 'demands': [['a', 2], ['b', 8], ['c', 8]]},
   [[['a', 2], ['b', 4], ['c', 4]], 0]],
  ['remainder to lowest ids',
   {'capacity': 14, 'demands': [['b', 20], ['a', 20], ['c', 20]]},
   [[['a', 5], ['b', 5], ['c', 4]], 0]],
  ['zero demand ignored',
   {'capacity': 7, 'demands': [['x', 0], ['y', 5], ['z', 8]]},
   [[['x', 0], ['y', 4], ['z', 3]], 0]],
  ['surplus left over',
   {'capacity': 20, 'demands': [['a', 3], ['b', 7]]},
   [[['a', 3], ['b', 7]], 10]],
  ['multi-round water filling',
   {'capacity': 17, 'demands': [['a', 1], ['b', 3], ['c', 9], ['d', 20]]},
   [[['a', 1], ['b', 3], ['c', 7], ['d', 6]], 0]],
  ['random demands',
   {'capacity': 21, 'demands': [['p', 7], ['q', 8], ['r', 2], ['s', 9], ['t', 1]]},
   [[['p', 6], ['q', 6], ['r', 2], ['s', 6], ['t', 1]], 0]],
  ['second round respects unmet demand',
   {'capacity': 18, 'demands': [['a', 2], ['b', 7], ['c', 103]]},
   [[['a', 2], ['b', 7], ['c', 9]], 0]],
  ['tiny capacity with idle client',
   {'capacity': 2, 'demands': [['a', 0], ['b', 5], ['c', 8]]},
   [[['a', 0], ['b', 1], ['c', 1]], 0]],
  ['remainder ignores demand size',
   {'capacity': 2, 'demands': [['a', 9], ['b', 3], ['c', 6]]},
   [[['a', 1], ['b', 1], ['c', 0]], 0]],
  ['exact share satisfies',
   {'capacity': 9, 'demands': [['a', 3], ['b', 3], ['c', 8]]},
   [[['a', 3], ['b', 3], ['c', 3]], 0]]],
 [['small demand satisfied first',
   {'capacity': 10, 'demands': [['a', 2], ['b', 8], ['c', 8]]},
   [[['a', 2], ['b', 4], ['c', 4]], 0]],
  ['remainder to lowest ids',
   {'capacity': 15, 'demands': [['b', 20], ['a', 20], ['c', 20]]},
   [[['a', 5], ['b', 5], ['c', 5]], 0]],
  ['zero demand ignored',
   {'capacity': 7, 'demands': [['x', 0], ['y', 5], ['z', 9]]},
   [[['x', 0], ['y', 4], ['z', 3]], 0]],
  ['surplus left over',
   {'capacity': 20, 'demands': [['a', 3], ['b', 8]]},
   [[['a', 3], ['b', 8]], 9]],
  ['multi-round water filling',
   {'capacity': 17, 'demands': [['a', 1], ['b', 3], ['c', 10], ['d', 20]]},
   [[['a', 1], ['b', 3], ['c', 7], ['d', 6]], 0]],
  ['random demands',
   {'capacity': 21, 'demands': [['p', 2], ['q', 0], ['r', 5], ['s', 3], ['t', 8]]},
   [[['p', 2], ['q', 0], ['r', 5], ['s', 3], ['t', 8]], 3]],
  ['second round respects unmet demand',
   {'capacity': 18, 'demands': [['a', 2], ['b', 7], ['c', 104]]},
   [[['a', 2], ['b', 7], ['c', 9]], 0]],
  ['tiny capacity with idle client',
   {'capacity': 2, 'demands': [['a', 0], ['b', 5], ['c', 9]]},
   [[['a', 0], ['b', 1], ['c', 1]], 0]],
  ['remainder ignores demand size',
   {'capacity': 2, 'demands': [['a', 9], ['b', 3], ['c', 7]]},
   [[['a', 1], ['b', 1], ['c', 0]], 0]],
  ['exact share satisfies',
   {'capacity': 9, 'demands': [['a', 3], ['b', 3], ['c', 9]]},
   [[['a', 3], ['b', 3], ['c', 3]], 0]]],
 [['small demand satisfied first',
   {'capacity': 10, 'demands': [['a', 2], ['b', 8], ['c', 8]]},
   [[['a', 2], ['b', 4], ['c', 4]], 0]],
  ['remainder to lowest ids',
   {'capacity': 16, 'demands': [['b', 20], ['a', 20], ['c', 20]]},
   [[['a', 6], ['b', 5], ['c', 5]], 0]],
  ['zero demand ignored',
   {'capacity': 7, 'demands': [['x', 0], ['y', 5], ['z', 10]]},
   [[['x', 0], ['y', 4], ['z', 3]], 0]],
  ['surplus left over',
   {'capacity': 20, 'demands': [['a', 3], ['b', 9]]},
   [[['a', 3], ['b', 9]], 8]],
  ['multi-round water filling',
   {'capacity': 17, 'demands': [['a', 1], ['b', 3], ['c', 11], ['d', 20]]},
   [[['a', 1], ['b', 3], ['c', 7], ['d', 6]], 0]],
  ['random demands',
   {'capacity': 21, 'demands': [['p', 1], ['q', 3], ['r', 0], ['s', 6], ['t', 7]]},
   [[['p', 1], ['q', 3], ['r', 0], ['s', 6], ['t', 7]], 4]],
  ['second round respects unmet demand',
   {'capacity': 18, 'demands': [['a', 2], ['b', 7], ['c', 105]]},
   [[['a', 2], ['b', 7], ['c', 9]], 0]],
  ['tiny capacity with idle client',
   {'capacity': 2, 'demands': [['a', 0], ['b', 5], ['c', 10]]},
   [[['a', 0], ['b', 1], ['c', 1]], 0]],
  ['remainder ignores demand size',
   {'capacity': 2, 'demands': [['a', 9], ['b', 3], ['c', 8]]},
   [[['a', 1], ['b', 1], ['c', 0]], 0]],
  ['exact share satisfies',
   {'capacity': 9, 'demands': [['a', 3], ['b', 3], ['c', 10]]},
   [[['a', 3], ['b', 3], ['c', 3]], 0]]]]
for label, args, expected in cases[N - 1]:
    check(label, 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:
Clients that asked for nothing shrink everyone else's first-round share and can receive remainder units.

Input {capacity, demands [[client, demand]]} in integer requests per second. Clients with positive demand are active. Repeatedly give each active client min(floor(left / active count), unmet demand) and drop satisfied clients; when the per-client share rounds to zero, hand single units to active clients in ascending id order until capacity is exhausted. Return [sorted [client, allocation]], unallocated capacity].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import hashlib
N = 1
observations = []
def solve(flag, user, salt, pct):
    limit = round(pct * 100)
    digest = hashlib.sha1((salt + '.' + user + '.' + flag).encode()).hexdigest()
    bucket = int(digest[:8], 16) % 10000
    return [bucket, bucket < limit]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('bucket exactly at limit is excluded (alice)', ['new-checkout', 'alice', 'prod', 66.65], [6665, False]),
  ('bucket one below limit is included (alice)', ['new-checkout', 'alice', 'prod', 66.66], [6665, True]),
  ('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('half rollout control', ['search-v2', 'grace', 'ramp-7', 50], [3372, True]),
  ('hashed user sample 1', ['search-v2', 'u55140', 's1', 100], [5052, True]),
  ('hashed user sample 2', ['new-checkout', 'u28082', 's1', 50], [928, True])],
 [('bucket one below limit is included (alice)', ['new-checkout', 'alice', 'prod', 66.66], [6665, True]),
  ('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('half rollout control', ['search-v2', 'grace', 'ramp-7', 50], [3372, True]),
  ('hashed user sample 6', ['new-checkout', 'u58886', 'ramp-7', 50.31], [3873, True])],
 [('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('hashed user sample 4', ['fast-pay', 'u43705', 'ramp-7', 32.8], [187, True]),
  ('hashed user sample 11', ['search-v2', 'u91686', 'prod', 100], [5233, True]),
  ('hashed user sample 12', ['search-v2', 'u3012', 'prod', 62.02], [6201, True])],
 [('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('hashed user sample 11', ['search-v2', 'u91686', 'prod', 100], [5233, True]),
  ('hashed user sample 16', ['new-checkout', 'u25854', 'prod', 0.57], [5842, False]),
  ('hashed user sample 17', ['search-v2', 'u90753', 'prod', 0], [9423, False])],
 [('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('full rollout enables everyone', ['dark-mode', 'erin', 's1', 100], [9606, True]),
  ('hashed user sample 18', ['dark-mode', 'u52498', 'prod', 39.33], [2698, True]),
  ('hashed user sample 21', ['new-checkout', 'u7954', 'prod', 59.72], [196, True]),
  ('hashed user sample 22', ['new-checkout', 'u52965', 'ramp-7', 70.89], [7088, True])]]
for label, args, expected in fixtures[N - 1]:
    check(label, 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
import hashlib
N = 1
observations = []
def solve(flag, user, salt, pct):
    limit = round(pct * 100)
    digest = hashlib.sha1((salt + flag + user).encode()).hexdigest()
    bucket = int(digest[:8], 16) % 10000
    return [bucket, bucket < limit]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('bucket exactly at limit is excluded (alice)', ['new-checkout', 'alice', 'prod', 66.65], [6665, False]),
  ('bucket one below limit is included (alice)', ['new-checkout', 'alice', 'prod', 66.66], [6665, True]),
  ('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('half rollout control', ['search-v2', 'grace', 'ramp-7', 50], [3372, True]),
  ('hashed user sample 1', ['search-v2', 'u55140', 's1', 100], [5052, True]),
  ('hashed user sample 2', ['new-checkout', 'u28082', 's1', 50], [928, True])],
 [('bucket one below limit is included (alice)', ['new-checkout', 'alice', 'prod', 66.66], [6665, True]),
  ('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('half rollout control', ['search-v2', 'grace', 'ramp-7', 50], [3372, True]),
  ('hashed user sample 6', ['new-checkout', 'u58886', 'ramp-7', 50.31], [3873, True])],
 [('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('hashed user sample 4', ['fast-pay', 'u43705', 'ramp-7', 32.8], [187, True]),
  ('hashed user sample 11', ['search-v2', 'u91686', 'prod', 100], [5233, True]),
  ('hashed user sample 12', ['search-v2', 'u3012', 'prod', 62.02], [6201, True])],
 [('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('hashed user sample 11', ['search-v2', 'u91686', 'prod', 100], [5233, True]),
  ('hashed user sample 16', ['new-checkout', 'u25854', 'prod', 0.57], [5842, False]),
  ('hashed user sample 17', ['search-v2', 'u90753', 'prod', 0], [9423, False])],
 [('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('full rollout enables everyone', ['dark-mode', 'erin', 's1', 100], [9606, True]),
  ('hashed user sample 18', ['dark-mode', 'u52498', 'prod', 39.33], [2698, True]),
  ('hashed user sample 21', ['new-checkout', 'u7954', 'prod', 59.72], [196, True]),
  ('hashed user sample 22', ['new-checkout', 'u52965', 'ramp-7', 70.89], [7088, True])]]
for label, args, expected in fixtures[N - 1]:
    check(label, 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:
Users land in different buckets than every other SDK computes for the same flag.

bucket = int(first 8 hex digits of sha1(salt + "." + flag + "." + user), 16) % 10000; the rollout percentage pct has at most two decimals and becomes a basis-point limit round(pct * 100); the user is enabled iff bucket < limit. Return [bucket, enabled].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import hashlib
N = 1
observations = []
def solve(flag, user, salt, pct):
    limit = round(pct * 100)
    digest = hashlib.sha1((salt + '.' + flag + '.' + user).encode()).hexdigest()
    bucket = int(digest[:7], 16) % 10000
    return [bucket, bucket < limit]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('bucket exactly at limit is excluded (alice)', ['new-checkout', 'alice', 'prod', 66.65], [6665, False]),
  ('bucket one below limit is included (alice)', ['new-checkout', 'alice', 'prod', 66.66], [6665, True]),
  ('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('half rollout control', ['search-v2', 'grace', 'ramp-7', 50], [3372, True]),
  ('hashed user sample 1', ['search-v2', 'u55140', 's1', 100], [5052, True]),
  ('hashed user sample 2', ['new-checkout', 'u28082', 's1', 50], [928, True])],
 [('bucket one below limit is included (alice)', ['new-checkout', 'alice', 'prod', 66.66], [6665, True]),
  ('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('half rollout control', ['search-v2', 'grace', 'ramp-7', 50], [3372, True]),
  ('hashed user sample 6', ['new-checkout', 'u58886', 'ramp-7', 50.31], [3873, True])],
 [('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('hashed user sample 4', ['fast-pay', 'u43705', 'ramp-7', 32.8], [187, True]),
  ('hashed user sample 11', ['search-v2', 'u91686', 'prod', 100], [5233, True]),
  ('hashed user sample 12', ['search-v2', 'u3012', 'prod', 62.02], [6201, True])],
 [('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('hashed user sample 11', ['search-v2', 'u91686', 'prod', 100], [5233, True]),
  ('hashed user sample 16', ['new-checkout', 'u25854', 'prod', 0.57], [5842, False]),
  ('hashed user sample 17', ['search-v2', 'u90753', 'prod', 0], [9423, False])],
 [('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('full rollout enables everyone', ['dark-mode', 'erin', 's1', 100], [9606, True]),
  ('hashed user sample 18', ['dark-mode', 'u52498', 'prod', 39.33], [2698, True]),
  ('hashed user sample 21', ['new-checkout', 'u7954', 'prod', 59.72], [196, True]),
  ('hashed user sample 22', ['new-checkout', 'u52965', 'ramp-7', 70.89], [7088, True])]]
for label, args, expected in fixtures[N - 1]:
    check(label, 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
import hashlib
N = 1
observations = []
def solve(flag, user, salt, pct):
    limit = round(pct * 100)
    digest = hashlib.sha1((salt + '.' + flag + '.' + user).encode()).hexdigest()
    bucket = int(digest[-8:], 16) % 10000
    return [bucket, bucket < limit]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('bucket exactly at limit is excluded (alice)', ['new-checkout', 'alice', 'prod', 66.65], [6665, False]),
  ('bucket one below limit is included (alice)', ['new-checkout', 'alice', 'prod', 66.66], [6665, True]),
  ('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('half rollout control', ['search-v2', 'grace', 'ramp-7', 50], [3372, True]),
  ('hashed user sample 1', ['search-v2', 'u55140', 's1', 100], [5052, True]),
  ('hashed user sample 2', ['new-checkout', 'u28082', 's1', 50], [928, True])],
 [('bucket one below limit is included (alice)', ['new-checkout', 'alice', 'prod', 66.66], [6665, True]),
  ('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('half rollout control', ['search-v2', 'grace', 'ramp-7', 50], [3372, True]),
  ('hashed user sample 6', ['new-checkout', 'u58886', 'ramp-7', 50.31], [3873, True])],
 [('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('hashed user sample 4', ['fast-pay', 'u43705', 'ramp-7', 32.8], [187, True]),
  ('hashed user sample 11', ['search-v2', 'u91686', 'prod', 100], [5233, True]),
  ('hashed user sample 12', ['search-v2', 'u3012', 'prod', 62.02], [6201, True])],
 [('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('hashed user sample 11', ['search-v2', 'u91686', 'prod', 100], [5233, True]),
  ('hashed user sample 16', ['new-checkout', 'u25854', 'prod', 0.57], [5842, False]),
  ('hashed user sample 17', ['search-v2', 'u90753', 'prod', 0], [9423, False])],
 [('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('full rollout enables everyone', ['dark-mode', 'erin', 's1', 100], [9606, True]),
  ('hashed user sample 18', ['dark-mode', 'u52498', 'prod', 39.33], [2698, True]),
  ('hashed user sample 21', ['new-checkout', 'u7954', 'prod', 59.72], [196, True]),
  ('hashed user sample 22', ['new-checkout', 'u52965', 'ramp-7', 70.89], [7088, True])]]
for label, args, expected in fixtures[N - 1]:
    check(label, 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:
Bucket numbers disagree with the reference for most users while still looking uniform.

bucket = int(first 8 hex digits of sha1(salt + "." + flag + "." + user), 16) % 10000; the rollout percentage pct has at most two decimals and becomes a basis-point limit round(pct * 100); the user is enabled iff bucket < limit. Return [bucket, enabled].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import hashlib
N = 1
observations = []
def solve(flag, user, salt, pct):
    limit = round(pct * 100)
    digest = hashlib.sha1((salt + '.' + flag + '.' + user).encode()).hexdigest()
    bucket = int(digest[:8], 16) % 10000
    return [bucket, bucket <= limit]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('bucket exactly at limit is excluded (alice)', ['new-checkout', 'alice', 'prod', 66.65], [6665, False]),
  ('bucket one below limit is included (alice)', ['new-checkout', 'alice', 'prod', 66.66], [6665, True]),
  ('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('hashed user sample 1', ['search-v2', 'u55140', 's1', 100], [5052, True]),
  ('hashed user sample 2', ['new-checkout', 'u28082', 's1', 50], [928, True])],
 [('bucket one below limit is included (alice)', ['new-checkout', 'alice', 'prod', 66.66], [6665, True]),
  ('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('hashed user sample 13', ['new-checkout', 'u70823', 'ramp-7', 31.8], [3179, True]),
  ('hashed user sample 23', ['new-checkout', 'u5210', 'prod', 58.78], [5878, False])],
 [('bucket exactly at limit is excluded (alice)', ['new-checkout', 'alice', 'prod', 66.65], [6665, False]),
  ('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('hashed user sample 11', ['search-v2', 'u91686', 'prod', 100], [5233, True]),
  ('hashed user sample 40', ['fast-pay', 'u536', 'prod', 9.61], [960, True])],
 [('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('hashed user sample 16', ['new-checkout', 'u25854', 'prod', 0.57], [5842, False]),
  ('hashed user sample 23', ['new-checkout', 'u5210', 'prod', 58.78], [5878, False]),
  ('hashed user sample 51', ['new-checkout', 'u15929', 'ramp-7', 98.17], [9816, True])],
 [('bucket exactly at limit is excluded (alice)', ['new-checkout', 'alice', 'prod', 66.65], [6665, False]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('full rollout enables everyone', ['dark-mode', 'erin', 's1', 100], [9606, True]),
  ('hashed user sample 21', ['new-checkout', 'u7954', 'prod', 59.72], [196, True]),
  ('hashed user sample 22', ['new-checkout', 'u52965', 'ramp-7', 70.89], [7088, True])]]
for label, args, expected in fixtures[N - 1]:
    check(label, 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
import hashlib
N = 1
observations = []
def solve(flag, user, salt, pct):
    limit = round(pct * 100)
    digest = hashlib.sha1((salt + '.' + flag + '.' + user).encode()).hexdigest()
    bucket = int(digest[:8], 16) % 10000
    return [bucket, bucket < limit - 1]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('bucket exactly at limit is excluded (alice)', ['new-checkout', 'alice', 'prod', 66.65], [6665, False]),
  ('bucket one below limit is included (alice)', ['new-checkout', 'alice', 'prod', 66.66], [6665, True]),
  ('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('hashed user sample 1', ['search-v2', 'u55140', 's1', 100], [5052, True]),
  ('hashed user sample 2', ['new-checkout', 'u28082', 's1', 50], [928, True])],
 [('bucket one below limit is included (alice)', ['new-checkout', 'alice', 'prod', 66.66], [6665, True]),
  ('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('hashed user sample 13', ['new-checkout', 'u70823', 'ramp-7', 31.8], [3179, True]),
  ('hashed user sample 23', ['new-checkout', 'u5210', 'prod', 58.78], [5878, False])],
 [('bucket exactly at limit is excluded (alice)', ['new-checkout', 'alice', 'prod', 66.65], [6665, False]),
  ('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('hashed user sample 11', ['search-v2', 'u91686', 'prod', 100], [5233, True]),
  ('hashed user sample 40', ['fast-pay', 'u536', 'prod', 9.61], [960, True])],
 [('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('hashed user sample 16', ['new-checkout', 'u25854', 'prod', 0.57], [5842, False]),
  ('hashed user sample 23', ['new-checkout', 'u5210', 'prod', 58.78], [5878, False]),
  ('hashed user sample 51', ['new-checkout', 'u15929', 'ramp-7', 98.17], [9816, True])],
 [('bucket exactly at limit is excluded (alice)', ['new-checkout', 'alice', 'prod', 66.65], [6665, False]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('full rollout enables everyone', ['dark-mode', 'erin', 's1', 100], [9606, True]),
  ('hashed user sample 21', ['new-checkout', 'u7954', 'prod', 59.72], [196, True]),
  ('hashed user sample 22', ['new-checkout', 'u52965', 'ramp-7', 70.89], [7088, True])]]
for label, args, expected in fixtures[N - 1]:
    check(label, 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:
Rollouts expose one extra basis point of traffic, and 0 percent still enables bucket zero.

bucket = int(first 8 hex digits of sha1(salt + "." + flag + "." + user), 16) % 10000; the rollout percentage pct has at most two decimals and becomes a basis-point limit round(pct * 100); the user is enabled iff bucket < limit. Return [bucket, enabled].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import hashlib
N = 1
observations = []
def solve(flag, user, salt, pct):
    limit = int(pct * 100)
    digest = hashlib.sha1((salt + '.' + flag + '.' + user).encode()).hexdigest()
    bucket = int(digest[:8], 16) % 10000
    return [bucket, bucket < limit]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('bucket exactly at limit is excluded (alice)', ['new-checkout', 'alice', 'prod', 66.65], [6665, False]),
  ('bucket one below limit is included (alice)', ['new-checkout', 'alice', 'prod', 66.66], [6665, True]),
  ('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('hashed user sample 1', ['search-v2', 'u55140', 's1', 100], [5052, True]),
  ('hashed user sample 2', ['new-checkout', 'u28082', 's1', 50], [928, True])],
 [('bucket one below limit is included (alice)', ['new-checkout', 'alice', 'prod', 66.66], [6665, True]),
  ('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('hashed user sample 13', ['new-checkout', 'u70823', 'ramp-7', 31.8], [3179, True]),
  ('hashed user sample 32', ['fast-pay', 'u26409', 's1', 39.73], [3972, True])],
 [('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('hashed user sample 11', ['search-v2', 'u91686', 'prod', 100], [5233, True]),
  ('hashed user sample 40', ['fast-pay', 'u536', 'prod', 9.61], [960, True]),
  ('hashed user sample 47', ['dark-mode', 'u58180', 's1', 70.46], [7045, True])],
 [('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('hashed user sample 16', ['new-checkout', 'u25854', 'prod', 0.57], [5842, False]),
  ('hashed user sample 17', ['search-v2', 'u90753', 'prod', 0], [9423, False]),
  ('hashed user sample 51', ['new-checkout', 'u15929', 'ramp-7', 98.17], [9816, True])],
 [('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('full rollout enables everyone', ['dark-mode', 'erin', 's1', 100], [9606, True]),
  ('hashed user sample 21', ['new-checkout', 'u7954', 'prod', 59.72], [196, True]),
  ('hashed user sample 22', ['new-checkout', 'u52965', 'ramp-7', 70.89], [7088, True]),
  ('hashed user sample 32', ['fast-pay', 'u26409', 's1', 39.73], [3972, True])]]
for label, args, expected in fixtures[N - 1]:
    check(label, 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
import hashlib
N = 1
observations = []
def solve(flag, user, salt, pct):
    limit = int(pct) * 100
    digest = hashlib.sha1((salt + '.' + flag + '.' + user).encode()).hexdigest()
    bucket = int(digest[:8], 16) % 10000
    return [bucket, bucket < limit]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('bucket exactly at limit is excluded (alice)', ['new-checkout', 'alice', 'prod', 66.65], [6665, False]),
  ('bucket one below limit is included (alice)', ['new-checkout', 'alice', 'prod', 66.66], [6665, True]),
  ('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('hashed user sample 1', ['search-v2', 'u55140', 's1', 100], [5052, True]),
  ('hashed user sample 2', ['new-checkout', 'u28082', 's1', 50], [928, True])],
 [('bucket one below limit is included (alice)', ['new-checkout', 'alice', 'prod', 66.66], [6665, True]),
  ('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('hashed user sample 13', ['new-checkout', 'u70823', 'ramp-7', 31.8], [3179, True]),
  ('hashed user sample 32', ['fast-pay', 'u26409', 's1', 39.73], [3972, True])],
 [('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('hashed user sample 11', ['search-v2', 'u91686', 'prod', 100], [5233, True]),
  ('hashed user sample 40', ['fast-pay', 'u536', 'prod', 9.61], [960, True]),
  ('hashed user sample 47', ['dark-mode', 'u58180', 's1', 70.46], [7045, True])],
 [('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('hashed user sample 16', ['new-checkout', 'u25854', 'prod', 0.57], [5842, False]),
  ('hashed user sample 17', ['search-v2', 'u90753', 'prod', 0], [9423, False]),
  ('hashed user sample 51', ['new-checkout', 'u15929', 'ramp-7', 98.17], [9816, True])],
 [('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('full rollout enables everyone', ['dark-mode', 'erin', 's1', 100], [9606, True]),
  ('hashed user sample 21', ['new-checkout', 'u7954', 'prod', 59.72], [196, True]),
  ('hashed user sample 22', ['new-checkout', 'u52965', 'ramp-7', 70.89], [7088, True]),
  ('hashed user sample 32', ['fast-pay', 'u26409', 's1', 39.73], [3972, True])]]
for label, args, expected in fixtures[N - 1]:
    check(label, 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:
A 0.29 percent rollout admits only 28 basis points of buckets.

bucket = int(first 8 hex digits of sha1(salt + "." + flag + "." + user), 16) % 10000; the rollout percentage pct has at most two decimals and becomes a basis-point limit round(pct * 100); the user is enabled iff bucket < limit. Return [bucket, enabled].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import hashlib
N = 1
observations = []
def solve(flag, user, salt, pct):
    limit = round(pct * 100)
    digest = hashlib.sha1((salt + '.' + flag + '.' + user).encode()).hexdigest()
    bucket = int(digest[:8], 16) % 1000
    return [bucket, bucket < limit]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('bucket exactly at limit is excluded (alice)', ['new-checkout', 'alice', 'prod', 66.65], [6665, False]),
  ('bucket one below limit is included (alice)', ['new-checkout', 'alice', 'prod', 66.66], [6665, True]),
  ('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('half rollout control', ['search-v2', 'grace', 'ramp-7', 50], [3372, True]),
  ('hashed user sample 1', ['search-v2', 'u55140', 's1', 100], [5052, True]),
  ('hashed user sample 2', ['new-checkout', 'u28082', 's1', 50], [928, True])],
 [('bucket one below limit is included (alice)', ['new-checkout', 'alice', 'prod', 66.66], [6665, True]),
  ('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('half rollout control', ['search-v2', 'grace', 'ramp-7', 50], [3372, True]),
  ('hashed user sample 6', ['new-checkout', 'u58886', 'ramp-7', 50.31], [3873, True])],
 [('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('hashed user sample 4', ['fast-pay', 'u43705', 'ramp-7', 32.8], [187, True]),
  ('hashed user sample 6', ['new-checkout', 'u58886', 'ramp-7', 50.31], [3873, True]),
  ('hashed user sample 11', ['search-v2', 'u91686', 'prod', 100], [5233, True])],
 [('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('hashed user sample 11', ['search-v2', 'u91686', 'prod', 100], [5233, True]),
  ('hashed user sample 13', ['new-checkout', 'u70823', 'ramp-7', 31.8], [3179, True]),
  ('hashed user sample 16', ['new-checkout', 'u25854', 'prod', 0.57], [5842, False])],
 [('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('full rollout enables everyone', ['dark-mode', 'erin', 's1', 100], [9606, True]),
  ('hashed user sample 18', ['dark-mode', 'u52498', 'prod', 39.33], [2698, True]),
  ('hashed user sample 20', ['dark-mode', 'u36438', 'prod', 34.74], [3474, False]),
  ('hashed user sample 21', ['new-checkout', 'u7954', 'prod', 59.72], [196, True])]]
for label, args, expected in fixtures[N - 1]:
    check(label, 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
import hashlib
N = 1
observations = []
def solve(flag, user, salt, pct):
    limit = round(pct * 100)
    digest = hashlib.sha1((salt + '.' + flag + '.' + user).encode()).hexdigest()
    bucket = int(digest[:4], 16) % 10000
    return [bucket, bucket < limit]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('bucket exactly at limit is excluded (alice)', ['new-checkout', 'alice', 'prod', 66.65], [6665, False]),
  ('bucket one below limit is included (alice)', ['new-checkout', 'alice', 'prod', 66.66], [6665, True]),
  ('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('half rollout control', ['search-v2', 'grace', 'ramp-7', 50], [3372, True]),
  ('hashed user sample 1', ['search-v2', 'u55140', 's1', 100], [5052, True]),
  ('hashed user sample 2', ['new-checkout', 'u28082', 's1', 50], [928, True])],
 [('bucket one below limit is included (alice)', ['new-checkout', 'alice', 'prod', 66.66], [6665, True]),
  ('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('half rollout control', ['search-v2', 'grace', 'ramp-7', 50], [3372, True]),
  ('hashed user sample 6', ['new-checkout', 'u58886', 'ramp-7', 50.31], [3873, True])],
 [('bucket exactly at limit is excluded (bob)', ['dark-mode', 'bob', 's1', 27.55], [2755, False]),
  ('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('hashed user sample 4', ['fast-pay', 'u43705', 'ramp-7', 32.8], [187, True]),
  ('hashed user sample 6', ['new-checkout', 'u58886', 'ramp-7', 50.31], [3873, True]),
  ('hashed user sample 11', ['search-v2', 'u91686', 'prod', 100], [5233, True])],
 [('bucket one below limit is included (bob)', ['dark-mode', 'bob', 's1', 27.56], [2755, True]),
  ('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('hashed user sample 11', ['search-v2', 'u91686', 'prod', 100], [5233, True]),
  ('hashed user sample 13', ['new-checkout', 'u70823', 'ramp-7', 31.8], [3179, True]),
  ('hashed user sample 16', ['new-checkout', 'u25854', 'prod', 0.57], [5842, False])],
 [('bucket exactly at limit is excluded (carol)', ['search-v2', 'carol', 'prod', 57.45], [5745, False]),
  ('bucket one below limit is included (carol)', ['search-v2', 'carol', 'prod', 57.46], [5745, True]),
  ('float truncation regression at 65.82 percent', ['fast-pay', 'member13', 'prod', 65.82], [6581, True]),
  ('zero percent disables everyone', ['dark-mode', 'dave', 's1', 0], [4167, False]),
  ('full rollout enables everyone', ['dark-mode', 'erin', 's1', 100], [9606, True]),
  ('hashed user sample 18', ['dark-mode', 'u52498', 'prod', 39.33], [2698, True]),
  ('hashed user sample 20', ['dark-mode', 'u36438', 'prod', 34.74], [3474, False]),
  ('hashed user sample 21', ['new-checkout', 'u7954', 'prod', 59.72], [196, True])]]
for label, args, expected in fixtures[N - 1]:
    check(label, 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:
Bucket values never exceed 999, so a 10 percent rollout enables every user.

bucket = int(first 8 hex digits of sha1(salt + "." + flag + "." + user), 16) % 10000; the rollout percentage pct has at most two decimals and becomes a basis-point limit round(pct * 100); the user is enabled iff bucket < limit. Return [bucket, enabled].

split: open-access


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

N = 1
observations = []
def solve(variants, bucket):
    acc = 0
    last = None
    for name, weight in variants:
        if weight <= 0:
            continue
        last = name
        acc += round(weight * 100)
        if bucket <= acc:
            return name
    return last
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('bucket at first cumulative edge goes to second arm',
   [[['control', 50], ['treatment', 50]], 5000],
   'treatment'),
  ('bucket just below first edge stays in first arm',
   [[['control', 50], ['treatment', 50]], 4999],
   'control'),
  ('zero weight arm is never selected', [[['control', 0], ['treatment', 100]], 0], 'treatment'),
  ('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('weight table sample 1', [[['green', 1.15], ['holdout', 0], ['alpha', 1.15], ['blue', 50]], 1135], 'blue'),
  ('weight table sample 2', [[['blue', 50], ['treatment', 10]], 2986], 'blue')],
 [('bucket at first cumulative edge goes to second arm',
   [[['control', 50], ['treatment', 50]], 5000],
   'treatment'),
  ('bucket just below first edge stays in first arm',
   [[['control', 50], ['treatment', 50]], 4999],
   'control'),
  ('zero weight arm is never selected', [[['control', 0], ['treatment', 100]], 0], 'treatment'),
  ('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('weight table sample 37', [[['holdout', 10], ['green', 1.15]], 1000], 'green'),
  ('weight table sample 58',
   [[['treatment', 50], ['control', 25], ['green', 25], ['holdout', 33.33]], 4999],
   'treatment')],
 [('zero weight arm is never selected', [[['control', 0], ['treatment', 100]], 0], 'treatment'),
  ('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('weight table sample 11', [[['holdout', 12.5], ['blue', 12.5], ['alpha', 0.57]], 2500], 'alpha'),
  ('weight table sample 19', [[['holdout', 0.57], ['treatment', 50], ['green', 50]], 5057], 'green'),
  ('weight table sample 55',
   [[['control', 1.15], ['green', -5], ['blue', 4.35], ['treatment', 25]], 549],
   'blue')],
 [('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('three way split middle arm', [[['a', 33.33], ['b', 33.33], ['c', 33.34]], 5000], 'b'),
  ('weight table sample 11', [[['holdout', 12.5], ['blue', 12.5], ['alpha', 0.57]], 2500], 'alpha'),
  ('weight table sample 16', [[['green', 0.57], ['alpha', 12.5], ['control', 25]], 1307], 'control'),
  ('weight table sample 50',
   [[['blue', 12.5], ['control', 0.57], ['green', 4.35], ['holdout', 0.29]], 1741],
   'green')],
 [('bucket at first cumulative edge goes to second arm',
   [[['control', 50], ['treatment', 50]], 5000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('three way split middle arm', [[['a', 33.33], ['b', 33.33], ['c', 33.34]], 5000], 'b'),
  ('weight table sample 21', [[['green', 33.33], ['treatment', 0]], 0], 'green'),
  ('weight table sample 39', [[['treatment', 1.15], ['control', 25], ['green', 4.35]], 115], 'control'),
  ('weight table sample 45',
   [[['control', 4.35], ['blue', 50], ['treatment', 50], ['alpha', 50]], 5434],
   'blue')]]
for label, args, expected in fixtures[N - 1]:
    check(label, 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(variants, bucket):
    acc = 0
    last = None
    for name, weight in variants:
        if weight <= 0:
            continue
        last = name
        acc += round(weight * 100)
        if bucket < acc - 1:
            return name
    return last
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('bucket at first cumulative edge goes to second arm',
   [[['control', 50], ['treatment', 50]], 5000],
   'treatment'),
  ('bucket just below first edge stays in first arm',
   [[['control', 50], ['treatment', 50]], 4999],
   'control'),
  ('zero weight arm is never selected', [[['control', 0], ['treatment', 100]], 0], 'treatment'),
  ('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('weight table sample 1', [[['green', 1.15], ['holdout', 0], ['alpha', 1.15], ['blue', 50]], 1135], 'blue'),
  ('weight table sample 2', [[['blue', 50], ['treatment', 10]], 2986], 'blue')],
 [('bucket at first cumulative edge goes to second arm',
   [[['control', 50], ['treatment', 50]], 5000],
   'treatment'),
  ('bucket just below first edge stays in first arm',
   [[['control', 50], ['treatment', 50]], 4999],
   'control'),
  ('zero weight arm is never selected', [[['control', 0], ['treatment', 100]], 0], 'treatment'),
  ('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('weight table sample 37', [[['holdout', 10], ['green', 1.15]], 1000], 'green'),
  ('weight table sample 58',
   [[['treatment', 50], ['control', 25], ['green', 25], ['holdout', 33.33]], 4999],
   'treatment')],
 [('zero weight arm is never selected', [[['control', 0], ['treatment', 100]], 0], 'treatment'),
  ('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('weight table sample 11', [[['holdout', 12.5], ['blue', 12.5], ['alpha', 0.57]], 2500], 'alpha'),
  ('weight table sample 19', [[['holdout', 0.57], ['treatment', 50], ['green', 50]], 5057], 'green'),
  ('weight table sample 55',
   [[['control', 1.15], ['green', -5], ['blue', 4.35], ['treatment', 25]], 549],
   'blue')],
 [('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('three way split middle arm', [[['a', 33.33], ['b', 33.33], ['c', 33.34]], 5000], 'b'),
  ('weight table sample 11', [[['holdout', 12.5], ['blue', 12.5], ['alpha', 0.57]], 2500], 'alpha'),
  ('weight table sample 16', [[['green', 0.57], ['alpha', 12.5], ['control', 25]], 1307], 'control'),
  ('weight table sample 50',
   [[['blue', 12.5], ['control', 0.57], ['green', 4.35], ['holdout', 0.29]], 1741],
   'green')],
 [('bucket at first cumulative edge goes to second arm',
   [[['control', 50], ['treatment', 50]], 5000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('three way split middle arm', [[['a', 33.33], ['b', 33.33], ['c', 33.34]], 5000], 'b'),
  ('weight table sample 21', [[['green', 33.33], ['treatment', 0]], 0], 'green'),
  ('weight table sample 39', [[['treatment', 1.15], ['control', 25], ['green', 4.35]], 115], 'control'),
  ('weight table sample 45',
   [[['control', 4.35], ['blue', 50], ['treatment', 50], ['alpha', 50]], 5434],
   'blue')]]
for label, args, expected in fixtures[N - 1]:
    check(label, 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:
A bucket equal to an arm boundary is assigned to the earlier arm, over-weighting it by one bucket.

variants is an ordered list of [name, weight percent with at most two decimals]; bucket is an integer in [0, 10000). Walk variants in declared order, skipping non-positive weights, adding round(weight * 100) to a running total, and return the first variant whose total exceeds the bucket. Buckets beyond the total go to the last positively weighted variant; with none, None.

split: open-access


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

N = 1
observations = []
def solve(variants, bucket):
    acc = 0
    last = None
    for name, weight in variants:
        last = name
        acc += round(weight * 100)
        if bucket < acc:
            return name
    return last
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('bucket at first cumulative edge goes to second arm',
   [[['control', 50], ['treatment', 50]], 5000],
   'treatment'),
  ('bucket just below first edge stays in first arm',
   [[['control', 50], ['treatment', 50]], 4999],
   'control'),
  ('zero weight arm is never selected', [[['control', 0], ['treatment', 100]], 0], 'treatment'),
  ('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('weight table sample 1', [[['green', 1.15], ['holdout', 0], ['alpha', 1.15], ['blue', 50]], 1135], 'blue'),
  ('weight table sample 2', [[['blue', 50], ['treatment', 10]], 2986], 'blue')],
 [('bucket just below first edge stays in first arm',
   [[['control', 50], ['treatment', 50]], 4999],
   'control'),
  ('zero weight arm is never selected', [[['control', 0], ['treatment', 100]], 0], 'treatment'),
  ('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('weight table sample 6',
   [[['alpha', 0.29], ['holdout', 12.5], ['blue', 0.57], ['treatment', 0]], 204],
   'holdout'),
  ('weight table sample 48', [[['treatment', 0], ['green', -5], ['blue', 0]], 0], None)],
 [('zero weight arm is never selected', [[['control', 0], ['treatment', 100]], 0], 'treatment'),
  ('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('weight table sample 11', [[['holdout', 12.5], ['blue', 12.5], ['alpha', 0.57]], 2500], 'alpha'),
  ('weight table sample 12', [[['blue', 12.5], ['holdout', 0]], 1249], 'blue'),
  ('weight table sample 27',
   [[['green', 33.33], ['holdout', 0], ['control', 0], ['alpha', -5]], 3333],
   'green')],
 [('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('three way split middle arm', [[['a', 33.33], ['b', 33.33], ['c', 33.34]], 5000], 'b'),
  ('weight table sample 16', [[['green', 0.57], ['alpha', 12.5], ['control', 25]], 1307], 'control'),
  ('weight table sample 17', [[['treatment', 1.15], ['control', 0.29], ['blue', 0.29]], 2597], 'blue'),
  ('weight table sample 18', [[['blue', 33.34], ['alpha', 0.29], ['green', 4.35]], 2889], 'blue')],
 [('bucket at first cumulative edge goes to second arm',
   [[['control', 50], ['treatment', 50]], 5000],
   'treatment'),
  ('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('three way split middle arm', [[['a', 33.33], ['b', 33.33], ['c', 33.34]], 5000], 'b'),
  ('weight table sample 21', [[['green', 33.33], ['treatment', 0]], 0], 'green'),
  ('weight table sample 22', [[['alpha', 0], ['control', 4.35], ['blue', 1.15]], 9182], 'blue')]]
for label, args, expected in fixtures[N - 1]:
    check(label, 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(variants, bucket):
    acc = 0
    last = None
    for name, weight in variants:
        if weight < 0:
            continue
        last = name
        acc += round(weight * 100)
        if bucket < acc:
            return name
    return last
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('bucket at first cumulative edge goes to second arm',
   [[['control', 50], ['treatment', 50]], 5000],
   'treatment'),
  ('bucket just below first edge stays in first arm',
   [[['control', 50], ['treatment', 50]], 4999],
   'control'),
  ('zero weight arm is never selected', [[['control', 0], ['treatment', 100]], 0], 'treatment'),
  ('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('weight table sample 1', [[['green', 1.15], ['holdout', 0], ['alpha', 1.15], ['blue', 50]], 1135], 'blue'),
  ('weight table sample 2', [[['blue', 50], ['treatment', 10]], 2986], 'blue')],
 [('bucket just below first edge stays in first arm',
   [[['control', 50], ['treatment', 50]], 4999],
   'control'),
  ('zero weight arm is never selected', [[['control', 0], ['treatment', 100]], 0], 'treatment'),
  ('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('weight table sample 6',
   [[['alpha', 0.29], ['holdout', 12.5], ['blue', 0.57], ['treatment', 0]], 204],
   'holdout'),
  ('weight table sample 48', [[['treatment', 0], ['green', -5], ['blue', 0]], 0], None)],
 [('zero weight arm is never selected', [[['control', 0], ['treatment', 100]], 0], 'treatment'),
  ('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('weight table sample 11', [[['holdout', 12.5], ['blue', 12.5], ['alpha', 0.57]], 2500], 'alpha'),
  ('weight table sample 12', [[['blue', 12.5], ['holdout', 0]], 1249], 'blue'),
  ('weight table sample 27',
   [[['green', 33.33], ['holdout', 0], ['control', 0], ['alpha', -5]], 3333],
   'green')],
 [('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('three way split middle arm', [[['a', 33.33], ['b', 33.33], ['c', 33.34]], 5000], 'b'),
  ('weight table sample 16', [[['green', 0.57], ['alpha', 12.5], ['control', 25]], 1307], 'control'),
  ('weight table sample 17', [[['treatment', 1.15], ['control', 0.29], ['blue', 0.29]], 2597], 'blue'),
  ('weight table sample 18', [[['blue', 33.34], ['alpha', 0.29], ['green', 4.35]], 2889], 'blue')],
 [('bucket at first cumulative edge goes to second arm',
   [[['control', 50], ['treatment', 50]], 5000],
   'treatment'),
  ('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('three way split middle arm', [[['a', 33.33], ['b', 33.33], ['c', 33.34]], 5000], 'b'),
  ('weight table sample 21', [[['green', 33.33], ['treatment', 0]], 0], 'green'),
  ('weight table sample 22', [[['alpha', 0], ['control', 4.35], ['blue', 1.15]], 9182], 'blue')]]
for label, args, expected in fixtures[N - 1]:
    check(label, 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:
A variant switched off with weight zero still receives remainder traffic, and negative weights shrink totals.

variants is an ordered list of [name, weight percent with at most two decimals]; bucket is an integer in [0, 10000). Walk variants in declared order, skipping non-positive weights, adding round(weight * 100) to a running total, and return the first variant whose total exceeds the bucket. Buckets beyond the total go to the last positively weighted variant; with none, None.

split: open-access


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

N = 1
observations = []
def solve(variants, bucket):
    acc = 0
    last = None
    for name, weight in variants:
        if weight <= 0:
            continue
        last = name
        acc += round(weight * 100)
        if bucket < acc:
            return name
    return None
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('bucket at first cumulative edge goes to second arm',
   [[['control', 50], ['treatment', 50]], 5000],
   'treatment'),
  ('bucket just below first edge stays in first arm',
   [[['control', 50], ['treatment', 50]], 4999],
   'control'),
  ('zero weight arm is never selected', [[['control', 0], ['treatment', 100]], 0], 'treatment'),
  ('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('weight table sample 1', [[['green', 1.15], ['holdout', 0], ['alpha', 1.15], ['blue', 50]], 1135], 'blue'),
  ('weight table sample 2', [[['blue', 50], ['treatment', 10]], 2986], 'blue')],
 [('bucket just below first edge stays in first arm',
   [[['control', 50], ['treatment', 50]], 4999],
   'control'),
  ('zero weight arm is never selected', [[['control', 0], ['treatment', 100]], 0], 'treatment'),
  ('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('weight table sample 6',
   [[['alpha', 0.29], ['holdout', 12.5], ['blue', 0.57], ['treatment', 0]], 204],
   'holdout'),
  ('weight table sample 27',
   [[['green', 33.33], ['holdout', 0], ['control', 0], ['alpha', -5]], 3333],
   'green')],
 [('zero weight arm is never selected', [[['control', 0], ['treatment', 100]], 0], 'treatment'),
  ('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('weight table sample 9',
   [[['blue', 0], ['alpha', 0.57], ['green', 4.35], ['treatment', -5]], 4555],
   'green'),
  ('weight table sample 11', [[['holdout', 12.5], ['blue', 12.5], ['alpha', 0.57]], 2500], 'alpha'),
  ('weight table sample 51', [[['alpha', 10], ['holdout', 10], ['blue', 0.29]], 5446], 'blue')],
 [('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('three way split middle arm', [[['a', 33.33], ['b', 33.33], ['c', 33.34]], 5000], 'b'),
  ('weight table sample 4', [[['green', 12.5], ['treatment', 0.29]], 7991], 'treatment'),
  ('weight table sample 16', [[['green', 0.57], ['alpha', 12.5], ['control', 25]], 1307], 'control'),
  ('weight table sample 27',
   [[['green', 33.33], ['holdout', 0], ['control', 0], ['alpha', -5]], 3333],
   'green')],
 [('bucket at first cumulative edge goes to second arm',
   [[['control', 50], ['treatment', 50]], 5000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('three way split middle arm', [[['a', 33.33], ['b', 33.33], ['c', 33.34]], 5000], 'b'),
  ('weight table sample 21', [[['green', 33.33], ['treatment', 0]], 0], 'green'),
  ('weight table sample 29', [[['holdout', -5], ['treatment', -5], ['blue', 4.35]], 435], 'blue'),
  ('weight table sample 48', [[['treatment', 0], ['green', -5], ['blue', 0]], 0], None)]]
for label, args, expected in fixtures[N - 1]:
    check(label, 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(variants, bucket):
    acc = 0
    last = None
    for name, weight in variants:
        if weight <= 0:
            continue
        last = name
        acc += round(weight * 100)
        if bucket < acc:
            return name
    return variants[-1][0] if variants else None
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('bucket at first cumulative edge goes to second arm',
   [[['control', 50], ['treatment', 50]], 5000],
   'treatment'),
  ('bucket just below first edge stays in first arm',
   [[['control', 50], ['treatment', 50]], 4999],
   'control'),
  ('zero weight arm is never selected', [[['control', 0], ['treatment', 100]], 0], 'treatment'),
  ('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('weight table sample 1', [[['green', 1.15], ['holdout', 0], ['alpha', 1.15], ['blue', 50]], 1135], 'blue'),
  ('weight table sample 2', [[['blue', 50], ['treatment', 10]], 2986], 'blue')],
 [('bucket just below first edge stays in first arm',
   [[['control', 50], ['treatment', 50]], 4999],
   'control'),
  ('zero weight arm is never selected', [[['control', 0], ['treatment', 100]], 0], 'treatment'),
  ('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('weight table sample 6',
   [[['alpha', 0.29], ['holdout', 12.5], ['blue', 0.57], ['treatment', 0]], 204],
   'holdout'),
  ('weight table sample 27',
   [[['green', 33.33], ['holdout', 0], ['control', 0], ['alpha', -5]], 3333],
   'green')],
 [('zero weight arm is never selected', [[['control', 0], ['treatment', 100]], 0], 'treatment'),
  ('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('weight table sample 9',
   [[['blue', 0], ['alpha', 0.57], ['green', 4.35], ['treatment', -5]], 4555],
   'green'),
  ('weight table sample 11', [[['holdout', 12.5], ['blue', 12.5], ['alpha', 0.57]], 2500], 'alpha'),
  ('weight table sample 51', [[['alpha', 10], ['holdout', 10], ['blue', 0.29]], 5446], 'blue')],
 [('trailing zero weight arm does not absorb remainder',
   [[['control', 40], ['treatment', 40], ['off', 0]], 9000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('three way split middle arm', [[['a', 33.33], ['b', 33.33], ['c', 33.34]], 5000], 'b'),
  ('weight table sample 4', [[['green', 12.5], ['treatment', 0.29]], 7991], 'treatment'),
  ('weight table sample 16', [[['green', 0.57], ['alpha', 12.5], ['control', 25]], 1307], 'control'),
  ('weight table sample 27',
   [[['green', 33.33], ['holdout', 0], ['control', 0], ['alpha', -5]], 3333],
   'green')],
 [('bucket at first cumulative edge goes to second arm',
   [[['control', 50], ['treatment', 50]], 5000],
   'treatment'),
  ('declared order beats alphabetical order', [[['zeta', 10], ['alpha', 90]], 500], 'zeta'),
  ('fractional weight 0.29 covers 29 buckets', [[['tiny', 0.29], ['rest', 99.71]], 28], 'tiny'),
  ('no positive weights yields None', [[['a', 0], ['b', 0]], 10], None),
  ('three way split middle arm', [[['a', 33.33], ['b', 33.33], ['c', 33.34]], 5000], 'b'),
  ('weight table sample 21', [[['green', 33.33], ['treatment', 0]], 0], 'green'),
  ('weight table sample 29', [[['holdout', -5], ['treatment', -5], ['blue', 4.35]], 435], 'blue'),
  ('weight table sample 48', [[['treatment', 0], ['green', -5], ['blue', 0]], 0], None)]]
for label, args, expected in fixtures[N - 1]:
    check(label, 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:
When weights sum below 100 percent, users in the leftover buckets get no variant at all.

variants is an ordered list of [name, weight percent with at most two decimals]; bucket is an integer in [0, 10000). Walk variants in declared order, skipping non-positive weights, adding round(weight * 100) to a running total, and return the first variant whose total exceeds the bucket. Buckets beyond the total go to the last positively weighted variant; with none, None.

split: open-access