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

N = 1
observations = []
def solve(contexts):
    def esc(s):
        return s.replace('%', '%25').replace(':', '%3A')
    if not contexts or any(k == '' for k in contexts.values()):
        return None
    if len(contexts) == 1:
        return next(iter(contexts.values()))
    return ':'.join(kind + ':' + esc(contexts[kind]) for kind in sorted(contexts))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('percent is escaped before colon', [{'org': 'a:b', 'user': '50%'}], 'org:a%3Ab:user:50%25'),
  ('already escaped text is escaped again', [{'org': 'x%3Ay', 'user': 'bob'}], 'org:x%253Ay:user:bob'),
  ('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('three kinds', [{'device': 'd1', 'app': 'z', 'user': 'bob'}], 'app:z:device:d1:user:bob'),
  ('context sample 1', [{'device': '50%', 'user': 'z', 'app': 'a:b'}], 'app:a%3Ab:device:50%25:user:z'),
  ('context sample 2', [{'device': 'acme', 'user': 'z', 'org': 'z'}], 'device:acme:org:z:user:z')],
 [('already escaped text is escaped again', [{'org': 'x%3Ay', 'user': 'bob'}], 'org:x%253Ay:user:bob'),
  ('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('three kinds', [{'device': 'd1', 'app': 'z', 'user': 'bob'}], 'app:z:device:d1:user:bob'),
  ('context sample 4', [{'user': 'z', 'org': 'a:b'}], 'org:a%3Ab:user:z'),
  ('context sample 33', [{'org': 'x%3Ay'}], 'org:x%253Ay')],
 [('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('context sample 11', [{'org': 'x%3Ay', 'app': 'a:b', 'device': 'z'}], 'app:a%3Ab:device:z:org:x%253Ay'),
  ('context sample 49', [{'device': 'x%3Ay', 'user': 'x%3Ay'}], 'device:x%253Ay:user:x%253Ay'),
  ('context sample 59', [{'org': 'z'}], 'org:z')],
 [('already escaped text is escaped again', [{'org': 'x%3Ay', 'user': 'bob'}], 'org:x%253Ay:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('three kinds', [{'device': 'd1', 'app': 'z', 'user': 'bob'}], 'app:z:device:d1:user:bob'),
  ('context sample 16', [{'org': 'x%3Ay', 'app': 'z'}], 'app:z:org:x%253Ay'),
  ('context sample 28', [{'app': 'acme'}], 'app:acme')],
 [('percent is escaped before colon', [{'org': 'a:b', 'user': '50%'}], 'org:a%3Ab:user:50%25'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('three kinds', [{'device': 'd1', 'app': 'z', 'user': 'bob'}], 'app:z:device:d1:user:bob'),
  ('context sample 7', [{'org': 'a:b', 'device': 'a:b', 'user': 'z'}], 'device:a%3Ab:org:a%3Ab:user:z'),
  ('context sample 21', [{'org': 'x%3Ay', 'app': 'z'}], 'app:z:org:x%253Ay'),
  ('context sample 55', [{'app': 'bob'}], 'app:bob')]]
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(contexts):
    def esc(s):
        return s.replace('%', '%25').replace(':', '%3A')
    if not contexts or any(k == '' for k in contexts.values()):
        return None
    if 'user' in contexts:
        return contexts['user']
    return ':'.join(kind + ':' + esc(contexts[kind]) for kind in sorted(contexts))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('percent is escaped before colon', [{'org': 'a:b', 'user': '50%'}], 'org:a%3Ab:user:50%25'),
  ('already escaped text is escaped again', [{'org': 'x%3Ay', 'user': 'bob'}], 'org:x%253Ay:user:bob'),
  ('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('three kinds', [{'device': 'd1', 'app': 'z', 'user': 'bob'}], 'app:z:device:d1:user:bob'),
  ('context sample 1', [{'device': '50%', 'user': 'z', 'app': 'a:b'}], 'app:a%3Ab:device:50%25:user:z'),
  ('context sample 2', [{'device': 'acme', 'user': 'z', 'org': 'z'}], 'device:acme:org:z:user:z')],
 [('already escaped text is escaped again', [{'org': 'x%3Ay', 'user': 'bob'}], 'org:x%253Ay:user:bob'),
  ('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('three kinds', [{'device': 'd1', 'app': 'z', 'user': 'bob'}], 'app:z:device:d1:user:bob'),
  ('context sample 4', [{'user': 'z', 'org': 'a:b'}], 'org:a%3Ab:user:z'),
  ('context sample 33', [{'org': 'x%3Ay'}], 'org:x%253Ay')],
 [('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('context sample 11', [{'org': 'x%3Ay', 'app': 'a:b', 'device': 'z'}], 'app:a%3Ab:device:z:org:x%253Ay'),
  ('context sample 49', [{'device': 'x%3Ay', 'user': 'x%3Ay'}], 'device:x%253Ay:user:x%253Ay'),
  ('context sample 59', [{'org': 'z'}], 'org:z')],
 [('already escaped text is escaped again', [{'org': 'x%3Ay', 'user': 'bob'}], 'org:x%253Ay:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('three kinds', [{'device': 'd1', 'app': 'z', 'user': 'bob'}], 'app:z:device:d1:user:bob'),
  ('context sample 16', [{'org': 'x%3Ay', 'app': 'z'}], 'app:z:org:x%253Ay'),
  ('context sample 28', [{'app': 'acme'}], 'app:acme')],
 [('percent is escaped before colon', [{'org': 'a:b', 'user': '50%'}], 'org:a%3Ab:user:50%25'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('three kinds', [{'device': 'd1', 'app': 'z', 'user': 'bob'}], 'app:z:device:d1:user:bob'),
  ('context sample 7', [{'org': 'a:b', 'device': 'a:b', 'user': 'z'}], 'device:a%3Ab:org:a%3Ab:user:z'),
  ('context sample 21', [{'org': 'x%3Ay', 'app': 'z'}], 'app:z:org:x%253Ay'),
  ('context sample 55', [{'app': 'bob'}], 'app:bob')]]
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:
An org-only context collides with a user whose key equals the org key.

contexts maps kind -> key. Empty input or any empty key -> None. A context containing only the kind "user" is keyed by the bare user key. Otherwise join, over kinds in sorted order, kind + ":" + escaped key with ":", where escaping replaces "%" by "%25" and then ":" by "%3A".

split: open-access


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

N = 1
observations = []
def solve(contexts):
    def esc(s):
        return s.replace('%', '%25').replace(':', '%3A')
    if not contexts:
        return None
    if list(contexts) == ['user']:
        return contexts['user']
    return ':'.join(kind + ':' + esc(contexts[kind]) for kind in sorted(contexts))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('percent is escaped before colon', [{'org': 'a:b', 'user': '50%'}], 'org:a%3Ab:user:50%25'),
  ('already escaped text is escaped again', [{'org': 'x%3Ay', 'user': 'bob'}], 'org:x%253Ay:user:bob'),
  ('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('context sample 1', [{'device': '50%', 'user': 'z', 'app': 'a:b'}], 'app:a%3Ab:device:50%25:user:z'),
  ('context sample 2', [{'device': 'acme', 'user': 'z', 'org': 'z'}], 'device:acme:org:z:user:z')],
 [('already escaped text is escaped again', [{'org': 'x%3Ay', 'user': 'bob'}], 'org:x%253Ay:user:bob'),
  ('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('context sample 6', [{'device': 'bob', 'org': 'a:b'}], 'device:bob:org:a%3Ab'),
  ('context sample 7', [{'org': 'a:b', 'device': 'a:b', 'user': 'z'}], 'device:a%3Ab:org:a%3Ab:user:z'),
  ('context sample 36', [{'user': '', 'app': 'bob', 'device': 'acme'}], None)],
 [('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('context sample 8', [{'app': 'k:1%', 'device': ''}], None),
  ('context sample 11', [{'org': 'x%3Ay', 'app': 'a:b', 'device': 'z'}], 'app:a%3Ab:device:z:org:x%253Ay'),
  ('context sample 12', [{'user': 'acme'}], 'acme')],
 [('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('three kinds', [{'device': 'd1', 'app': 'z', 'user': 'bob'}], 'app:z:device:d1:user:bob'),
  ('context sample 16', [{'org': 'x%3Ay', 'app': 'z'}], 'app:z:org:x%253Ay'),
  ('context sample 17', [{'org': '50%', 'user': 'z'}], 'org:50%25:user:z'),
  ('context sample 38', [{'device': '', 'org': 'bob', 'user': 'bob'}], None)],
 [('percent is escaped before colon', [{'org': 'a:b', 'user': '50%'}], 'org:a%3Ab:user:50%25'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('three kinds', [{'device': 'd1', 'app': 'z', 'user': 'bob'}], 'app:z:device:d1:user:bob'),
  ('context sample 9', [{'org': 'bob', 'device': '', 'app': 'acme'}], None),
  ('context sample 21', [{'org': 'x%3Ay', 'app': 'z'}], 'app:z:org:x%253Ay'),
  ('context sample 22', [{'org': 'x%3Ay'}], 'org:x%253Ay')]]
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

N = 1
observations = []
def solve(contexts):
    def esc(s):
        return s.replace('%', '%25').replace(':', '%3A')
    if not contexts or all(k == '' for k in contexts.values()):
        return None
    if list(contexts) == ['user']:
        return contexts['user']
    return ':'.join(kind + ':' + esc(contexts[kind]) for kind in sorted(contexts))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('percent is escaped before colon', [{'org': 'a:b', 'user': '50%'}], 'org:a%3Ab:user:50%25'),
  ('already escaped text is escaped again', [{'org': 'x%3Ay', 'user': 'bob'}], 'org:x%253Ay:user:bob'),
  ('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('context sample 1', [{'device': '50%', 'user': 'z', 'app': 'a:b'}], 'app:a%3Ab:device:50%25:user:z'),
  ('context sample 2', [{'device': 'acme', 'user': 'z', 'org': 'z'}], 'device:acme:org:z:user:z')],
 [('already escaped text is escaped again', [{'org': 'x%3Ay', 'user': 'bob'}], 'org:x%253Ay:user:bob'),
  ('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('context sample 6', [{'device': 'bob', 'org': 'a:b'}], 'device:bob:org:a%3Ab'),
  ('context sample 7', [{'org': 'a:b', 'device': 'a:b', 'user': 'z'}], 'device:a%3Ab:org:a%3Ab:user:z'),
  ('context sample 36', [{'user': '', 'app': 'bob', 'device': 'acme'}], None)],
 [('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('context sample 8', [{'app': 'k:1%', 'device': ''}], None),
  ('context sample 11', [{'org': 'x%3Ay', 'app': 'a:b', 'device': 'z'}], 'app:a%3Ab:device:z:org:x%253Ay'),
  ('context sample 12', [{'user': 'acme'}], 'acme')],
 [('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('three kinds', [{'device': 'd1', 'app': 'z', 'user': 'bob'}], 'app:z:device:d1:user:bob'),
  ('context sample 16', [{'org': 'x%3Ay', 'app': 'z'}], 'app:z:org:x%253Ay'),
  ('context sample 17', [{'org': '50%', 'user': 'z'}], 'org:50%25:user:z'),
  ('context sample 38', [{'device': '', 'org': 'bob', 'user': 'bob'}], None)],
 [('percent is escaped before colon', [{'org': 'a:b', 'user': '50%'}], 'org:a%3Ab:user:50%25'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('three kinds', [{'device': 'd1', 'app': 'z', 'user': 'bob'}], 'app:z:device:d1:user:bob'),
  ('context sample 9', [{'org': 'bob', 'device': '', 'app': 'acme'}], None),
  ('context sample 21', [{'org': 'x%3Ay', 'app': 'z'}], 'app:z:org:x%253Ay'),
  ('context sample 22', [{'org': 'x%3Ay'}], 'org:x%253Ay')]]
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:
Contexts with a blank org key all share the canonical key "org:".

contexts maps kind -> key. Empty input or any empty key -> None. A context containing only the kind "user" is keyed by the bare user key. Otherwise join, over kinds in sorted order, kind + ":" + escaped key with ":", where escaping replaces "%" by "%25" and then ":" by "%3A".

split: open-access


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

N = 1
observations = []
def solve(contexts):
    def esc(s):
        return s.replace('%', '%25').replace(':', '%3A')
    if not contexts or any(k == '' for k in contexts.values()):
        return None
    if list(contexts) == ['user']:
        return esc(contexts['user'])
    return ':'.join(kind + ':' + esc(contexts[kind]) for kind in sorted(contexts))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('percent is escaped before colon', [{'org': 'a:b', 'user': '50%'}], 'org:a%3Ab:user:50%25'),
  ('already escaped text is escaped again', [{'org': 'x%3Ay', 'user': 'bob'}], 'org:x%253Ay:user:bob'),
  ('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('context sample 1', [{'device': '50%', 'user': 'z', 'app': 'a:b'}], 'app:a%3Ab:device:50%25:user:z'),
  ('context sample 2', [{'device': 'acme', 'user': 'z', 'org': 'z'}], 'device:acme:org:z:user:z'),
  ('context sample 3',
   [{'app': 'k:1%', 'user': 'acme', 'device': 'bob'}],
   'app:k%3A1%25:device:bob:user:acme')],
 [('already escaped text is escaped again', [{'org': 'x%3Ay', 'user': 'bob'}], 'org:x%253Ay:user:bob'),
  ('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('context sample 6', [{'device': 'bob', 'org': 'a:b'}], 'device:bob:org:a%3Ab'),
  ('context sample 12', [{'user': 'acme'}], 'acme'),
  ('context sample 29', [{'user': 'a:b'}], 'a:b')],
 [('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('context sample 11', [{'org': 'x%3Ay', 'app': 'a:b', 'device': 'z'}], 'app:a%3Ab:device:z:org:x%253Ay'),
  ('context sample 18', [{'user': 'x%3Ay'}], 'x%3Ay'),
  ('context sample 47', [{'user': 'a:b'}], 'a:b')],
 [('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('three kinds', [{'device': 'd1', 'app': 'z', 'user': 'bob'}], 'app:z:device:d1:user:bob'),
  ('context sample 16', [{'org': 'x%3Ay', 'app': 'z'}], 'app:z:org:x%253Ay'),
  ('context sample 18', [{'user': 'x%3Ay'}], 'x%3Ay'),
  ('context sample 29', [{'user': 'a:b'}], 'a:b')],
 [('percent is escaped before colon', [{'org': 'a:b', 'user': '50%'}], 'org:a%3Ab:user:50%25'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('three kinds', [{'device': 'd1', 'app': 'z', 'user': 'bob'}], 'app:z:device:d1:user:bob'),
  ('context sample 21', [{'org': 'x%3Ay', 'app': 'z'}], 'app:z:org:x%253Ay'),
  ('context sample 22', [{'org': 'x%3Ay'}], 'org:x%253Ay'),
  ('context sample 46', [{'user': 'x%3Ay'}], 'x%3Ay')]]
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(contexts):
    def esc(s):
        return s.replace('%', '%25').replace(':', '%3A')
    if not contexts or any(k == '' for k in contexts.values()):
        return None
    if list(contexts) == ['user']:
        return 'user:' + contexts['user']
    return ':'.join(kind + ':' + esc(contexts[kind]) for kind in sorted(contexts))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('percent is escaped before colon', [{'org': 'a:b', 'user': '50%'}], 'org:a%3Ab:user:50%25'),
  ('already escaped text is escaped again', [{'org': 'x%3Ay', 'user': 'bob'}], 'org:x%253Ay:user:bob'),
  ('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('context sample 1', [{'device': '50%', 'user': 'z', 'app': 'a:b'}], 'app:a%3Ab:device:50%25:user:z'),
  ('context sample 2', [{'device': 'acme', 'user': 'z', 'org': 'z'}], 'device:acme:org:z:user:z'),
  ('context sample 3',
   [{'app': 'k:1%', 'user': 'acme', 'device': 'bob'}],
   'app:k%3A1%25:device:bob:user:acme')],
 [('already escaped text is escaped again', [{'org': 'x%3Ay', 'user': 'bob'}], 'org:x%253Ay:user:bob'),
  ('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('context sample 6', [{'device': 'bob', 'org': 'a:b'}], 'device:bob:org:a%3Ab'),
  ('context sample 12', [{'user': 'acme'}], 'acme'),
  ('context sample 29', [{'user': 'a:b'}], 'a:b')],
 [('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('context sample 11', [{'org': 'x%3Ay', 'app': 'a:b', 'device': 'z'}], 'app:a%3Ab:device:z:org:x%253Ay'),
  ('context sample 18', [{'user': 'x%3Ay'}], 'x%3Ay'),
  ('context sample 47', [{'user': 'a:b'}], 'a:b')],
 [('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('three kinds', [{'device': 'd1', 'app': 'z', 'user': 'bob'}], 'app:z:device:d1:user:bob'),
  ('context sample 16', [{'org': 'x%3Ay', 'app': 'z'}], 'app:z:org:x%253Ay'),
  ('context sample 18', [{'user': 'x%3Ay'}], 'x%3Ay'),
  ('context sample 29', [{'user': 'a:b'}], 'a:b')],
 [('percent is escaped before colon', [{'org': 'a:b', 'user': '50%'}], 'org:a%3Ab:user:50%25'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('three kinds', [{'device': 'd1', 'app': 'z', 'user': 'bob'}], 'app:z:device:d1:user:bob'),
  ('context sample 21', [{'org': 'x%3Ay', 'app': 'z'}], 'app:z:org:x%253Ay'),
  ('context sample 22', [{'org': 'x%3Ay'}], 'org:x%253Ay'),
  ('context sample 46', [{'user': 'x%3Ay'}], 'x%3Ay')]]
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:
Single-user contexts with ":" in the key no longer match the legacy user key.

contexts maps kind -> key. Empty input or any empty key -> None. A context containing only the kind "user" is keyed by the bare user key. Otherwise join, over kinds in sorted order, kind + ":" + escaped key with ":", where escaping replaces "%" by "%25" and then ":" by "%3A".

split: open-access


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

N = 1
observations = []
def solve(ip, cidrs):
    def parse(s):
        parts = s.split('.')
        if len(parts) != 4 or not all(p.isdigit() and int(p) <= 255 for p in parts):
            return None
        v = 0
        for p in parts:
            v = v * 256 + int(p)
        return v
    addr = parse(ip)
    if addr is None:
        return None
    for i, c in enumerate(cidrs):
        net, _, bits = c.partition('/')
        bits = bits or '32'
        base = parse(net)
        if base is None or not bits.isdigit() or int(bits) > 32:
            continue
        n = int(bits)
        mask = (1 << n) - 1
        if addr & mask == base & mask:
            return [True, i]
    return [False, -1]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('slash 24 matches inside the network', ['10.1.2.3', ['192.168.0.0/16', '10.1.2.0/24']], [True, 1]),
  ('slash 0 matches everything', ['8.8.8.8', ['0.0.0.0/0']], [True, 0]),
  ('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('prefix longer than 32 is skipped', ['10.0.0.1', ['10.0.0.0/33', '10.0.0.0/8']], [True, 1]),
  ('network sample 1', ['10.1.2.0', ['8.8.8.0', '10.1.2.3/32', '10.0.0.0/8']], [True, 2]),
  ('network sample 2', ['8.8.8.8', ['10.1.2.3/32']], [False, -1])],
 [('slash 0 matches everything', ['8.8.8.8', ['0.0.0.0/0']], [True, 0]),
  ('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('prefix longer than 32 is skipped', ['10.0.0.1', ['10.0.0.0/33', '10.0.0.0/8']], [True, 1]),
  ('network sample 6', ['172.16.5.4', ['192.168.0.0/16', '8.8.8.0', '10.1.2.77/24']], [False, -1]),
  ('network sample 55', ['255.255.255.255', ['192.168.1.0/24', '0.0.0.0/0']], [True, 1])],
 [('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('prefix longer than 32 is skipped', ['10.0.0.1', ['10.0.0.0/33', '10.0.0.0/8']], [True, 1]),
  ('network sample 11', ['10.1.2.3', ['192.168.1.0/24']], [False, -1]),
  ('network sample 25', ['172.16.5.4', ['10.1.2.0/31', '0.0.0.0/0', '8.8.8.0']], [True, 1])],
 [('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('invalid ip returns None', ['10.0.0.300', ['0.0.0.0/0']], None),
  ('network sample 7', ['10.1.2.0', ['0.0.0.0/0']], [True, 0]),
  ('network sample 16', ['10.1.2.0', ['1.0.0.256/8']], [False, -1]),
  ('network sample 43', ['0.0.0.0', ['10.0.0.0/8']], [False, -1])],
 [('slash 0 matches everything', ['8.8.8.8', ['0.0.0.0/0']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('invalid ip returns None', ['10.0.0.300', ['0.0.0.0/0']], None),
  ('prefix longer than 32 is skipped', ['10.0.0.1', ['10.0.0.0/33', '10.0.0.0/8']], [True, 1]),
  ('network sample 21', ['10.1.2.3', ['10.1.2.3', '192.168.1.0/24']], [True, 0]),
  ('network sample 45', ['10.1.2.3', ['10.0.0.0/8', '8.8.8.0', '192.168.1.0/24']], [True, 0])]]
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(ip, cidrs):
    def parse(s):
        parts = s.split('.')
        if len(parts) != 4 or not all(p.isdigit() and int(p) <= 255 for p in parts):
            return None
        v = 0
        for p in parts:
            v = v * 256 + int(p)
        return v
    addr = parse(ip)
    if addr is None:
        return None
    for i, c in enumerate(cidrs):
        net, _, bits = c.partition('/')
        bits = bits or '32'
        base = parse(net)
        if base is None or not bits.isdigit() or int(bits) > 32:
            continue
        n = int(bits)
        mask = (0xFFFFFFFF << (32 - n)) & 0xFFFFFFFF if n else 0xFFFFFFFF
        if addr & mask == base & mask:
            return [True, i]
    return [False, -1]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('slash 24 matches inside the network', ['10.1.2.3', ['192.168.0.0/16', '10.1.2.0/24']], [True, 1]),
  ('slash 0 matches everything', ['8.8.8.8', ['0.0.0.0/0']], [True, 0]),
  ('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('prefix longer than 32 is skipped', ['10.0.0.1', ['10.0.0.0/33', '10.0.0.0/8']], [True, 1]),
  ('network sample 1', ['10.1.2.0', ['8.8.8.0', '10.1.2.3/32', '10.0.0.0/8']], [True, 2]),
  ('network sample 2', ['8.8.8.8', ['10.1.2.3/32']], [False, -1])],
 [('slash 0 matches everything', ['8.8.8.8', ['0.0.0.0/0']], [True, 0]),
  ('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('prefix longer than 32 is skipped', ['10.0.0.1', ['10.0.0.0/33', '10.0.0.0/8']], [True, 1]),
  ('network sample 6', ['172.16.5.4', ['192.168.0.0/16', '8.8.8.0', '10.1.2.77/24']], [False, -1]),
  ('network sample 55', ['255.255.255.255', ['192.168.1.0/24', '0.0.0.0/0']], [True, 1])],
 [('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('prefix longer than 32 is skipped', ['10.0.0.1', ['10.0.0.0/33', '10.0.0.0/8']], [True, 1]),
  ('network sample 11', ['10.1.2.3', ['192.168.1.0/24']], [False, -1]),
  ('network sample 25', ['172.16.5.4', ['10.1.2.0/31', '0.0.0.0/0', '8.8.8.0']], [True, 1])],
 [('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('invalid ip returns None', ['10.0.0.300', ['0.0.0.0/0']], None),
  ('network sample 7', ['10.1.2.0', ['0.0.0.0/0']], [True, 0]),
  ('network sample 16', ['10.1.2.0', ['1.0.0.256/8']], [False, -1]),
  ('network sample 43', ['0.0.0.0', ['10.0.0.0/8']], [False, -1])],
 [('slash 0 matches everything', ['8.8.8.8', ['0.0.0.0/0']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('invalid ip returns None', ['10.0.0.300', ['0.0.0.0/0']], None),
  ('prefix longer than 32 is skipped', ['10.0.0.1', ['10.0.0.0/33', '10.0.0.0/8']], [True, 1]),
  ('network sample 21', ['10.1.2.3', ['10.1.2.3', '192.168.1.0/24']], [True, 0]),
  ('network sample 45', ['10.1.2.3', ['10.0.0.0/8', '8.8.8.0', '192.168.1.0/24']], [True, 0])]]
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 /24 rule compares the last three octets, so unrelated networks match.

ip is dotted-quad IPv4 with octets 0..255 (else return None). Each cidr is "a.b.c.d/n" with 0 <= n <= 32, or a bare address meaning /32; malformed entries are skipped. An entry matches when the top n bits of ip and of its address agree (host bits of the entry are ignored). Return [True, index of first match] or [False, -1].

split: open-access


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

N = 1
observations = []
def solve(ip, cidrs):
    def parse(s):
        parts = s.split('.')
        if len(parts) != 4 or not all(p.isdigit() for p in parts):
            return None
        v = 0
        for p in parts:
            v = v * 256 + int(p)
        return v
    addr = parse(ip)
    if addr is None:
        return None
    for i, c in enumerate(cidrs):
        net, _, bits = c.partition('/')
        bits = bits or '32'
        base = parse(net)
        if base is None or not bits.isdigit() or int(bits) > 32:
            continue
        n = int(bits)
        mask = ((1 << n) - 1) << (32 - n)
        if addr & mask == base & mask:
            return [True, i]
    return [False, -1]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('slash 24 matches inside the network', ['10.1.2.3', ['192.168.0.0/16', '10.1.2.0/24']], [True, 1]),
  ('slash 0 matches everything', ['8.8.8.8', ['0.0.0.0/0']], [True, 0]),
  ('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('invalid ip returns None', ['10.0.0.300', ['0.0.0.0/0']], None),
  ('network sample 1', ['10.1.2.0', ['8.8.8.0', '10.1.2.3/32', '10.0.0.0/8']], [True, 2]),
  ('network sample 2', ['8.8.8.8', ['10.1.2.3/32']], [False, -1])],
 [('slash 0 matches everything', ['8.8.8.8', ['0.0.0.0/0']], [True, 0]),
  ('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('invalid ip returns None', ['10.0.0.300', ['0.0.0.0/0']], None),
  ('network sample 34', ['10.0.0.300', ['10.0.0.0/8']], None),
  ('network sample 55', ['255.255.255.255', ['192.168.1.0/24', '0.0.0.0/0']], [True, 1])],
 [('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('invalid ip returns None', ['10.0.0.300', ['0.0.0.0/0']], None),
  ('network sample 11', ['10.1.2.3', ['192.168.1.0/24']], [False, -1]),
  ('network sample 20', ['192.168.0.255', ['172.16.5.4/30', '192.168.1.0/24']], [False, -1])],
 [('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('invalid ip returns None', ['10.0.0.300', ['0.0.0.0/0']], None),
  ('network sample 16', ['10.1.2.0', ['1.0.0.256/8']], [False, -1]),
  ('network sample 40', ['10.0.0.300', ['10.0.0.0/8', '10.1.2.0/24', '172.16.5.4/30']], None),
  ('network sample 60', ['255.255.255.255', ['10.0.0.0/33', '10.1.2.3/32', '10.1.2.77/24']], [False, -1])],
 [('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('invalid ip returns None', ['10.0.0.300', ['0.0.0.0/0']], None),
  ('prefix longer than 32 is skipped', ['10.0.0.1', ['10.0.0.0/33', '10.0.0.0/8']], [True, 1]),
  ('network sample 13', ['10.0.0.300', ['10.0.0.0/33', '192.168.0.0/16', '10.1.2.3']], None),
  ('network sample 21', ['10.1.2.3', ['10.1.2.3', '192.168.1.0/24']], [True, 0]),
  ('network sample 51', ['255.255.255.255', ['10.1.2.3', '172.16.0.0/12', '8.8.8.0']], [False, -1])]]
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(ip, cidrs):
    def parse(s):
        parts = s.split('.')
        if len(parts) != 4 or not all(p.isdigit() and int(p) < 255 for p in parts):
            return None
        v = 0
        for p in parts:
            v = v * 256 + int(p)
        return v
    addr = parse(ip)
    if addr is None:
        return None
    for i, c in enumerate(cidrs):
        net, _, bits = c.partition('/')
        bits = bits or '32'
        base = parse(net)
        if base is None or not bits.isdigit() or int(bits) > 32:
            continue
        n = int(bits)
        mask = ((1 << n) - 1) << (32 - n)
        if addr & mask == base & mask:
            return [True, i]
    return [False, -1]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('slash 24 matches inside the network', ['10.1.2.3', ['192.168.0.0/16', '10.1.2.0/24']], [True, 1]),
  ('slash 0 matches everything', ['8.8.8.8', ['0.0.0.0/0']], [True, 0]),
  ('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('invalid ip returns None', ['10.0.0.300', ['0.0.0.0/0']], None),
  ('network sample 1', ['10.1.2.0', ['8.8.8.0', '10.1.2.3/32', '10.0.0.0/8']], [True, 2]),
  ('network sample 2', ['8.8.8.8', ['10.1.2.3/32']], [False, -1])],
 [('slash 0 matches everything', ['8.8.8.8', ['0.0.0.0/0']], [True, 0]),
  ('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('invalid ip returns None', ['10.0.0.300', ['0.0.0.0/0']], None),
  ('network sample 34', ['10.0.0.300', ['10.0.0.0/8']], None),
  ('network sample 55', ['255.255.255.255', ['192.168.1.0/24', '0.0.0.0/0']], [True, 1])],
 [('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('invalid ip returns None', ['10.0.0.300', ['0.0.0.0/0']], None),
  ('network sample 11', ['10.1.2.3', ['192.168.1.0/24']], [False, -1]),
  ('network sample 20', ['192.168.0.255', ['172.16.5.4/30', '192.168.1.0/24']], [False, -1])],
 [('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('invalid ip returns None', ['10.0.0.300', ['0.0.0.0/0']], None),
  ('network sample 16', ['10.1.2.0', ['1.0.0.256/8']], [False, -1]),
  ('network sample 40', ['10.0.0.300', ['10.0.0.0/8', '10.1.2.0/24', '172.16.5.4/30']], None),
  ('network sample 60', ['255.255.255.255', ['10.0.0.0/33', '10.1.2.3/32', '10.1.2.77/24']], [False, -1])],
 [('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('invalid ip returns None', ['10.0.0.300', ['0.0.0.0/0']], None),
  ('prefix longer than 32 is skipped', ['10.0.0.1', ['10.0.0.0/33', '10.0.0.0/8']], [True, 1]),
  ('network sample 13', ['10.0.0.300', ['10.0.0.0/33', '192.168.0.0/16', '10.1.2.3']], None),
  ('network sample 21', ['10.1.2.3', ['10.1.2.3', '192.168.1.0/24']], [True, 0]),
  ('network sample 51', ['255.255.255.255', ['10.1.2.3', '172.16.0.0/12', '8.8.8.0']], [False, -1])]]
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:
An entry such as 1.0.0.256/8 is parsed into an unrelated network instead of being skipped.

ip is dotted-quad IPv4 with octets 0..255 (else return None). Each cidr is "a.b.c.d/n" with 0 <= n <= 32, or a bare address meaning /32; malformed entries are skipped. An entry matches when the top n bits of ip and of its address agree (host bits of the entry are ignored). Return [True, index of first match] or [False, -1].

split: open-access


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

N = 1
observations = []
def solve(ip, cidrs):
    def parse(s):
        parts = s.split('.')
        if len(parts) != 4 or not all(p.isdigit() and int(p) <= 255 for p in parts):
            return None
        v = 0
        for p in parts:
            v = v * 256 + int(p)
        return v
    addr = parse(ip)
    if addr is None:
        return None
    for i, c in enumerate(cidrs):
        net, _, bits = c.partition('/')
        bits = bits or '0'
        base = parse(net)
        if base is None or not bits.isdigit() or int(bits) > 32:
            continue
        n = int(bits)
        mask = ((1 << n) - 1) << (32 - n)
        if addr & mask == base & mask:
            return [True, i]
    return [False, -1]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('slash 24 matches inside the network', ['10.1.2.3', ['192.168.0.0/16', '10.1.2.0/24']], [True, 1]),
  ('slash 0 matches everything', ['8.8.8.8', ['0.0.0.0/0']], [True, 0]),
  ('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('network sample 1', ['10.1.2.0', ['8.8.8.0', '10.1.2.3/32', '10.0.0.0/8']], [True, 2]),
  ('network sample 2', ['8.8.8.8', ['10.1.2.3/32']], [False, -1]),
  ('network sample 3', ['10.1.2.0', ['1.0.0.256/8']], [False, -1])],
 [('slash 0 matches everything', ['8.8.8.8', ['0.0.0.0/0']], [True, 0]),
  ('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network sample 6', ['172.16.5.4', ['192.168.0.0/16', '8.8.8.0', '10.1.2.77/24']], [False, -1]),
  ('network sample 35', ['172.16.5.4', ['8.8.8.0']], [False, -1]),
  ('network sample 37', ['10.1.2.0', ['192.168.0.0/16', '172.16.0.0/12', '10.1.2.3']], [False, -1])],
 [('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('network sample 6', ['172.16.5.4', ['192.168.0.0/16', '8.8.8.0', '10.1.2.77/24']], [False, -1]),
  ('network sample 11', ['10.1.2.3', ['192.168.1.0/24']], [False, -1]),
  ('network sample 12', ['0.0.0.0', ['0.0.0.0/0', '172.16.0.0/12']], [True, 0])],
 [('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('invalid ip returns None', ['10.0.0.300', ['0.0.0.0/0']], None),
  ('network sample 16', ['10.1.2.0', ['1.0.0.256/8']], [False, -1]),
  ('network sample 37', ['10.1.2.0', ['192.168.0.0/16', '172.16.0.0/12', '10.1.2.3']], [False, -1]),
  ('network sample 48', ['0.0.0.0', ['8.8.8.0', '192.168.1.0/24', '172.16.5.4/30']], [False, -1])],
 [('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('invalid ip returns None', ['10.0.0.300', ['0.0.0.0/0']], None),
  ('prefix longer than 32 is skipped', ['10.0.0.1', ['10.0.0.0/33', '10.0.0.0/8']], [True, 1]),
  ('network sample 14', ['172.16.5.4', ['10.0.0.0/33', '10.1.2.3/32', '8.8.8.0']], [False, -1]),
  ('network sample 21', ['10.1.2.3', ['10.1.2.3', '192.168.1.0/24']], [True, 0]),
  ('network sample 22', ['10.1.2.0', ['192.168.0.0/16', '10.0.0.0/8', '8.8.8.0']], [True, 1])]]
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(ip, cidrs):
    def parse(s):
        parts = s.split('.')
        if len(parts) != 4 or not all(p.isdigit() and int(p) <= 255 for p in parts):
            return None
        v = 0
        for p in parts:
            v = v * 256 + int(p)
        return v
    addr = parse(ip)
    if addr is None:
        return None
    for i, c in enumerate(cidrs):
        net, _, bits = c.partition('/')
        bits = bits or '24'
        base = parse(net)
        if base is None or not bits.isdigit() or int(bits) > 32:
            continue
        n = int(bits)
        mask = ((1 << n) - 1) << (32 - n)
        if addr & mask == base & mask:
            return [True, i]
    return [False, -1]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('slash 24 matches inside the network', ['10.1.2.3', ['192.168.0.0/16', '10.1.2.0/24']], [True, 1]),
  ('slash 0 matches everything', ['8.8.8.8', ['0.0.0.0/0']], [True, 0]),
  ('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('network sample 1', ['10.1.2.0', ['8.8.8.0', '10.1.2.3/32', '10.0.0.0/8']], [True, 2]),
  ('network sample 2', ['8.8.8.8', ['10.1.2.3/32']], [False, -1]),
  ('network sample 3', ['10.1.2.0', ['1.0.0.256/8']], [False, -1])],
 [('slash 0 matches everything', ['8.8.8.8', ['0.0.0.0/0']], [True, 0]),
  ('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network sample 6', ['172.16.5.4', ['192.168.0.0/16', '8.8.8.0', '10.1.2.77/24']], [False, -1]),
  ('network sample 35', ['172.16.5.4', ['8.8.8.0']], [False, -1]),
  ('network sample 37', ['10.1.2.0', ['192.168.0.0/16', '172.16.0.0/12', '10.1.2.3']], [False, -1])],
 [('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('network sample 6', ['172.16.5.4', ['192.168.0.0/16', '8.8.8.0', '10.1.2.77/24']], [False, -1]),
  ('network sample 11', ['10.1.2.3', ['192.168.1.0/24']], [False, -1]),
  ('network sample 12', ['0.0.0.0', ['0.0.0.0/0', '172.16.0.0/12']], [True, 0])],
 [('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('invalid ip returns None', ['10.0.0.300', ['0.0.0.0/0']], None),
  ('network sample 16', ['10.1.2.0', ['1.0.0.256/8']], [False, -1]),
  ('network sample 37', ['10.1.2.0', ['192.168.0.0/16', '172.16.0.0/12', '10.1.2.3']], [False, -1]),
  ('network sample 48', ['0.0.0.0', ['8.8.8.0', '192.168.1.0/24', '172.16.5.4/30']], [False, -1])],
 [('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('invalid ip returns None', ['10.0.0.300', ['0.0.0.0/0']], None),
  ('prefix longer than 32 is skipped', ['10.0.0.1', ['10.0.0.0/33', '10.0.0.0/8']], [True, 1]),
  ('network sample 14', ['172.16.5.4', ['10.0.0.0/33', '10.1.2.3/32', '8.8.8.0']], [False, -1]),
  ('network sample 21', ['10.1.2.3', ['10.1.2.3', '192.168.1.0/24']], [True, 0]),
  ('network sample 22', ['10.1.2.0', ['192.168.0.0/16', '10.0.0.0/8', '8.8.8.0']], [True, 1])]]
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:
Listing a single office IP without "/32" opens the feature to the whole internet.

ip is dotted-quad IPv4 with octets 0..255 (else return None). Each cidr is "a.b.c.d/n" with 0 <= n <= 32, or a bare address meaning /32; malformed entries are skipped. An entry matches when the top n bits of ip and of its address agree (host bits of the entry are ignored). Return [True, index of first match] or [False, -1].

split: open-access


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

N = 1
observations = []
def solve(ip, cidrs):
    def parse(s):
        parts = s.split('.')
        if len(parts) != 4 or not all(p.isdigit() and int(p) <= 255 for p in parts):
            return None
        v = 0
        for p in parts:
            v = v * 256 + int(p)
        return v
    addr = parse(ip)
    if addr is None:
        return None
    for i, c in enumerate(cidrs):
        net, _, bits = c.partition('/')
        bits = bits or '32'
        base = parse(net)
        if base is None or not bits.isdigit() or int(bits) > 32:
            continue
        n = int(bits)
        mask = ((1 << n) - 1) << (32 - n)
        if addr & mask == base:
            return [True, i]
    return [False, -1]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('slash 24 matches inside the network', ['10.1.2.3', ['192.168.0.0/16', '10.1.2.0/24']], [True, 1]),
  ('slash 0 matches everything', ['8.8.8.8', ['0.0.0.0/0']], [True, 0]),
  ('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('network sample 1', ['10.1.2.0', ['8.8.8.0', '10.1.2.3/32', '10.0.0.0/8']], [True, 2])],
 [('slash 0 matches everything', ['8.8.8.8', ['0.0.0.0/0']], [True, 0]),
  ('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('network sample 6', ['172.16.5.4', ['192.168.0.0/16', '8.8.8.0', '10.1.2.77/24']], [False, -1]),
  ('network sample 7', ['10.1.2.0', ['0.0.0.0/0']], [True, 0])],
 [('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('network sample 4', ['10.1.2.0', ['10.1.2.0/31']], [True, 0]),
  ('network sample 11', ['10.1.2.3', ['192.168.1.0/24']], [False, -1]),
  ('network sample 12', ['0.0.0.0', ['0.0.0.0/0', '172.16.0.0/12']], [True, 0])],
 [('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('invalid ip returns None', ['10.0.0.300', ['0.0.0.0/0']], None),
  ('network sample 12', ['0.0.0.0', ['0.0.0.0/0', '172.16.0.0/12']], [True, 0]),
  ('network sample 16', ['10.1.2.0', ['1.0.0.256/8']], [False, -1]),
  ('network sample 17', ['10.1.2.0', ['192.168.1.0/24', '10.1.2.3/32', '1.0.0.256/8']], [False, -1])],
 [('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('invalid ip returns None', ['10.0.0.300', ['0.0.0.0/0']], None),
  ('prefix longer than 32 is skipped', ['10.0.0.1', ['10.0.0.0/33', '10.0.0.0/8']], [True, 1]),
  ('network sample 21', ['10.1.2.3', ['10.1.2.3', '192.168.1.0/24']], [True, 0]),
  ('network sample 22', ['10.1.2.0', ['192.168.0.0/16', '10.0.0.0/8', '8.8.8.0']], [True, 1]),
  ('network sample 23', ['172.16.5.4', ['10.1.2.0/24', '10.0.0.0/8', '10.1.2.3']], [False, -1])]]
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(ip, cidrs):
    def parse(s):
        parts = s.split('.')
        if len(parts) != 4 or not all(p.isdigit() and int(p) <= 255 for p in parts):
            return None
        v = 0
        for p in parts:
            v = v * 256 + int(p)
        return v
    addr = parse(ip)
    if addr is None:
        return None
    for i, c in enumerate(cidrs):
        net, _, bits = c.partition('/')
        bits = bits or '32'
        base = parse(net)
        if base is None or not bits.isdigit() or int(bits) > 32:
            continue
        n = int(bits)
        mask = ((1 << n) - 1) << (32 - n)
        if addr & mask == base & mask and addr != base & mask:
            return [True, i]
    return [False, -1]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('slash 24 matches inside the network', ['10.1.2.3', ['192.168.0.0/16', '10.1.2.0/24']], [True, 1]),
  ('slash 0 matches everything', ['8.8.8.8', ['0.0.0.0/0']], [True, 0]),
  ('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('network sample 1', ['10.1.2.0', ['8.8.8.0', '10.1.2.3/32', '10.0.0.0/8']], [True, 2])],
 [('slash 0 matches everything', ['8.8.8.8', ['0.0.0.0/0']], [True, 0]),
  ('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('network sample 6', ['172.16.5.4', ['192.168.0.0/16', '8.8.8.0', '10.1.2.77/24']], [False, -1]),
  ('network sample 7', ['10.1.2.0', ['0.0.0.0/0']], [True, 0])],
 [('octet 256 in an entry is malformed', ['1.0.0.0', ['1.0.0.256/8']], [False, -1]),
  ('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('network sample 4', ['10.1.2.0', ['10.1.2.0/31']], [True, 0]),
  ('network sample 11', ['10.1.2.3', ['192.168.1.0/24']], [False, -1]),
  ('network sample 12', ['0.0.0.0', ['0.0.0.0/0', '172.16.0.0/12']], [True, 0])],
 [('octet 255 is valid', ['192.168.0.255', ['192.168.0.255']], [True, 0]),
  ('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('invalid ip returns None', ['10.0.0.300', ['0.0.0.0/0']], None),
  ('network sample 12', ['0.0.0.0', ['0.0.0.0/0', '172.16.0.0/12']], [True, 0]),
  ('network sample 16', ['10.1.2.0', ['1.0.0.256/8']], [False, -1]),
  ('network sample 17', ['10.1.2.0', ['192.168.1.0/24', '10.1.2.3/32', '1.0.0.256/8']], [False, -1])],
 [('bare address means host route', ['10.1.2.4', ['10.1.2.3']], [False, -1]),
  ('entry with host bits still matches its network', ['10.1.2.9', ['10.1.2.77/24']], [True, 0]),
  ('network address itself matches', ['10.1.2.0', ['10.1.2.0/24']], [True, 0]),
  ('invalid ip returns None', ['10.0.0.300', ['0.0.0.0/0']], None),
  ('prefix longer than 32 is skipped', ['10.0.0.1', ['10.0.0.0/33', '10.0.0.0/8']], [True, 1]),
  ('network sample 21', ['10.1.2.3', ['10.1.2.3', '192.168.1.0/24']], [True, 0]),
  ('network sample 22', ['10.1.2.0', ['192.168.0.0/16', '10.0.0.0/8', '8.8.8.0']], [True, 1]),
  ('network sample 23', ['172.16.5.4', ['10.1.2.0/24', '10.0.0.0/8', '10.1.2.3']], [False, -1])]]
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:
An entry written as 10.1.2.77/24 silently matches nothing.

ip is dotted-quad IPv4 with octets 0..255 (else return None). Each cidr is "a.b.c.d/n" with 0 <= n <= 32, or a bare address meaning /32; malformed entries are skipped. An entry matches when the top n bits of ip and of its address agree (host bits of the entry are ignored). Return [True, index of first match] or [False, -1].

split: open-access


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

N = 1
observations = []
def solve(events, window):
    last = {}
    out = []
    for i in sorted(range(len(events)), key=lambda j: events[j][0]):
        t, user, flag, variant = events[i]
        k = (user, flag)
        if k in last and t - last[k] < window:
            continue
        last[k] = t
        out.append(i)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('variant change emits immediately', [[[0, 'a', 'f', 'on'], [1, 'a', 'f', 'off']], 10], [0, 1]),
  ('different flags are tracked separately', [[[0, 'a', 'f', 'on'], [1, 'a', 'g', 'on']], 10], [0, 1]),
  ('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exposure stream sample 1',
   [[[2, 'a', 'f', 'on'],
     [2, 'b', 'g', 'on'],
     [9, 'a', 'g', 'on'],
     [14, 'b', 'g', 'off'],
     [18, 'a', 'g', 'off'],
     [21, 'b', 'f', 'off'],
     [21, 'b', 'f', 'on'],
     [24, 'a', 'f', 'off']],
    5],
   [0, 1, 2, 3, 4, 5, 6, 7]),
  ('exposure stream sample 2',
   [[[21, 'a', 'f', 'off'],
     [8, 'a', 'g', 'off'],
     [3, 'a', 'f', 'off'],
     [9, 'b', 'f', 'on'],
     [21, 'a', 'g', 'on'],
     [24, 'b', 'g', 'off'],
     [20, 'b', 'f', 'on']],
    0],
   [2, 1, 3, 6, 0, 4, 5]),
  ('exposure stream sample 3',
   [[[2, 'b', 'f', 'on'], [6, 'b', 'f', 'on'], [21, 'b', 'f', 'off'], [24, 'a', 'g', 'on']], 10],
   [0, 2, 3])],
 [('variant change emits immediately', [[[0, 'a', 'f', 'on'], [1, 'a', 'f', 'off']], 10], [0, 1]),
  ('different flags are tracked separately', [[[0, 'a', 'f', 'on'], [1, 'a', 'g', 'on']], 10], [0, 1]),
  ('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('exposure stream sample 23',
   [[[1, 'a', 'g', 'on'],
     [6, 'a', 'g', 'on'],
     [9, 'b', 'f', 'on'],
     [12, 'a', 'f', 'on'],
     [13, 'a', 'f', 'off'],
     [16, 'a', 'g', 'off'],
     [20, 'b', 'f', 'off']],
    10],
   [0, 2, 3, 4, 5, 6]),
  ('exposure stream sample 30',
   [[[1, 'a', 'f', 'off'],
     [5, 'a', 'g', 'on'],
     [13, 'a', 'f', 'off'],
     [7, 'a', 'f', 'on'],
     [20, 'a', 'f', 'on']],
    5],
   [0, 1, 3, 2, 4])],
 [('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('exposure stream sample 11',
   [[[10, 'b', 'g', 'on'], [19, 'b', 'g', 'off'], [9, 'b', 'f', 'on'], [16, 'a', 'f', 'on']], 10],
   [2, 0, 3, 1]),
  ('exposure stream sample 44',
   [[[2, 'b', 'f', 'on'],
     [5, 'b', 'g', 'off'],
     [7, 'b', 'g', 'on'],
     [10, 'a', 'g', 'off'],
     [10, 'a', 'g', 'on']],
    10],
   [0, 1, 2, 3, 4]),
  ('exposure stream sample 51',
   [[[2, 'a', 'f', 'on'],
     [10, 'a', 'g', 'off'],
     [15, 'a', 'f', 'off'],
     [19, 'b', 'f', 'off'],
     [22, 'b', 'f', 'on'],
     [24, 'a', 'f', 'off']],
    10],
   [0, 1, 2, 3, 4])],
 [('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('zero window never suppresses', [[[0, 'a', 'f', 'on'], [0, 'a', 'f', 'on']], 0], [0, 1]),
  ('exposure stream sample 1',
   [[[2, 'a', 'f', 'on'],
     [2, 'b', 'g', 'on'],
     [9, 'a', 'g', 'on'],
     [14, 'b', 'g', 'off'],
     [18, 'a', 'g', 'off'],
     [21, 'b', 'f', 'off'],
     [21, 'b', 'f', 'on'],
     [24, 'a', 'f', 'off']],
    5],
   [0, 1, 2, 3, 4, 5, 6, 7]),
  ('exposure stream sample 12',
   [[[7, 'a', 'f', 'off'],
     [13, 'a', 'g', 'off'],
     [3, 'a', 'g', 'off'],
     [4, 'a', 'f', 'on'],
     [3, 'a', 'g', 'off']],
    10],
   [2, 3, 0, 1]),
  ('exposure stream sample 16',
   [[[4, 'a', 'g', 'off'],
     [21, 'a', 'g', 'off'],
     [20, 'a', 'g', 'off'],
     [23, 'b', 'g', 'on'],
     [19, 'b', 'f', 'on'],
     [22, 'b', 'f', 'on'],
     [10, 'b', 'f', 'on']],
    0],
   [0, 6, 4, 2, 1, 5, 3])],
 [('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('zero window never suppresses', [[[0, 'a', 'f', 'on'], [0, 'a', 'f', 'on']], 0], [0, 1]),
  ('users are tracked separately',
   [[[0, 'a', 'f', 'on'], [1, 'b', 'f', 'on'], [2, 'a', 'f', 'on']], 5],
   [0, 1]),
  ('exposure stream sample 21',
   [[[4, 'a', 'g', 'on'],
     [5, 'a', 'g', 'on'],
     [22, 'a', 'f', 'off'],
     [4, 'a', 'g', 'on'],
     [19, 'a', 'f', 'off'],
     [8, 'a', 'g', 'on'],
     [11, 'a', 'f', 'off']],
    5],
   [0, 6, 4]),
  ('exposure stream sample 24',
   [[[13, 'b', 'g', 'on'],
     [22, 'a', 'g', 'off'],
     [7, 'a', 'f', 'on'],
     [8, 'b', 'f', 'off'],
     [5, 'a', 'f', 'off'],
     [17, 'b', 'f', 'off'],
     [5, 'a', 'g', 'off'],
     [9, 'a', 'g', 'on']],
    5],
   [4, 6, 2, 3, 7, 0, 5, 1]),
  ('exposure stream sample 40',
   [[[5, 'b', 'g', 'on'],
     [22, 'a', 'g', 'on'],
     [20, 'b', 'g', 'off'],
     [1, 'b', 'g', 'off'],
     [22, 'a', 'f', 'off'],
     [9, 'b', 'f', 'on'],
     [15, 'a', 'f', 'on'],
     [5, 'b', 'f', 'off']],
    10],
   [3, 0, 7, 5, 6, 2, 1, 4])]]
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(events, window):
    last = {}
    out = []
    for i in sorted(range(len(events)), key=lambda j: events[j][0]):
        t, user, flag, variant = events[i]
        k = (user, variant)
        if k in last and t - last[k] < window:
            continue
        last[k] = t
        out.append(i)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('variant change emits immediately', [[[0, 'a', 'f', 'on'], [1, 'a', 'f', 'off']], 10], [0, 1]),
  ('different flags are tracked separately', [[[0, 'a', 'f', 'on'], [1, 'a', 'g', 'on']], 10], [0, 1]),
  ('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exposure stream sample 1',
   [[[2, 'a', 'f', 'on'],
     [2, 'b', 'g', 'on'],
     [9, 'a', 'g', 'on'],
     [14, 'b', 'g', 'off'],
     [18, 'a', 'g', 'off'],
     [21, 'b', 'f', 'off'],
     [21, 'b', 'f', 'on'],
     [24, 'a', 'f', 'off']],
    5],
   [0, 1, 2, 3, 4, 5, 6, 7]),
  ('exposure stream sample 2',
   [[[21, 'a', 'f', 'off'],
     [8, 'a', 'g', 'off'],
     [3, 'a', 'f', 'off'],
     [9, 'b', 'f', 'on'],
     [21, 'a', 'g', 'on'],
     [24, 'b', 'g', 'off'],
     [20, 'b', 'f', 'on']],
    0],
   [2, 1, 3, 6, 0, 4, 5]),
  ('exposure stream sample 3',
   [[[2, 'b', 'f', 'on'], [6, 'b', 'f', 'on'], [21, 'b', 'f', 'off'], [24, 'a', 'g', 'on']], 10],
   [0, 2, 3])],
 [('variant change emits immediately', [[[0, 'a', 'f', 'on'], [1, 'a', 'f', 'off']], 10], [0, 1]),
  ('different flags are tracked separately', [[[0, 'a', 'f', 'on'], [1, 'a', 'g', 'on']], 10], [0, 1]),
  ('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('exposure stream sample 23',
   [[[1, 'a', 'g', 'on'],
     [6, 'a', 'g', 'on'],
     [9, 'b', 'f', 'on'],
     [12, 'a', 'f', 'on'],
     [13, 'a', 'f', 'off'],
     [16, 'a', 'g', 'off'],
     [20, 'b', 'f', 'off']],
    10],
   [0, 2, 3, 4, 5, 6]),
  ('exposure stream sample 30',
   [[[1, 'a', 'f', 'off'],
     [5, 'a', 'g', 'on'],
     [13, 'a', 'f', 'off'],
     [7, 'a', 'f', 'on'],
     [20, 'a', 'f', 'on']],
    5],
   [0, 1, 3, 2, 4])],
 [('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('exposure stream sample 11',
   [[[10, 'b', 'g', 'on'], [19, 'b', 'g', 'off'], [9, 'b', 'f', 'on'], [16, 'a', 'f', 'on']], 10],
   [2, 0, 3, 1]),
  ('exposure stream sample 44',
   [[[2, 'b', 'f', 'on'],
     [5, 'b', 'g', 'off'],
     [7, 'b', 'g', 'on'],
     [10, 'a', 'g', 'off'],
     [10, 'a', 'g', 'on']],
    10],
   [0, 1, 2, 3, 4]),
  ('exposure stream sample 51',
   [[[2, 'a', 'f', 'on'],
     [10, 'a', 'g', 'off'],
     [15, 'a', 'f', 'off'],
     [19, 'b', 'f', 'off'],
     [22, 'b', 'f', 'on'],
     [24, 'a', 'f', 'off']],
    10],
   [0, 1, 2, 3, 4])],
 [('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('zero window never suppresses', [[[0, 'a', 'f', 'on'], [0, 'a', 'f', 'on']], 0], [0, 1]),
  ('exposure stream sample 1',
   [[[2, 'a', 'f', 'on'],
     [2, 'b', 'g', 'on'],
     [9, 'a', 'g', 'on'],
     [14, 'b', 'g', 'off'],
     [18, 'a', 'g', 'off'],
     [21, 'b', 'f', 'off'],
     [21, 'b', 'f', 'on'],
     [24, 'a', 'f', 'off']],
    5],
   [0, 1, 2, 3, 4, 5, 6, 7]),
  ('exposure stream sample 12',
   [[[7, 'a', 'f', 'off'],
     [13, 'a', 'g', 'off'],
     [3, 'a', 'g', 'off'],
     [4, 'a', 'f', 'on'],
     [3, 'a', 'g', 'off']],
    10],
   [2, 3, 0, 1]),
  ('exposure stream sample 16',
   [[[4, 'a', 'g', 'off'],
     [21, 'a', 'g', 'off'],
     [20, 'a', 'g', 'off'],
     [23, 'b', 'g', 'on'],
     [19, 'b', 'f', 'on'],
     [22, 'b', 'f', 'on'],
     [10, 'b', 'f', 'on']],
    0],
   [0, 6, 4, 2, 1, 5, 3])],
 [('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('zero window never suppresses', [[[0, 'a', 'f', 'on'], [0, 'a', 'f', 'on']], 0], [0, 1]),
  ('users are tracked separately',
   [[[0, 'a', 'f', 'on'], [1, 'b', 'f', 'on'], [2, 'a', 'f', 'on']], 5],
   [0, 1]),
  ('exposure stream sample 21',
   [[[4, 'a', 'g', 'on'],
     [5, 'a', 'g', 'on'],
     [22, 'a', 'f', 'off'],
     [4, 'a', 'g', 'on'],
     [19, 'a', 'f', 'off'],
     [8, 'a', 'g', 'on'],
     [11, 'a', 'f', 'off']],
    5],
   [0, 6, 4]),
  ('exposure stream sample 24',
   [[[13, 'b', 'g', 'on'],
     [22, 'a', 'g', 'off'],
     [7, 'a', 'f', 'on'],
     [8, 'b', 'f', 'off'],
     [5, 'a', 'f', 'off'],
     [17, 'b', 'f', 'off'],
     [5, 'a', 'g', 'off'],
     [9, 'a', 'g', 'on']],
    5],
   [4, 6, 2, 3, 7, 0, 5, 1]),
  ('exposure stream sample 40',
   [[[5, 'b', 'g', 'on'],
     [22, 'a', 'g', 'on'],
     [20, 'b', 'g', 'off'],
     [1, 'b', 'g', 'off'],
     [22, 'a', 'f', 'off'],
     [9, 'b', 'f', 'on'],
     [15, 'a', 'f', 'on'],
     [5, 'b', 'f', 'off']],
    10],
   [3, 0, 7, 5, 6, 2, 1, 4])]]
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 user re-bucketed to another variant within the window has no exposure logged for the new variant.

events are [t, user, flag, variant] processed in timestamp order (stable for ties). An exposure is emitted unless the same (user, flag, variant) was emitted less than window seconds earlier; suppressed events do not move the window. Return emitted indices in processing order.

split: open-access


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

N = 1
observations = []
def solve(events, window):
    last = {}
    out = []
    for i in sorted(range(len(events)), key=lambda j: events[j][0]):
        t, user, flag, variant = events[i]
        k = (user, flag, variant)
        prev = last.get(k)
        last[k] = t
        if prev is not None and t - prev < window:
            continue
        out.append(i)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('variant change emits immediately', [[[0, 'a', 'f', 'on'], [1, 'a', 'f', 'off']], 10], [0, 1]),
  ('different flags are tracked separately', [[[0, 'a', 'f', 'on'], [1, 'a', 'g', 'on']], 10], [0, 1]),
  ('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exposure stream sample 1',
   [[[2, 'a', 'f', 'on'],
     [2, 'b', 'g', 'on'],
     [9, 'a', 'g', 'on'],
     [14, 'b', 'g', 'off'],
     [18, 'a', 'g', 'off'],
     [21, 'b', 'f', 'off'],
     [21, 'b', 'f', 'on'],
     [24, 'a', 'f', 'off']],
    5],
   [0, 1, 2, 3, 4, 5, 6, 7]),
  ('exposure stream sample 2',
   [[[21, 'a', 'f', 'off'],
     [8, 'a', 'g', 'off'],
     [3, 'a', 'f', 'off'],
     [9, 'b', 'f', 'on'],
     [21, 'a', 'g', 'on'],
     [24, 'b', 'g', 'off'],
     [20, 'b', 'f', 'on']],
    0],
   [2, 1, 3, 6, 0, 4, 5]),
  ('exposure stream sample 3',
   [[[2, 'b', 'f', 'on'], [6, 'b', 'f', 'on'], [21, 'b', 'f', 'off'], [24, 'a', 'g', 'on']], 10],
   [0, 2, 3])],
 [('different flags are tracked separately', [[[0, 'a', 'f', 'on'], [1, 'a', 'g', 'on']], 10], [0, 1]),
  ('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('exposure stream sample 6',
   [[[0, 'a', 'f', 'on'],
     [4, 'a', 'f', 'off'],
     [5, 'b', 'f', 'off'],
     [16, 'a', 'f', 'off'],
     [22, 'b', 'f', 'on']],
    5],
   [0, 1, 2, 3, 4]),
  ('exposure stream sample 7',
   [[[1, 'a', 'f', 'on'],
     [3, 'a', 'g', 'off'],
     [8, 'b', 'g', 'off'],
     [9, 'a', 'f', 'off'],
     [11, 'b', 'f', 'on'],
     [19, 'a', 'g', 'off'],
     [22, 'b', 'f', 'off'],
     [24, 'b', 'f', 'on']],
    5],
   [0, 1, 2, 3, 4, 5, 6, 7]),
  ('exposure stream sample 21',
   [[[4, 'a', 'g', 'on'],
     [5, 'a', 'g', 'on'],
     [22, 'a', 'f', 'off'],
     [4, 'a', 'g', 'on'],
     [19, 'a', 'f', 'off'],
     [8, 'a', 'g', 'on'],
     [11, 'a', 'f', 'off']],
    5],
   [0, 6, 4])],
 [('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('exposure stream sample 11',
   [[[10, 'b', 'g', 'on'], [19, 'b', 'g', 'off'], [9, 'b', 'f', 'on'], [16, 'a', 'f', 'on']], 10],
   [2, 0, 3, 1]),
  ('exposure stream sample 12',
   [[[7, 'a', 'f', 'off'],
     [13, 'a', 'g', 'off'],
     [3, 'a', 'g', 'off'],
     [4, 'a', 'f', 'on'],
     [3, 'a', 'g', 'off']],
    10],
   [2, 3, 0, 1]),
  ('exposure stream sample 56',
   [[[0, 'b', 'g', 'off'],
     [1, 'a', 'g', 'on'],
     [10, 'a', 'f', 'off'],
     [13, 'b', 'f', 'off'],
     [17, 'a', 'g', 'on'],
     [21, 'a', 'g', 'on'],
     [22, 'b', 'g', 'off'],
     [23, 'b', 'f', 'off']],
    10],
   [0, 1, 2, 3, 4, 6, 7])],
 [('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('zero window never suppresses', [[[0, 'a', 'f', 'on'], [0, 'a', 'f', 'on']], 0], [0, 1]),
  ('exposure stream sample 14',
   [[[8, 'a', 'g', 'on'],
     [10, 'a', 'g', 'off'],
     [17, 'b', 'g', 'off'],
     [23, 'a', 'g', 'on'],
     [24, 'a', 'g', 'on']],
    10],
   [0, 1, 2, 3]),
  ('exposure stream sample 16',
   [[[4, 'a', 'g', 'off'],
     [21, 'a', 'g', 'off'],
     [20, 'a', 'g', 'off'],
     [23, 'b', 'g', 'on'],
     [19, 'b', 'f', 'on'],
     [22, 'b', 'f', 'on'],
     [10, 'b', 'f', 'on']],
    0],
   [0, 6, 4, 2, 1, 5, 3])],
 [('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('zero window never suppresses', [[[0, 'a', 'f', 'on'], [0, 'a', 'f', 'on']], 0], [0, 1]),
  ('users are tracked separately',
   [[[0, 'a', 'f', 'on'], [1, 'b', 'f', 'on'], [2, 'a', 'f', 'on']], 5],
   [0, 1]),
  ('exposure stream sample 21',
   [[[4, 'a', 'g', 'on'],
     [5, 'a', 'g', 'on'],
     [22, 'a', 'f', 'off'],
     [4, 'a', 'g', 'on'],
     [19, 'a', 'f', 'off'],
     [8, 'a', 'g', 'on'],
     [11, 'a', 'f', 'off']],
    5],
   [0, 6, 4]),
  ('exposure stream sample 32',
   [[[0, 'b', 'f', 'off'],
     [0, 'b', 'g', 'on'],
     [1, 'a', 'f', 'on'],
     [6, 'b', 'f', 'off'],
     [14, 'a', 'g', 'on'],
     [18, 'b', 'g', 'on'],
     [21, 'b', 'g', 'on'],
     [23, 'a', 'f', 'on']],
    5],
   [0, 1, 2, 3, 4, 5, 7])]]
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(events, window):
    last = {}
    out = []
    for i in sorted(range(len(events)), key=lambda j: events[j][0]):
        t, user, flag, variant = events[i]
        k = (user, flag, variant)
        if k in last and t - last[k] < window:
            continue
        last.setdefault(k, t)
        out.append(i)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('variant change emits immediately', [[[0, 'a', 'f', 'on'], [1, 'a', 'f', 'off']], 10], [0, 1]),
  ('different flags are tracked separately', [[[0, 'a', 'f', 'on'], [1, 'a', 'g', 'on']], 10], [0, 1]),
  ('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exposure stream sample 1',
   [[[2, 'a', 'f', 'on'],
     [2, 'b', 'g', 'on'],
     [9, 'a', 'g', 'on'],
     [14, 'b', 'g', 'off'],
     [18, 'a', 'g', 'off'],
     [21, 'b', 'f', 'off'],
     [21, 'b', 'f', 'on'],
     [24, 'a', 'f', 'off']],
    5],
   [0, 1, 2, 3, 4, 5, 6, 7]),
  ('exposure stream sample 2',
   [[[21, 'a', 'f', 'off'],
     [8, 'a', 'g', 'off'],
     [3, 'a', 'f', 'off'],
     [9, 'b', 'f', 'on'],
     [21, 'a', 'g', 'on'],
     [24, 'b', 'g', 'off'],
     [20, 'b', 'f', 'on']],
    0],
   [2, 1, 3, 6, 0, 4, 5]),
  ('exposure stream sample 3',
   [[[2, 'b', 'f', 'on'], [6, 'b', 'f', 'on'], [21, 'b', 'f', 'off'], [24, 'a', 'g', 'on']], 10],
   [0, 2, 3])],
 [('different flags are tracked separately', [[[0, 'a', 'f', 'on'], [1, 'a', 'g', 'on']], 10], [0, 1]),
  ('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('exposure stream sample 6',
   [[[0, 'a', 'f', 'on'],
     [4, 'a', 'f', 'off'],
     [5, 'b', 'f', 'off'],
     [16, 'a', 'f', 'off'],
     [22, 'b', 'f', 'on']],
    5],
   [0, 1, 2, 3, 4]),
  ('exposure stream sample 7',
   [[[1, 'a', 'f', 'on'],
     [3, 'a', 'g', 'off'],
     [8, 'b', 'g', 'off'],
     [9, 'a', 'f', 'off'],
     [11, 'b', 'f', 'on'],
     [19, 'a', 'g', 'off'],
     [22, 'b', 'f', 'off'],
     [24, 'b', 'f', 'on']],
    5],
   [0, 1, 2, 3, 4, 5, 6, 7]),
  ('exposure stream sample 21',
   [[[4, 'a', 'g', 'on'],
     [5, 'a', 'g', 'on'],
     [22, 'a', 'f', 'off'],
     [4, 'a', 'g', 'on'],
     [19, 'a', 'f', 'off'],
     [8, 'a', 'g', 'on'],
     [11, 'a', 'f', 'off']],
    5],
   [0, 6, 4])],
 [('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('exposure stream sample 11',
   [[[10, 'b', 'g', 'on'], [19, 'b', 'g', 'off'], [9, 'b', 'f', 'on'], [16, 'a', 'f', 'on']], 10],
   [2, 0, 3, 1]),
  ('exposure stream sample 12',
   [[[7, 'a', 'f', 'off'],
     [13, 'a', 'g', 'off'],
     [3, 'a', 'g', 'off'],
     [4, 'a', 'f', 'on'],
     [3, 'a', 'g', 'off']],
    10],
   [2, 3, 0, 1]),
  ('exposure stream sample 56',
   [[[0, 'b', 'g', 'off'],
     [1, 'a', 'g', 'on'],
     [10, 'a', 'f', 'off'],
     [13, 'b', 'f', 'off'],
     [17, 'a', 'g', 'on'],
     [21, 'a', 'g', 'on'],
     [22, 'b', 'g', 'off'],
     [23, 'b', 'f', 'off']],
    10],
   [0, 1, 2, 3, 4, 6, 7])],
 [('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('zero window never suppresses', [[[0, 'a', 'f', 'on'], [0, 'a', 'f', 'on']], 0], [0, 1]),
  ('exposure stream sample 14',
   [[[8, 'a', 'g', 'on'],
     [10, 'a', 'g', 'off'],
     [17, 'b', 'g', 'off'],
     [23, 'a', 'g', 'on'],
     [24, 'a', 'g', 'on']],
    10],
   [0, 1, 2, 3]),
  ('exposure stream sample 16',
   [[[4, 'a', 'g', 'off'],
     [21, 'a', 'g', 'off'],
     [20, 'a', 'g', 'off'],
     [23, 'b', 'g', 'on'],
     [19, 'b', 'f', 'on'],
     [22, 'b', 'f', 'on'],
     [10, 'b', 'f', 'on']],
    0],
   [0, 6, 4, 2, 1, 5, 3])],
 [('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('zero window never suppresses', [[[0, 'a', 'f', 'on'], [0, 'a', 'f', 'on']], 0], [0, 1]),
  ('users are tracked separately',
   [[[0, 'a', 'f', 'on'], [1, 'b', 'f', 'on'], [2, 'a', 'f', 'on']], 5],
   [0, 1]),
  ('exposure stream sample 21',
   [[[4, 'a', 'g', 'on'],
     [5, 'a', 'g', 'on'],
     [22, 'a', 'f', 'off'],
     [4, 'a', 'g', 'on'],
     [19, 'a', 'f', 'off'],
     [8, 'a', 'g', 'on'],
     [11, 'a', 'f', 'off']],
    5],
   [0, 6, 4]),
  ('exposure stream sample 32',
   [[[0, 'b', 'f', 'off'],
     [0, 'b', 'g', 'on'],
     [1, 'a', 'f', 'on'],
     [6, 'b', 'f', 'off'],
     [14, 'a', 'g', 'on'],
     [18, 'b', 'g', 'on'],
     [21, 'b', 'g', 'on'],
     [23, 'a', 'f', 'on']],
    5],
   [0, 1, 2, 3, 4, 5, 7])]]
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 frequently active user is exposed once and then never again.

events are [t, user, flag, variant] processed in timestamp order (stable for ties). An exposure is emitted unless the same (user, flag, variant) was emitted less than window seconds earlier; suppressed events do not move the window. Return emitted indices in processing order.

split: open-access