broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(teams):
    def pct(w, l):
        return Fraction(w, w + l) if w + l else Fraction(0)
    rows = sorted(teams, key=lambda r: (-pct(r[1], r[2]), -r[1], r[0]))
    lw, ll = rows[0][1], rows[0][2]
    out = []
    for name, w, l in rows:
        p = '%.3f' % float(pct(w, l))
        if p.startswith('0'):
            p = p[1:]
        gb2 = (lw - w) + (l - ll)
        gb = '-' if gb2 == 0 else '%.1f' % gb2
        out.append([name, p, gb])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: games behind halving',
   ([['Wolves', 0, 17], ['Cats', 0, 34]],),
   [['Cats', '.000', '-'], ['Wolves', '.000', '-8.5']]),
  ('variant scenario 1',
   ([['Suns', 3, 25], ['Jets', 6, 50], ['Wolves', 22, 18], ['Bucks', 18, 4]],),
   [['Bucks', '.818', '-'],
    ['Wolves', '.550', '5.0'],
    ['Jets', '.107', '29.0'],
    ['Suns', '.107', '18.0']]),
  ('variant scenario 2',
   ([['Cats', 11, 25], ['Suns', 21, 0], ['Bucks', 10, 10], ['Jets', 31, 7]],),
   [['Suns', '1.000', '-'],
    ['Jets', '.816', '-1.5'],
    ['Bucks', '.500', '10.5'],
    ['Cats', '.306', '17.5']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: games behind halving',
   ([['Cats', 0, 10], ['Jets', 8, 2], ['Wolves', 21, 9]],),
   [['Jets', '.800', '-'], ['Wolves', '.700', '-3.0'], ['Cats', '.000', '8.0']]),
  ('variant scenario 1',
   ([['Wolves', 1, 30], ['Cats', 3, 7], ['Bucks', 17, 22]],),
   [['Bucks', '.436', '-'], ['Cats', '.300', '-0.5'], ['Wolves', '.032', '12.0']]),
  ('variant scenario 2',
   ([['Cats', 14, 6], ['Suns', 5, 5], ['Jets', 19, 12], ['Wolves', 2, 0], ['Bucks', 2, 29]],),
   [['Wolves', '1.000', '-'],
    ['Cats', '.700', '-3.0'],
    ['Jets', '.613', '-2.5'],
    ['Suns', '.500', '1.0'],
    ['Bucks', '.065', '14.5']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: games behind halving',
   ([['Bucks', 0, 0], ['Suns', 7, 19], ['Wolves', 3, 14], ['Cats', 4, 1]],),
   [['Cats', '.800', '-'],
    ['Suns', '.269', '7.5'],
    ['Wolves', '.176', '7.0'],
    ['Bucks', '.000', '1.5']]),
  ('variant scenario 1',
   ([['Jets', 0, 30], ['Wolves', 1, 6], ['Bucks', 25, 5], ['Suns', 0, 1]],),
   [['Bucks', '.833', '-'],
    ['Wolves', '.143', '12.5'],
    ['Jets', '.000', '25.0'],
    ['Suns', '.000', '10.5']]),
  ('variant scenario 2',
   ([['Cats', 12, 6], ['Jets', 5, 15], ['Wolves', 9, 30], ['Bucks', 1, 0], ['Suns', 6, 4]],),
   [['Bucks', '1.000', '-'],
    ['Cats', '.667', '-2.5'],
    ['Suns', '.600', '-0.5'],
    ['Jets', '.250', '5.5'],
    ['Wolves', '.231', '11.0']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: games behind halving',
   ([['Suns', 7, 3], ['Jets', 12, 14]],),
   [['Suns', '.700', '-'], ['Jets', '.462', '3.0']]),
  ('variant scenario 1',
   ([['Wolves', 1, 3], ['Bucks', 1, 19]],),
   [['Wolves', '.250', '-'], ['Bucks', '.050', '8.0']]),
  ('variant scenario 2',
   ([['Jets', 0, 1], ['Cats', 25, 5], ['Suns', 3, 8], ['Wolves', 6, 10]],),
   [['Cats', '.833', '-'],
    ['Wolves', '.375', '12.0'],
    ['Suns', '.273', '12.5'],
    ['Jets', '.000', '10.5']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: games behind halving',
   ([['Wolves', 0, 4], ['Jets', 14, 1]],),
   [['Jets', '.933', '-'], ['Wolves', '.000', '8.5']]),
  ('variant scenario 1',
   ([['Cats', 1, 16], ['Bucks', 1, 5], ['Jets', 4, 6], ['Suns', 0, 30], ['Wolves', 27, 11]],),
   [['Wolves', '.711', '-'],
    ['Jets', '.400', '9.0'],
    ['Bucks', '.167', '10.0'],
    ['Cats', '.059', '15.5'],
    ['Suns', '.000', '23.0']]),
  ('variant scenario 2',
   ([['Wolves', 6, 33], ['Bucks', 0, 0]],),
   [['Wolves', '.154', '-'], ['Bucks', '.000', '-13.5']])]]
for label, args, expected in cases[N - 1]:
    check(label, run(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(teams):
    def pct(w, l):
        return Fraction(w, w + l) if w + l else Fraction(0)
    rows = sorted(teams, key=lambda r: (-pct(r[1], r[2]), -r[1], r[0]))
    lw, ll = rows[0][1], rows[0][2]
    out = []
    for name, w, l in rows:
        p = '%.3f' % float(pct(w, l))
        if p.startswith('0'):
            p = p[1:]
        gb2 = 2 * (lw - w)
        gb = '-' if gb2 == 0 else '%.1f' % (gb2 / 2)
        out.append([name, p, gb])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: games behind halving',
   ([['Wolves', 0, 17], ['Cats', 0, 34]],),
   [['Cats', '.000', '-'], ['Wolves', '.000', '-8.5']]),
  ('variant scenario 1',
   ([['Suns', 3, 25], ['Jets', 6, 50], ['Wolves', 22, 18], ['Bucks', 18, 4]],),
   [['Bucks', '.818', '-'],
    ['Wolves', '.550', '5.0'],
    ['Jets', '.107', '29.0'],
    ['Suns', '.107', '18.0']]),
  ('variant scenario 2',
   ([['Cats', 11, 25], ['Suns', 21, 0], ['Bucks', 10, 10], ['Jets', 31, 7]],),
   [['Suns', '1.000', '-'],
    ['Jets', '.816', '-1.5'],
    ['Bucks', '.500', '10.5'],
    ['Cats', '.306', '17.5']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: games behind halving',
   ([['Cats', 0, 10], ['Jets', 8, 2], ['Wolves', 21, 9]],),
   [['Jets', '.800', '-'], ['Wolves', '.700', '-3.0'], ['Cats', '.000', '8.0']]),
  ('variant scenario 1',
   ([['Wolves', 1, 30], ['Cats', 3, 7], ['Bucks', 17, 22]],),
   [['Bucks', '.436', '-'], ['Cats', '.300', '-0.5'], ['Wolves', '.032', '12.0']]),
  ('variant scenario 2',
   ([['Cats', 14, 6], ['Suns', 5, 5], ['Jets', 19, 12], ['Wolves', 2, 0], ['Bucks', 2, 29]],),
   [['Wolves', '1.000', '-'],
    ['Cats', '.700', '-3.0'],
    ['Jets', '.613', '-2.5'],
    ['Suns', '.500', '1.0'],
    ['Bucks', '.065', '14.5']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: games behind halving',
   ([['Bucks', 0, 0], ['Suns', 7, 19], ['Wolves', 3, 14], ['Cats', 4, 1]],),
   [['Cats', '.800', '-'],
    ['Suns', '.269', '7.5'],
    ['Wolves', '.176', '7.0'],
    ['Bucks', '.000', '1.5']]),
  ('variant scenario 1',
   ([['Jets', 0, 30], ['Wolves', 1, 6], ['Bucks', 25, 5], ['Suns', 0, 1]],),
   [['Bucks', '.833', '-'],
    ['Wolves', '.143', '12.5'],
    ['Jets', '.000', '25.0'],
    ['Suns', '.000', '10.5']]),
  ('variant scenario 2',
   ([['Cats', 12, 6], ['Jets', 5, 15], ['Wolves', 9, 30], ['Bucks', 1, 0], ['Suns', 6, 4]],),
   [['Bucks', '1.000', '-'],
    ['Cats', '.667', '-2.5'],
    ['Suns', '.600', '-0.5'],
    ['Jets', '.250', '5.5'],
    ['Wolves', '.231', '11.0']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: games behind halving',
   ([['Suns', 7, 3], ['Jets', 12, 14]],),
   [['Suns', '.700', '-'], ['Jets', '.462', '3.0']]),
  ('variant scenario 1',
   ([['Wolves', 1, 3], ['Bucks', 1, 19]],),
   [['Wolves', '.250', '-'], ['Bucks', '.050', '8.0']]),
  ('variant scenario 2',
   ([['Jets', 0, 1], ['Cats', 25, 5], ['Suns', 3, 8], ['Wolves', 6, 10]],),
   [['Cats', '.833', '-'],
    ['Wolves', '.375', '12.0'],
    ['Suns', '.273', '12.5'],
    ['Jets', '.000', '10.5']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: games behind halving',
   ([['Wolves', 0, 4], ['Jets', 14, 1]],),
   [['Jets', '.933', '-'], ['Wolves', '.000', '8.5']]),
  ('variant scenario 1',
   ([['Cats', 1, 16], ['Bucks', 1, 5], ['Jets', 4, 6], ['Suns', 0, 30], ['Wolves', 27, 11]],),
   [['Wolves', '.711', '-'],
    ['Jets', '.400', '9.0'],
    ['Bucks', '.167', '10.0'],
    ['Cats', '.059', '15.5'],
    ['Suns', '.000', '23.0']]),
  ('variant scenario 2',
   ([['Wolves', 6, 33], ['Bucks', 0, 0]],),
   [['Wolves', '.154', '-'], ['Bucks', '.000', '-13.5']])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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 team one win and one loss back is shown 2.0 games behind.

Division standings. teams rows are [name, wins, losses]. Win percentage is wins / games (0 for no games) shown with three decimals and the leading zero dropped (".500", but "1.000"). Sort by win percentage, then more wins, then name. The leader is the first sorted row; games behind = ((leader_wins - wins) + (losses - leader_losses)) / 2, shown as "-" when zero and otherwise with one decimal (negative values allowed). Return [name, pct, gb] rows.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(teams):
    def pct(w, l):
        return Fraction(w, w + l) if w + l else Fraction(0)
    rows = sorted(teams, key=lambda r: (-pct(r[1], r[2]), -r[1], r[0]))
    lw, ll = max((r[1], r[2]) for r in teams)
    out = []
    for name, w, l in rows:
        p = '%.3f' % float(pct(w, l))
        if p.startswith('0'):
            p = p[1:]
        gb2 = (lw - w) + (l - ll)
        gb = '-' if gb2 == 0 else '%.1f' % (gb2 / 2)
        out.append([name, p, gb])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: leader selection',
   ([['Jets', 0, 33], ['Cats', 0, 66], ['Bucks', 1, 6], ['Wolves', 6, 3]],),
   [['Wolves', '.667', '-'],
    ['Bucks', '.143', '4.0'],
    ['Cats', '.000', '34.5'],
    ['Jets', '.000', '18.0']]),
  ('regression: leader selection',
   ([['Jets', 4, 16], ['Cats', 25, 15], ['Suns', 2, 0], ['Bucks', 25, 12], ['Wolves', 9, 8]],),
   [['Suns', '1.000', '-'],
    ['Bucks', '.676', '-5.5'],
    ['Cats', '.625', '-4.0'],
    ['Wolves', '.529', '0.5'],
    ['Jets', '.200', '7.0']]),
  ('variant scenario 1',
   ([['Suns', 14, 1], ['Jets', 7, 23], ['Cats', 2, 3], ['Wolves', 1, 9]],),
   [['Suns', '.933', '-'],
    ['Cats', '.400', '7.0'],
    ['Jets', '.233', '14.5'],
    ['Wolves', '.100', '10.5']]),
  ('variant scenario 2',
   ([['Wolves', 4, 0], ['Suns', 3, 14], ['Cats', 18, 1], ['Bucks', 0, 11]],),
   [['Wolves', '1.000', '-'],
    ['Cats', '.947', '-6.5'],
    ['Suns', '.176', '7.5'],
    ['Bucks', '.000', '7.5']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: leader selection',
   ([['Bucks', 1, 8], ['Wolves', 39, 1]],),
   [['Wolves', '.975', '-'], ['Bucks', '.111', '22.5']]),
  ('regression: leader selection',
   ([['Cats', 9, 1], ['Suns', 8, 2], ['Jets', 4, 4], ['Wolves', 15, 18]],),
   [['Cats', '.900', '-'],
    ['Suns', '.800', '1.0'],
    ['Jets', '.500', '4.0'],
    ['Wolves', '.455', '5.5']]),
  ('variant scenario 1',
   ([['Wolves', 29, 11], ['Jets', 9, 10], ['Bucks', 4, 2]],),
   [['Wolves', '.725', '-'], ['Bucks', '.667', '8.0'], ['Jets', '.474', '9.5']]),
  ('variant scenario 2',
   ([['Bucks', 7, 9], ['Wolves', 15, 16], ['Jets', 5, 8]],),
   [['Wolves', '.484', '-'], ['Bucks', '.438', '0.5'], ['Jets', '.385', '1.0']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: leader selection',
   ([['Wolves', 7, 25], ['Jets', 6, 20], ['Bucks', 0, 15]],),
   [['Jets', '.231', '-'], ['Wolves', '.219', '2.0'], ['Bucks', '.000', '0.5']]),
  ('variant scenario 1',
   ([['Wolves', 0, 1], ['Cats', 0, 0], ['Suns', 19, 20], ['Jets', 5, 10], ['Bucks', 14, 23]],),
   [['Suns', '.487', '-'],
    ['Bucks', '.378', '4.0'],
    ['Jets', '.333', '2.0'],
    ['Cats', '.000', '-0.5'],
    ['Wolves', '.000', '-']]),
  ('variant scenario 2',
   ([['Jets', 4, 15], ['Cats', 4, 18], ['Suns', 7, 27], ['Wolves', 13, 7], ['Bucks', 1, 6]],),
   [['Wolves', '.650', '-'],
    ['Jets', '.211', '8.5'],
    ['Suns', '.206', '13.0'],
    ['Cats', '.182', '10.0'],
    ['Bucks', '.143', '5.5']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: leader selection',
   ([['Jets', 17, 11], ['Bucks', 34, 22]],),
   [['Bucks', '.607', '-'], ['Jets', '.607', '3.0']]),
  ('regression: leader selection',
   ([['Cats', 14, 9], ['Jets', 10, 3], ['Wolves', 1, 15], ['Bucks', 2, 18], ['Suns', 7, 32]],),
   [['Jets', '.769', '-'],
    ['Cats', '.609', '1.0'],
    ['Suns', '.179', '16.0'],
    ['Bucks', '.100', '11.5'],
    ['Wolves', '.062', '10.5']]),
  ('variant scenario 1',
   ([['Cats', 8, 15], ['Jets', 16, 30], ['Wolves', 0, 7], ['Bucks', 22, 4], ['Suns', 4, 8]],),
   [['Bucks', '.846', '-'],
    ['Jets', '.348', '16.0'],
    ['Cats', '.348', '12.5'],
    ['Suns', '.333', '11.0'],
    ['Wolves', '.000', '12.5']]),
  ('variant scenario 2',
   ([['Bucks', 32, 2], ['Suns', 64, 4], ['Wolves', 8, 12], ['Cats', 7, 13], ['Jets', 13, 15]],),
   [['Suns', '.941', '-'],
    ['Bucks', '.941', '15.0'],
    ['Jets', '.464', '31.0'],
    ['Wolves', '.400', '32.0'],
    ['Cats', '.350', '33.0']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: leader selection',
   ([['Cats', 9, 3], ['Jets', 12, 4]],),
   [['Jets', '.750', '-'], ['Cats', '.750', '1.0']]),
  ('regression: leader selection',
   ([['Jets', 14, 7], ['Suns', 7, 12], ['Bucks', 23, 7], ['Cats', 8, 12], ['Wolves', 20, 0]],),
   [['Wolves', '1.000', '-'],
    ['Bucks', '.767', '2.0'],
    ['Jets', '.667', '6.5'],
    ['Cats', '.400', '12.0'],
    ['Suns', '.368', '12.5']]),
  ('variant scenario 1',
   ([['Suns', 20, 1], ['Wolves', 2, 2], ['Jets', 1, 4], ['Bucks', 1, 1], ['Cats', 0, 1]],),
   [['Suns', '.952', '-'],
    ['Wolves', '.500', '9.5'],
    ['Bucks', '.500', '9.5'],
    ['Jets', '.200', '11.0'],
    ['Cats', '.000', '10.0']]),
  ('variant scenario 2',
   ([['Wolves', 1, 0], ['Cats', 0, 4]],),
   [['Wolves', '1.000', '-'], ['Cats', '.000', '2.5']])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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
from fractions import Fraction
N = 1
observations = []
def solve(teams):
    def pct(w, l):
        return Fraction(w, w + l) if w + l else Fraction(0)
    rows = sorted(teams, key=lambda r: (-pct(r[1], r[2]), -r[1], r[0]))
    lw, ll = teams[0][1], teams[0][2]
    out = []
    for name, w, l in rows:
        p = '%.3f' % float(pct(w, l))
        if p.startswith('0'):
            p = p[1:]
        gb2 = (lw - w) + (l - ll)
        gb = '-' if gb2 == 0 else '%.1f' % (gb2 / 2)
        out.append([name, p, gb])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: leader selection',
   ([['Jets', 0, 33], ['Cats', 0, 66], ['Bucks', 1, 6], ['Wolves', 6, 3]],),
   [['Wolves', '.667', '-'],
    ['Bucks', '.143', '4.0'],
    ['Cats', '.000', '34.5'],
    ['Jets', '.000', '18.0']]),
  ('regression: leader selection',
   ([['Jets', 4, 16], ['Cats', 25, 15], ['Suns', 2, 0], ['Bucks', 25, 12], ['Wolves', 9, 8]],),
   [['Suns', '1.000', '-'],
    ['Bucks', '.676', '-5.5'],
    ['Cats', '.625', '-4.0'],
    ['Wolves', '.529', '0.5'],
    ['Jets', '.200', '7.0']]),
  ('variant scenario 1',
   ([['Suns', 14, 1], ['Jets', 7, 23], ['Cats', 2, 3], ['Wolves', 1, 9]],),
   [['Suns', '.933', '-'],
    ['Cats', '.400', '7.0'],
    ['Jets', '.233', '14.5'],
    ['Wolves', '.100', '10.5']]),
  ('variant scenario 2',
   ([['Wolves', 4, 0], ['Suns', 3, 14], ['Cats', 18, 1], ['Bucks', 0, 11]],),
   [['Wolves', '1.000', '-'],
    ['Cats', '.947', '-6.5'],
    ['Suns', '.176', '7.5'],
    ['Bucks', '.000', '7.5']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: leader selection',
   ([['Bucks', 1, 8], ['Wolves', 39, 1]],),
   [['Wolves', '.975', '-'], ['Bucks', '.111', '22.5']]),
  ('regression: leader selection',
   ([['Cats', 9, 1], ['Suns', 8, 2], ['Jets', 4, 4], ['Wolves', 15, 18]],),
   [['Cats', '.900', '-'],
    ['Suns', '.800', '1.0'],
    ['Jets', '.500', '4.0'],
    ['Wolves', '.455', '5.5']]),
  ('variant scenario 1',
   ([['Wolves', 29, 11], ['Jets', 9, 10], ['Bucks', 4, 2]],),
   [['Wolves', '.725', '-'], ['Bucks', '.667', '8.0'], ['Jets', '.474', '9.5']]),
  ('variant scenario 2',
   ([['Bucks', 7, 9], ['Wolves', 15, 16], ['Jets', 5, 8]],),
   [['Wolves', '.484', '-'], ['Bucks', '.438', '0.5'], ['Jets', '.385', '1.0']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: leader selection',
   ([['Wolves', 7, 25], ['Jets', 6, 20], ['Bucks', 0, 15]],),
   [['Jets', '.231', '-'], ['Wolves', '.219', '2.0'], ['Bucks', '.000', '0.5']]),
  ('variant scenario 1',
   ([['Wolves', 0, 1], ['Cats', 0, 0], ['Suns', 19, 20], ['Jets', 5, 10], ['Bucks', 14, 23]],),
   [['Suns', '.487', '-'],
    ['Bucks', '.378', '4.0'],
    ['Jets', '.333', '2.0'],
    ['Cats', '.000', '-0.5'],
    ['Wolves', '.000', '-']]),
  ('variant scenario 2',
   ([['Jets', 4, 15], ['Cats', 4, 18], ['Suns', 7, 27], ['Wolves', 13, 7], ['Bucks', 1, 6]],),
   [['Wolves', '.650', '-'],
    ['Jets', '.211', '8.5'],
    ['Suns', '.206', '13.0'],
    ['Cats', '.182', '10.0'],
    ['Bucks', '.143', '5.5']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: leader selection',
   ([['Jets', 17, 11], ['Bucks', 34, 22]],),
   [['Bucks', '.607', '-'], ['Jets', '.607', '3.0']]),
  ('regression: leader selection',
   ([['Cats', 14, 9], ['Jets', 10, 3], ['Wolves', 1, 15], ['Bucks', 2, 18], ['Suns', 7, 32]],),
   [['Jets', '.769', '-'],
    ['Cats', '.609', '1.0'],
    ['Suns', '.179', '16.0'],
    ['Bucks', '.100', '11.5'],
    ['Wolves', '.062', '10.5']]),
  ('variant scenario 1',
   ([['Cats', 8, 15], ['Jets', 16, 30], ['Wolves', 0, 7], ['Bucks', 22, 4], ['Suns', 4, 8]],),
   [['Bucks', '.846', '-'],
    ['Jets', '.348', '16.0'],
    ['Cats', '.348', '12.5'],
    ['Suns', '.333', '11.0'],
    ['Wolves', '.000', '12.5']]),
  ('variant scenario 2',
   ([['Bucks', 32, 2], ['Suns', 64, 4], ['Wolves', 8, 12], ['Cats', 7, 13], ['Jets', 13, 15]],),
   [['Suns', '.941', '-'],
    ['Bucks', '.941', '15.0'],
    ['Jets', '.464', '31.0'],
    ['Wolves', '.400', '32.0'],
    ['Cats', '.350', '33.0']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: leader selection',
   ([['Cats', 9, 3], ['Jets', 12, 4]],),
   [['Jets', '.750', '-'], ['Cats', '.750', '1.0']]),
  ('regression: leader selection',
   ([['Jets', 14, 7], ['Suns', 7, 12], ['Bucks', 23, 7], ['Cats', 8, 12], ['Wolves', 20, 0]],),
   [['Wolves', '1.000', '-'],
    ['Bucks', '.767', '2.0'],
    ['Jets', '.667', '6.5'],
    ['Cats', '.400', '12.0'],
    ['Suns', '.368', '12.5']]),
  ('variant scenario 1',
   ([['Suns', 20, 1], ['Wolves', 2, 2], ['Jets', 1, 4], ['Bucks', 1, 1], ['Cats', 0, 1]],),
   [['Suns', '.952', '-'],
    ['Wolves', '.500', '9.5'],
    ['Bucks', '.500', '9.5'],
    ['Jets', '.200', '11.0'],
    ['Cats', '.000', '10.0']]),
  ('variant scenario 2',
   ([['Wolves', 1, 0], ['Cats', 0, 4]],),
   [['Wolves', '1.000', '-'], ['Cats', '.000', '2.5']])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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:
Games behind is computed from the team with the most wins rather than the best percentage.

Division standings. teams rows are [name, wins, losses]. Win percentage is wins / games (0 for no games) shown with three decimals and the leading zero dropped (".500", but "1.000"). Sort by win percentage, then more wins, then name. The leader is the first sorted row; games behind = ((leader_wins - wins) + (losses - leader_losses)) / 2, shown as "-" when zero and otherwise with one decimal (negative values allowed). Return [name, pct, gb] rows.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(teams):
    def pct(w, l):
        return Fraction(w, w + l) if w + l else Fraction(0)
    rows = sorted(teams, key=lambda r: (-pct(r[1], r[2]), r[0]))
    lw, ll = rows[0][1], rows[0][2]
    out = []
    for name, w, l in rows:
        p = '%.3f' % float(pct(w, l))
        if p.startswith('0'):
            p = p[1:]
        gb2 = (lw - w) + (l - ll)
        gb = '-' if gb2 == 0 else '%.1f' % (gb2 / 2)
        out.append([name, p, gb])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: equal percentage order',
   ([['Cats', 3, 8], ['Wolves', 6, 16], ['Jets', 3, 11], ['Suns', 0, 4]],),
   [['Wolves', '.273', '-'],
    ['Cats', '.273', '-2.5'],
    ['Jets', '.214', '-1.0'],
    ['Suns', '.000', '-3.0']]),
  ('variant scenario 1',
   ([['Suns', 9, 0], ['Cats', 19, 11], ['Bucks', 6, 7]],),
   [['Suns', '1.000', '-'], ['Cats', '.633', '0.5'], ['Bucks', '.462', '5.0']]),
  ('variant scenario 2',
   ([['Cats', 8, 15], ['Jets', 18, 12], ['Wolves', 6, 3]],),
   [['Wolves', '.667', '-'], ['Jets', '.600', '-1.5'], ['Cats', '.348', '5.0']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: equal percentage order',
   ([['Cats', 1, 0], ['Jets', 15, 5], ['Wolves', 0, 0], ['Suns', 15, 0]],),
   [['Suns', '1.000', '-'],
    ['Cats', '1.000', '7.0'],
    ['Jets', '.750', '2.5'],
    ['Wolves', '.000', '7.5']]),
  ('variant scenario 1',
   ([['Suns', 8, 18], ['Cats', 30, 2], ['Jets', 0, 33], ['Bucks', 2, 3], ['Wolves', 1, 9]],),
   [['Cats', '.938', '-'],
    ['Bucks', '.400', '14.5'],
    ['Suns', '.308', '19.0'],
    ['Wolves', '.100', '18.0'],
    ['Jets', '.000', '30.5']]),
  ('variant scenario 2',
   ([['Bucks', 10, 19], ['Suns', 27, 4], ['Jets', 31, 0]],),
   [['Jets', '1.000', '-'], ['Suns', '.871', '4.0'], ['Bucks', '.345', '20.0']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: equal percentage order',
   ([['Bucks', 14, 20], ['Jets', 28, 40], ['Wolves', 14, 19], ['Suns', 0, 10]],),
   [['Wolves', '.424', '-'],
    ['Jets', '.412', '3.5'],
    ['Bucks', '.412', '0.5'],
    ['Suns', '.000', '2.5']]),
  ('variant scenario 1',
   ([['Cats', 2, 15], ['Suns', 1, 7]],),
   [['Suns', '.125', '-'], ['Cats', '.118', '3.5']]),
  ('variant scenario 2',
   ([['Bucks', 2, 17], ['Suns', 9, 11]],),
   [['Suns', '.450', '-'], ['Bucks', '.105', '6.5']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: equal percentage order',
   ([['Wolves', 4, 18], ['Suns', 8, 36], ['Cats', 4, 35], ['Jets', 10, 27]],),
   [['Jets', '.270', '-'],
    ['Suns', '.182', '5.5'],
    ['Wolves', '.182', '-1.5'],
    ['Cats', '.103', '7.0']]),
  ('regression: equal percentage order',
   ([['Jets', 7, 16], ['Wolves', 14, 32], ['Suns', 3, 15]],),
   [['Wolves', '.304', '-'], ['Jets', '.304', '-4.5'], ['Suns', '.167', '-3.0']]),
  ('variant scenario 1',
   ([['Bucks', 5, 10], ['Cats', 16, 0]],),
   [['Cats', '1.000', '-'], ['Bucks', '.333', '10.5']]),
  ('variant scenario 2',
   ([['Jets', 11, 19], ['Bucks', 22, 38]],),
   [['Bucks', '.367', '-'], ['Jets', '.367', '-4.0']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: equal percentage order',
   ([['Bucks', 1, 3], ['Suns', 2, 6], ['Cats', 15, 15]],),
   [['Cats', '.500', '-'], ['Suns', '.250', '2.0'], ['Bucks', '.250', '1.0']]),
  ('variant scenario 1',
   ([['Cats', 4, 26], ['Jets', 8, 52], ['Suns', 6, 27]],),
   [['Suns', '.182', '-'], ['Jets', '.133', '11.5'], ['Cats', '.133', '0.5']]),
  ('variant scenario 2',
   ([['Suns', 11, 6], ['Cats', 22, 12], ['Bucks', 7, 0], ['Wolves', 6, 8], ['Jets', 1, 33]],),
   [['Bucks', '1.000', '-'],
    ['Cats', '.647', '-1.5'],
    ['Suns', '.647', '1.0'],
    ['Wolves', '.429', '4.5'],
    ['Jets', '.029', '19.5']])]]
for label, args, expected in cases[N - 1]:
    check(label, run(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(teams):
    def pct(w, l):
        return Fraction(w, w + l) if w + l else Fraction(0)
    rows = sorted(teams, key=lambda r: (-pct(r[1], r[2]), r[2], r[0]))
    lw, ll = rows[0][1], rows[0][2]
    out = []
    for name, w, l in rows:
        p = '%.3f' % float(pct(w, l))
        if p.startswith('0'):
            p = p[1:]
        gb2 = (lw - w) + (l - ll)
        gb = '-' if gb2 == 0 else '%.1f' % (gb2 / 2)
        out.append([name, p, gb])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: equal percentage order',
   ([['Cats', 3, 8], ['Wolves', 6, 16], ['Jets', 3, 11], ['Suns', 0, 4]],),
   [['Wolves', '.273', '-'],
    ['Cats', '.273', '-2.5'],
    ['Jets', '.214', '-1.0'],
    ['Suns', '.000', '-3.0']]),
  ('variant scenario 1',
   ([['Suns', 9, 0], ['Cats', 19, 11], ['Bucks', 6, 7]],),
   [['Suns', '1.000', '-'], ['Cats', '.633', '0.5'], ['Bucks', '.462', '5.0']]),
  ('variant scenario 2',
   ([['Cats', 8, 15], ['Jets', 18, 12], ['Wolves', 6, 3]],),
   [['Wolves', '.667', '-'], ['Jets', '.600', '-1.5'], ['Cats', '.348', '5.0']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: equal percentage order',
   ([['Cats', 1, 0], ['Jets', 15, 5], ['Wolves', 0, 0], ['Suns', 15, 0]],),
   [['Suns', '1.000', '-'],
    ['Cats', '1.000', '7.0'],
    ['Jets', '.750', '2.5'],
    ['Wolves', '.000', '7.5']]),
  ('variant scenario 1',
   ([['Suns', 8, 18], ['Cats', 30, 2], ['Jets', 0, 33], ['Bucks', 2, 3], ['Wolves', 1, 9]],),
   [['Cats', '.938', '-'],
    ['Bucks', '.400', '14.5'],
    ['Suns', '.308', '19.0'],
    ['Wolves', '.100', '18.0'],
    ['Jets', '.000', '30.5']]),
  ('variant scenario 2',
   ([['Bucks', 10, 19], ['Suns', 27, 4], ['Jets', 31, 0]],),
   [['Jets', '1.000', '-'], ['Suns', '.871', '4.0'], ['Bucks', '.345', '20.0']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: equal percentage order',
   ([['Bucks', 14, 20], ['Jets', 28, 40], ['Wolves', 14, 19], ['Suns', 0, 10]],),
   [['Wolves', '.424', '-'],
    ['Jets', '.412', '3.5'],
    ['Bucks', '.412', '0.5'],
    ['Suns', '.000', '2.5']]),
  ('variant scenario 1',
   ([['Cats', 2, 15], ['Suns', 1, 7]],),
   [['Suns', '.125', '-'], ['Cats', '.118', '3.5']]),
  ('variant scenario 2',
   ([['Bucks', 2, 17], ['Suns', 9, 11]],),
   [['Suns', '.450', '-'], ['Bucks', '.105', '6.5']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: equal percentage order',
   ([['Wolves', 4, 18], ['Suns', 8, 36], ['Cats', 4, 35], ['Jets', 10, 27]],),
   [['Jets', '.270', '-'],
    ['Suns', '.182', '5.5'],
    ['Wolves', '.182', '-1.5'],
    ['Cats', '.103', '7.0']]),
  ('regression: equal percentage order',
   ([['Jets', 7, 16], ['Wolves', 14, 32], ['Suns', 3, 15]],),
   [['Wolves', '.304', '-'], ['Jets', '.304', '-4.5'], ['Suns', '.167', '-3.0']]),
  ('variant scenario 1',
   ([['Bucks', 5, 10], ['Cats', 16, 0]],),
   [['Cats', '1.000', '-'], ['Bucks', '.333', '10.5']]),
  ('variant scenario 2',
   ([['Jets', 11, 19], ['Bucks', 22, 38]],),
   [['Bucks', '.367', '-'], ['Jets', '.367', '-4.0']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: equal percentage order',
   ([['Bucks', 1, 3], ['Suns', 2, 6], ['Cats', 15, 15]],),
   [['Cats', '.500', '-'], ['Suns', '.250', '2.0'], ['Bucks', '.250', '1.0']]),
  ('variant scenario 1',
   ([['Cats', 4, 26], ['Jets', 8, 52], ['Suns', 6, 27]],),
   [['Suns', '.182', '-'], ['Jets', '.133', '11.5'], ['Cats', '.133', '0.5']]),
  ('variant scenario 2',
   ([['Suns', 11, 6], ['Cats', 22, 12], ['Bucks', 7, 0], ['Wolves', 6, 8], ['Jets', 1, 33]],),
   [['Bucks', '1.000', '-'],
    ['Cats', '.647', '-1.5'],
    ['Suns', '.647', '1.0'],
    ['Wolves', '.429', '4.5'],
    ['Jets', '.029', '19.5']])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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 4-4 team is listed below a 2-2 team.

Division standings. teams rows are [name, wins, losses]. Win percentage is wins / games (0 for no games) shown with three decimals and the leading zero dropped (".500", but "1.000"). Sort by win percentage, then more wins, then name. The leader is the first sorted row; games behind = ((leader_wins - wins) + (losses - leader_losses)) / 2, shown as "-" when zero and otherwise with one decimal (negative values allowed). Return [name, pct, gb] rows.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(teams):
    def pct(w, l):
        return Fraction(w, w + l)
    rows = sorted(teams, key=lambda r: (-pct(r[1], r[2]), -r[1], r[0]))
    lw, ll = rows[0][1], rows[0][2]
    out = []
    for name, w, l in rows:
        p = '%.3f' % float(pct(w, l))
        if p.startswith('0'):
            p = p[1:]
        gb2 = (lw - w) + (l - ll)
        gb = '-' if gb2 == 0 else '%.1f' % (gb2 / 2)
        out.append([name, p, gb])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: zero games percentage',
   ([['Jets', 4, 0], ['Bucks', 3, 28], ['Suns', 0, 0], ['Wolves', 0, 5]],),
   [['Jets', '1.000', '-'],
    ['Bucks', '.097', '14.5'],
    ['Suns', '.000', '2.0'],
    ['Wolves', '.000', '4.5']]),
  ('variant scenario 1',
   ([['Suns', 1, 0], ['Wolves', 2, 0], ['Jets', 1, 6]],),
   [['Wolves', '1.000', '-'], ['Suns', '1.000', '0.5'], ['Jets', '.143', '3.5']]),
  ('variant scenario 2',
   ([['Suns', 15, 0], ['Jets', 30, 0], ['Wolves', 10, 0]],),
   [['Jets', '1.000', '-'], ['Suns', '1.000', '7.5'], ['Wolves', '1.000', '10.0']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: zero games percentage',
   ([['Suns', 8, 2], ['Jets', 0, 0], ['Bucks', 10, 19]],),
   [['Suns', '.800', '-'], ['Bucks', '.345', '7.5'], ['Jets', '.000', '3.0']]),
  ('variant scenario 1',
   ([['Cats', 14, 16], ['Wolves', 8, 9], ['Jets', 2, 8]],),
   [['Wolves', '.471', '-'], ['Cats', '.467', '0.5'], ['Jets', '.200', '2.5']]),
  ('variant scenario 2',
   ([['Wolves', 19, 7], ['Bucks', 38, 14], ['Suns', 0, 8], ['Jets', 6, 1], ['Cats', 1, 6]],),
   [['Jets', '.857', '-'],
    ['Bucks', '.731', '-9.5'],
    ['Wolves', '.731', '-3.5'],
    ['Cats', '.143', '5.0'],
    ['Suns', '.000', '6.5']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: zero games percentage',
   ([['Wolves', 2, 18], ['Suns', 0, 0], ['Jets', 9, 7]],),
   [['Jets', '.562', '-'], ['Wolves', '.100', '9.0'], ['Suns', '.000', '1.0']]),
  ('variant scenario 1',
   ([['Cats', 9, 7], ['Suns', 19, 0], ['Jets', 20, 6], ['Bucks', 2, 4]],),
   [['Suns', '1.000', '-'],
    ['Jets', '.769', '2.5'],
    ['Cats', '.562', '8.5'],
    ['Bucks', '.333', '10.5']]),
  ('variant scenario 2',
   ([['Jets', 12, 11], ['Suns', 4, 0], ['Bucks', 0, 2], ['Wolves', 16, 8]],),
   [['Suns', '1.000', '-'],
    ['Wolves', '.667', '-2.0'],
    ['Jets', '.522', '1.5'],
    ['Bucks', '.000', '3.0']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: zero games percentage',
   ([['Cats', 6, 6], ['Suns', 2, 0], ['Wolves', 0, 0], ['Jets', 13, 17]],),
   [['Suns', '1.000', '-'],
    ['Cats', '.500', '1.0'],
    ['Jets', '.433', '3.0'],
    ['Wolves', '.000', '1.0']]),
  ('variant scenario 1',
   ([['Wolves', 23, 12], ['Jets', 9, 16]],),
   [['Wolves', '.657', '-'], ['Jets', '.360', '9.0']]),
  ('variant scenario 2',
   ([['Jets', 7, 13], ['Wolves', 13, 24], ['Bucks', 2, 18], ['Suns', 2, 6]],),
   [['Wolves', '.351', '-'],
    ['Jets', '.350', '-2.5'],
    ['Suns', '.250', '-3.5'],
    ['Bucks', '.100', '2.5']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: zero games percentage',
   ([['Suns', 0, 0], ['Jets', 9, 10], ['Wolves', 30, 1], ['Bucks', 15, 13]],),
   [['Wolves', '.968', '-'],
    ['Bucks', '.536', '13.5'],
    ['Jets', '.474', '15.0'],
    ['Suns', '.000', '14.5']]),
  ('variant scenario 1',
   ([['Bucks', 6, 2], ['Wolves', 19, 7], ['Jets', 23, 16], ['Suns', 1, 37], ['Cats', 0, 8]],),
   [['Bucks', '.750', '-'],
    ['Wolves', '.731', '-4.0'],
    ['Jets', '.590', '-1.5'],
    ['Suns', '.026', '20.0'],
    ['Cats', '.000', '6.0']]),
  ('variant scenario 2',
   ([['Wolves', 4, 0], ['Bucks', 2, 35]],),
   [['Wolves', '1.000', '-'], ['Bucks', '.054', '18.5']])]]
for label, args, expected in cases[N - 1]:
    check(label, run(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(teams):
    def pct(w, l):
        return Fraction(w, w + l) if w + l else Fraction(1, 2)
    rows = sorted(teams, key=lambda r: (-pct(r[1], r[2]), -r[1], r[0]))
    lw, ll = rows[0][1], rows[0][2]
    out = []
    for name, w, l in rows:
        p = '%.3f' % float(pct(w, l))
        if p.startswith('0'):
            p = p[1:]
        gb2 = (lw - w) + (l - ll)
        gb = '-' if gb2 == 0 else '%.1f' % (gb2 / 2)
        out.append([name, p, gb])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: zero games percentage',
   ([['Jets', 4, 0], ['Bucks', 3, 28], ['Suns', 0, 0], ['Wolves', 0, 5]],),
   [['Jets', '1.000', '-'],
    ['Bucks', '.097', '14.5'],
    ['Suns', '.000', '2.0'],
    ['Wolves', '.000', '4.5']]),
  ('variant scenario 1',
   ([['Suns', 1, 0], ['Wolves', 2, 0], ['Jets', 1, 6]],),
   [['Wolves', '1.000', '-'], ['Suns', '1.000', '0.5'], ['Jets', '.143', '3.5']]),
  ('variant scenario 2',
   ([['Suns', 15, 0], ['Jets', 30, 0], ['Wolves', 10, 0]],),
   [['Jets', '1.000', '-'], ['Suns', '1.000', '7.5'], ['Wolves', '1.000', '10.0']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: zero games percentage',
   ([['Suns', 8, 2], ['Jets', 0, 0], ['Bucks', 10, 19]],),
   [['Suns', '.800', '-'], ['Bucks', '.345', '7.5'], ['Jets', '.000', '3.0']]),
  ('variant scenario 1',
   ([['Cats', 14, 16], ['Wolves', 8, 9], ['Jets', 2, 8]],),
   [['Wolves', '.471', '-'], ['Cats', '.467', '0.5'], ['Jets', '.200', '2.5']]),
  ('variant scenario 2',
   ([['Wolves', 19, 7], ['Bucks', 38, 14], ['Suns', 0, 8], ['Jets', 6, 1], ['Cats', 1, 6]],),
   [['Jets', '.857', '-'],
    ['Bucks', '.731', '-9.5'],
    ['Wolves', '.731', '-3.5'],
    ['Cats', '.143', '5.0'],
    ['Suns', '.000', '6.5']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: zero games percentage',
   ([['Wolves', 2, 18], ['Suns', 0, 0], ['Jets', 9, 7]],),
   [['Jets', '.562', '-'], ['Wolves', '.100', '9.0'], ['Suns', '.000', '1.0']]),
  ('variant scenario 1',
   ([['Cats', 9, 7], ['Suns', 19, 0], ['Jets', 20, 6], ['Bucks', 2, 4]],),
   [['Suns', '1.000', '-'],
    ['Jets', '.769', '2.5'],
    ['Cats', '.562', '8.5'],
    ['Bucks', '.333', '10.5']]),
  ('variant scenario 2',
   ([['Jets', 12, 11], ['Suns', 4, 0], ['Bucks', 0, 2], ['Wolves', 16, 8]],),
   [['Suns', '1.000', '-'],
    ['Wolves', '.667', '-2.0'],
    ['Jets', '.522', '1.5'],
    ['Bucks', '.000', '3.0']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: zero games percentage',
   ([['Cats', 6, 6], ['Suns', 2, 0], ['Wolves', 0, 0], ['Jets', 13, 17]],),
   [['Suns', '1.000', '-'],
    ['Cats', '.500', '1.0'],
    ['Jets', '.433', '3.0'],
    ['Wolves', '.000', '1.0']]),
  ('variant scenario 1',
   ([['Wolves', 23, 12], ['Jets', 9, 16]],),
   [['Wolves', '.657', '-'], ['Jets', '.360', '9.0']]),
  ('variant scenario 2',
   ([['Jets', 7, 13], ['Wolves', 13, 24], ['Bucks', 2, 18], ['Suns', 2, 6]],),
   [['Wolves', '.351', '-'],
    ['Jets', '.350', '-2.5'],
    ['Suns', '.250', '-3.5'],
    ['Bucks', '.100', '2.5']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: zero games percentage',
   ([['Suns', 0, 0], ['Jets', 9, 10], ['Wolves', 30, 1], ['Bucks', 15, 13]],),
   [['Wolves', '.968', '-'],
    ['Bucks', '.536', '13.5'],
    ['Jets', '.474', '15.0'],
    ['Suns', '.000', '14.5']]),
  ('variant scenario 1',
   ([['Bucks', 6, 2], ['Wolves', 19, 7], ['Jets', 23, 16], ['Suns', 1, 37], ['Cats', 0, 8]],),
   [['Bucks', '.750', '-'],
    ['Wolves', '.731', '-4.0'],
    ['Jets', '.590', '-1.5'],
    ['Suns', '.026', '20.0'],
    ['Cats', '.000', '6.0']]),
  ('variant scenario 2',
   ([['Wolves', 4, 0], ['Bucks', 2, 35]],),
   [['Wolves', '1.000', '-'], ['Bucks', '.054', '18.5']])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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 team yet to play raises a division error or is shown as a .500 team.

Division standings. teams rows are [name, wins, losses]. Win percentage is wins / games (0 for no games) shown with three decimals and the leading zero dropped (".500", but "1.000"). Sort by win percentage, then more wins, then name. The leader is the first sorted row; games behind = ((leader_wins - wins) + (losses - leader_losses)) / 2, shown as "-" when zero and otherwise with one decimal (negative values allowed). Return [name, pct, gb] rows.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(teams):
    def pct(w, l):
        return Fraction(w, w + l) if w + l else Fraction(0)
    rows = sorted(teams, key=lambda r: (-pct(r[1], r[2]), -r[1], r[0]))
    lw, ll = rows[0][1], rows[0][2]
    out = []
    for name, w, l in rows:
        p = '%.3f' % float(pct(w, l))
        if p.startswith('0'):
            p = p[1:]
        gb2 = (lw - w) + (l - ll)
        gb = '-' if name == rows[0][0] else '%.1f' % (gb2 / 2)
        out.append([name, p, gb])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: zero gap dash',
   ([['Jets', 5, 7], ['Cats', 21, 6], ['Bucks', 8, 0]],),
   [['Bucks', '1.000', '-'], ['Cats', '.778', '-3.5'], ['Jets', '.417', '5.0']]),
  ('regression: zero gap dash',
   ([['Cats', 0, 0], ['Wolves', 0, 0]],),
   [['Cats', '.000', '-'], ['Wolves', '.000', '-']]),
  ('variant scenario 1',
   ([['Jets', 9, 15], ['Suns', 4, 1], ['Cats', 2, 8]],),
   [['Suns', '.800', '-'], ['Jets', '.375', '4.5'], ['Cats', '.200', '4.5']]),
  ('variant scenario 2',
   ([['Jets', 4, 24], ['Suns', 4, 6], ['Wolves', 3, 7], ['Bucks', 1, 4], ['Cats', 25, 2]],),
   [['Cats', '.926', '-'],
    ['Suns', '.400', '12.5'],
    ['Wolves', '.300', '13.5'],
    ['Bucks', '.200', '13.0'],
    ['Jets', '.143', '21.5']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: zero gap dash',
   ([['Cats', 7, 23], ['Bucks', 14, 46], ['Jets', 0, 0]],),
   [['Bucks', '.233', '-'], ['Cats', '.233', '-8.0'], ['Jets', '.000', '-16.0']]),
  ('regression: zero gap dash',
   ([['Suns', 2, 2], ['Jets', 4, 4], ['Wolves', 10, 20]],),
   [['Jets', '.500', '-'], ['Suns', '.500', '-'], ['Wolves', '.333', '5.0']]),
  ('variant scenario 1',
   ([['Suns', 14, 2], ['Jets', 1, 23]],),
   [['Suns', '.875', '-'], ['Jets', '.042', '17.0']]),
  ('variant scenario 2',
   ([['Cats', 30, 2], ['Jets', 3, 2], ['Bucks', 4, 15], ['Suns', 2, 0], ['Wolves', 17, 5]],),
   [['Suns', '1.000', '-'],
    ['Cats', '.938', '-13.0'],
    ['Wolves', '.773', '-5.0'],
    ['Jets', '.600', '0.5'],
    ['Bucks', '.211', '6.5']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: zero gap dash',
   ([['Cats', 1, 10], ['Suns', 4, 2], ['Bucks', 3, 1], ['Wolves', 7, 6]],),
   [['Bucks', '.750', '-'],
    ['Suns', '.667', '-'],
    ['Wolves', '.538', '0.5'],
    ['Cats', '.091', '5.5']]),
  ('regression: zero gap dash',
   ([['Wolves', 0, 0], ['Suns', 3, 17]],),
   [['Suns', '.150', '-'], ['Wolves', '.000', '-7.0']]),
  ('variant scenario 1',
   ([['Cats', 2, 8], ['Suns', 15, 9]],),
   [['Suns', '.625', '-'], ['Cats', '.200', '6.0']]),
  ('variant scenario 2',
   ([['Wolves', 21, 17], ['Bucks', 7, 29], ['Jets', 8, 13]],),
   [['Wolves', '.553', '-'], ['Jets', '.381', '4.5'], ['Bucks', '.194', '13.0']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: zero gap dash',
   ([['Cats', 1, 0], ['Suns', 30, 10]],),
   [['Cats', '1.000', '-'], ['Suns', '.750', '-9.5']]),
  ('regression: zero gap dash',
   ([['Suns', 3, 3], ['Wolves', 6, 6]],),
   [['Wolves', '.500', '-'], ['Suns', '.500', '-']]),
  ('variant scenario 1',
   ([['Bucks', 4, 18], ['Cats', 8, 36], ['Jets', 11, 7]],),
   [['Jets', '.611', '-'], ['Cats', '.182', '16.0'], ['Bucks', '.182', '9.0']]),
  ('variant scenario 2',
   ([['Wolves', 5, 15], ['Cats', 4, 14], ['Jets', 9, 16], ['Suns', 8, 14]],),
   [['Suns', '.364', '-'],
    ['Jets', '.360', '0.5'],
    ['Wolves', '.250', '2.0'],
    ['Cats', '.222', '2.0']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: zero gap dash',
   ([['Wolves', 4, 26], ['Suns', 14, 6], ['Bucks', 10, 3]],),
   [['Bucks', '.769', '-'], ['Suns', '.700', '-0.5'], ['Wolves', '.133', '14.5']]),
  ('regression: zero gap dash',
   ([['Suns', 0, 0], ['Wolves', 0, 0], ['Cats', 1, 4], ['Bucks', 1, 1]],),
   [['Bucks', '.500', '-'],
    ['Cats', '.200', '1.5'],
    ['Suns', '.000', '-'],
    ['Wolves', '.000', '-']]),
  ('variant scenario 1',
   ([['Bucks', 20, 2], ['Suns', 2, 17], ['Cats', 6, 21]],),
   [['Bucks', '.909', '-'], ['Cats', '.222', '16.5'], ['Suns', '.105', '16.5']]),
  ('variant scenario 2',
   ([['Bucks', 0, 2], ['Wolves', 7, 12], ['Jets', 26, 9]],),
   [['Jets', '.743', '-'], ['Wolves', '.368', '11.0'], ['Bucks', '.000', '9.5']])]]
for label, args, expected in cases[N - 1]:
    check(label, run(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(teams):
    def pct(w, l):
        return Fraction(w, w + l) if w + l else Fraction(0)
    rows = sorted(teams, key=lambda r: (-pct(r[1], r[2]), -r[1], r[0]))
    lw, ll = rows[0][1], rows[0][2]
    out = []
    for name, w, l in rows:
        p = '%.3f' % float(pct(w, l))
        if p.startswith('0'):
            p = p[1:]
        gb2 = (lw - w) + (l - ll)
        gb = '-' if gb2 <= 0 else '%.1f' % (gb2 / 2)
        out.append([name, p, gb])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: zero gap dash',
   ([['Jets', 5, 7], ['Cats', 21, 6], ['Bucks', 8, 0]],),
   [['Bucks', '1.000', '-'], ['Cats', '.778', '-3.5'], ['Jets', '.417', '5.0']]),
  ('regression: zero gap dash',
   ([['Cats', 0, 0], ['Wolves', 0, 0]],),
   [['Cats', '.000', '-'], ['Wolves', '.000', '-']]),
  ('variant scenario 1',
   ([['Jets', 9, 15], ['Suns', 4, 1], ['Cats', 2, 8]],),
   [['Suns', '.800', '-'], ['Jets', '.375', '4.5'], ['Cats', '.200', '4.5']]),
  ('variant scenario 2',
   ([['Jets', 4, 24], ['Suns', 4, 6], ['Wolves', 3, 7], ['Bucks', 1, 4], ['Cats', 25, 2]],),
   [['Cats', '.926', '-'],
    ['Suns', '.400', '12.5'],
    ['Wolves', '.300', '13.5'],
    ['Bucks', '.200', '13.0'],
    ['Jets', '.143', '21.5']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: zero gap dash',
   ([['Cats', 7, 23], ['Bucks', 14, 46], ['Jets', 0, 0]],),
   [['Bucks', '.233', '-'], ['Cats', '.233', '-8.0'], ['Jets', '.000', '-16.0']]),
  ('regression: zero gap dash',
   ([['Suns', 2, 2], ['Jets', 4, 4], ['Wolves', 10, 20]],),
   [['Jets', '.500', '-'], ['Suns', '.500', '-'], ['Wolves', '.333', '5.0']]),
  ('variant scenario 1',
   ([['Suns', 14, 2], ['Jets', 1, 23]],),
   [['Suns', '.875', '-'], ['Jets', '.042', '17.0']]),
  ('variant scenario 2',
   ([['Cats', 30, 2], ['Jets', 3, 2], ['Bucks', 4, 15], ['Suns', 2, 0], ['Wolves', 17, 5]],),
   [['Suns', '1.000', '-'],
    ['Cats', '.938', '-13.0'],
    ['Wolves', '.773', '-5.0'],
    ['Jets', '.600', '0.5'],
    ['Bucks', '.211', '6.5']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: zero gap dash',
   ([['Cats', 1, 10], ['Suns', 4, 2], ['Bucks', 3, 1], ['Wolves', 7, 6]],),
   [['Bucks', '.750', '-'],
    ['Suns', '.667', '-'],
    ['Wolves', '.538', '0.5'],
    ['Cats', '.091', '5.5']]),
  ('regression: zero gap dash',
   ([['Wolves', 0, 0], ['Suns', 3, 17]],),
   [['Suns', '.150', '-'], ['Wolves', '.000', '-7.0']]),
  ('variant scenario 1',
   ([['Cats', 2, 8], ['Suns', 15, 9]],),
   [['Suns', '.625', '-'], ['Cats', '.200', '6.0']]),
  ('variant scenario 2',
   ([['Wolves', 21, 17], ['Bucks', 7, 29], ['Jets', 8, 13]],),
   [['Wolves', '.553', '-'], ['Jets', '.381', '4.5'], ['Bucks', '.194', '13.0']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: zero gap dash',
   ([['Cats', 1, 0], ['Suns', 30, 10]],),
   [['Cats', '1.000', '-'], ['Suns', '.750', '-9.5']]),
  ('regression: zero gap dash',
   ([['Suns', 3, 3], ['Wolves', 6, 6]],),
   [['Wolves', '.500', '-'], ['Suns', '.500', '-']]),
  ('variant scenario 1',
   ([['Bucks', 4, 18], ['Cats', 8, 36], ['Jets', 11, 7]],),
   [['Jets', '.611', '-'], ['Cats', '.182', '16.0'], ['Bucks', '.182', '9.0']]),
  ('variant scenario 2',
   ([['Wolves', 5, 15], ['Cats', 4, 14], ['Jets', 9, 16], ['Suns', 8, 14]],),
   [['Suns', '.364', '-'],
    ['Jets', '.360', '0.5'],
    ['Wolves', '.250', '2.0'],
    ['Cats', '.222', '2.0']])],
 [('control two teams',
   ([['Cats', 10, 5], ['Jets', 8, 7]],),
   [['Cats', '.667', '-'], ['Jets', '.533', '2.0']]),
  ('boundary half game',
   ([['Cats', 10, 5], ['Jets', 9, 5]],),
   [['Cats', '.667', '-'], ['Jets', '.643', '0.5']]),
  ('boundary perfect record',
   ([['Suns', 3, 0], ['Jets', 1, 1]],),
   [['Suns', '1.000', '-'], ['Jets', '.500', '1.5']]),
  ('boundary no games played',
   ([['Suns', 0, 0], ['Bucks', 0, 2]],),
   [['Bucks', '.000', '-'], ['Suns', '.000', '-1.0']]),
  ('control equal pct more wins first',
   ([['Cats', 2, 2], ['Bucks', 4, 4]],),
   [['Bucks', '.500', '-'], ['Cats', '.500', '-']]),
  ('regression: zero gap dash',
   ([['Wolves', 4, 26], ['Suns', 14, 6], ['Bucks', 10, 3]],),
   [['Bucks', '.769', '-'], ['Suns', '.700', '-0.5'], ['Wolves', '.133', '14.5']]),
  ('regression: zero gap dash',
   ([['Suns', 0, 0], ['Wolves', 0, 0], ['Cats', 1, 4], ['Bucks', 1, 1]],),
   [['Bucks', '.500', '-'],
    ['Cats', '.200', '1.5'],
    ['Suns', '.000', '-'],
    ['Wolves', '.000', '-']]),
  ('variant scenario 1',
   ([['Bucks', 20, 2], ['Suns', 2, 17], ['Cats', 6, 21]],),
   [['Bucks', '.909', '-'], ['Cats', '.222', '16.5'], ['Suns', '.105', '16.5']]),
  ('variant scenario 2',
   ([['Bucks', 0, 2], ['Wolves', 7, 12], ['Jets', 26, 9]],),
   [['Jets', '.743', '-'], ['Wolves', '.368', '11.0'], ['Bucks', '.000', '9.5']])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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 team with zero games behind shows "0.0" or a trailing team ahead on games shows "-".

Division standings. teams rows are [name, wins, losses]. Win percentage is wins / games (0 for no games) shown with three decimals and the leading zero dropped (".500", but "1.000"). Sort by win percentage, then more wins, then name. The leader is the first sorted row; games behind = ((leader_wins - wins) + (losses - leader_losses)) / 2, shown as "-" when zero and otherwise with one decimal (negative values allowed). Return [name, pct, gb] rows.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(outings, innings_per_game):
    outs = er = 0
    for ip, runs in outings:
        whole, _, part = ip.partition('.')
        part = int(part or 0)
        if part > 2:
            return 'invalid ip ' + ip
        outs += round(float(ip) * 3)
        er += runs
    ip_str = '%d.%d' % (outs // 3, outs % 3)
    if outs == 0:
        return [ip_str, 'INF' if er else '0.00']
    v = Fraction(innings_per_game * er * 3, outs)
    cents = math.floor(v * 100 + Fraction(1, 2))
    return [ip_str, '%d.%02d' % (cents // 100, cents % 100)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control complete game', ([['9.0', 2]], 9), ['9.0', '2.00']),
  ('boundary thirds carry', ([['5.2', 1], ['1.1', 0]], 9), ['7.0', '1.29']),
  ('boundary seven-inning game', ([['7.0', 3]], 7), ['7.0', '3.00']),
  ('boundary no outs with runs', ([['0.0', 2]], 9), ['0.0', 'INF']),
  ('boundary invalid out digit', ([['4.3', 1]], 9), 'invalid ip 4.3'),
  ('control half-up rounding', ([['8.0', 3]], 9), ['8.0', '3.38']),
  ('regression: outs notation', ([['6.2', 4]], 7), ['6.2', '4.20']),
  ('variant scenario 1', ([['5.2', 1], ['7.0', 2], ['0.3', 4]], 9), 'invalid ip 0.3'),
  ('variant scenario 2', ([['9', 1], ['6.0', 0]], 9), ['15.0', '0.60'])],
 [('control complete game', ([['9.0', 2]], 9), ['9.0', '2.00']),
  ('boundary thirds carry', ([['5.2', 1], ['1.1', 0]], 9), ['7.0', '1.29']),
  ('boundary seven-inning game', ([['7.0', 3]], 7), ['7.0', '3.00']),
  ('boundary no outs with runs', ([['0.0', 2]], 9), ['0.0', 'INF']),
  ('boundary invalid out digit', ([['4.3', 1]], 9), 'invalid ip 4.3'),
  ('control half-up rounding', ([['8.0', 3]], 9), ['8.0', '3.38']),
  ('regression: outs notation', ([['4.1', 3], ['2.0', 4], ['6.2', 2]], 9), ['13.0', '6.23']),
  ('variant scenario 1', ([['5.2', 2], ['9.1', 3], ['9', 3]], 9), ['24.0', '3.00']),
  ('variant scenario 2', ([['5.0', 1], ['2.0', 3], ['3.1', 4], ['1.0', 3]], 9), ['11.1', '8.74'])],
 [('control complete game', ([['9.0', 2]], 9), ['9.0', '2.00']),
  ('boundary thirds carry', ([['5.2', 1], ['1.1', 0]], 9), ['7.0', '1.29']),
  ('boundary seven-inning game', ([['7.0', 3]], 7), ['7.0', '3.00']),
  ('boundary no outs with runs', ([['0.0', 2]], 9), ['0.0', 'INF']),
  ('boundary invalid out digit', ([['4.3', 1]], 9), 'invalid ip 4.3'),
  ('control half-up rounding', ([['8.0', 3]], 9), ['8.0', '3.38']),
  ('regression: outs notation', ([['8.2', 3], ['4.0', 3]], 9), ['12.2', '4.26']),
  ('variant scenario 1', ([['1', 0], ['4.0', 4]], 9), ['5.0', '7.20']),
  ('variant scenario 2', ([['4.1', 0], ['5.2', 3], ['7.1', 4], ['4.0', 2]], 7), ['21.1', '2.95'])],
 [('control complete game', ([['9.0', 2]], 9), ['9.0', '2.00']),
  ('boundary thirds carry', ([['5.2', 1], ['1.1', 0]], 9), ['7.0', '1.29']),
  ('boundary seven-inning game', ([['7.0', 3]], 7), ['7.0', '3.00']),
  ('boundary no outs with runs', ([['0.0', 2]], 9), ['0.0', 'INF']),
  ('boundary invalid out digit', ([['4.3', 1]], 9), 'invalid ip 4.3'),
  ('control half-up rounding', ([['8.0', 3]], 9), ['8.0', '3.38']),
  ('regression: outs notation', ([['4.1', 1], ['4.2', 1], ['0.1', 0]], 7), ['9.1', '1.50']),
  ('variant scenario 1', ([['8.3', 1], ['4.2', 4], ['9', 2]], 9), 'invalid ip 8.3'),
  ('variant scenario 2', ([['6.3', 0]], 7), 'invalid ip 6.3')],
 [('control complete game', ([['9.0', 2]], 9), ['9.0', '2.00']),
  ('boundary thirds carry', ([['5.2', 1], ['1.1', 0]], 9), ['7.0', '1.29']),
  ('boundary seven-inning game', ([['7.0', 3]], 7), ['7.0', '3.00']),
  ('boundary no outs with runs', ([['0.0', 2]], 9), ['0.0', 'INF']),
  ('boundary invalid out digit', ([['4.3', 1]], 9), 'invalid ip 4.3'),
  ('control half-up rounding', ([['8.0', 3]], 9), ['8.0', '3.38']),
  ('regression: outs notation', ([['3.2', 0], ['6.0', 0], ['2.1', 4]], 7), ['12.0', '2.33']),
  ('variant scenario 1',
   ([['9.2', 4], ['0.2', 1], ['6.2', 1], ['3.3', 3], ['3.1', 4], ['9.1', 1]], 7),
   'invalid ip 3.3'),
  ('variant scenario 2',
   ([['6.3', 4], ['4.1', 3], ['7.0', 0], ['7.0', 2], ['2.1', 4], ['7.2', 4], ['0.0', 0]], 9),
   'invalid ip 6.3')]]
for label, args, expected in cases[N - 1]:
    check(label, run(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(outings, innings_per_game):
    outs = er = 0
    for ip, runs in outings:
        whole, _, part = ip.partition('.')
        part = int(part or 0)
        if part > 2:
            return 'invalid ip ' + ip
        outs += int(float(ip) * 3)
        er += runs
    ip_str = '%d.%d' % (outs // 3, outs % 3)
    if outs == 0:
        return [ip_str, 'INF' if er else '0.00']
    v = Fraction(innings_per_game * er * 3, outs)
    cents = math.floor(v * 100 + Fraction(1, 2))
    return [ip_str, '%d.%02d' % (cents // 100, cents % 100)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control complete game', ([['9.0', 2]], 9), ['9.0', '2.00']),
  ('boundary thirds carry', ([['5.2', 1], ['1.1', 0]], 9), ['7.0', '1.29']),
  ('boundary seven-inning game', ([['7.0', 3]], 7), ['7.0', '3.00']),
  ('boundary no outs with runs', ([['0.0', 2]], 9), ['0.0', 'INF']),
  ('boundary invalid out digit', ([['4.3', 1]], 9), 'invalid ip 4.3'),
  ('control half-up rounding', ([['8.0', 3]], 9), ['8.0', '3.38']),
  ('regression: outs notation', ([['6.2', 4]], 7), ['6.2', '4.20']),
  ('variant scenario 1', ([['5.2', 1], ['7.0', 2], ['0.3', 4]], 9), 'invalid ip 0.3'),
  ('variant scenario 2', ([['9', 1], ['6.0', 0]], 9), ['15.0', '0.60'])],
 [('control complete game', ([['9.0', 2]], 9), ['9.0', '2.00']),
  ('boundary thirds carry', ([['5.2', 1], ['1.1', 0]], 9), ['7.0', '1.29']),
  ('boundary seven-inning game', ([['7.0', 3]], 7), ['7.0', '3.00']),
  ('boundary no outs with runs', ([['0.0', 2]], 9), ['0.0', 'INF']),
  ('boundary invalid out digit', ([['4.3', 1]], 9), 'invalid ip 4.3'),
  ('control half-up rounding', ([['8.0', 3]], 9), ['8.0', '3.38']),
  ('regression: outs notation', ([['4.1', 3], ['2.0', 4], ['6.2', 2]], 9), ['13.0', '6.23']),
  ('variant scenario 1', ([['5.2', 2], ['9.1', 3], ['9', 3]], 9), ['24.0', '3.00']),
  ('variant scenario 2', ([['5.0', 1], ['2.0', 3], ['3.1', 4], ['1.0', 3]], 9), ['11.1', '8.74'])],
 [('control complete game', ([['9.0', 2]], 9), ['9.0', '2.00']),
  ('boundary thirds carry', ([['5.2', 1], ['1.1', 0]], 9), ['7.0', '1.29']),
  ('boundary seven-inning game', ([['7.0', 3]], 7), ['7.0', '3.00']),
  ('boundary no outs with runs', ([['0.0', 2]], 9), ['0.0', 'INF']),
  ('boundary invalid out digit', ([['4.3', 1]], 9), 'invalid ip 4.3'),
  ('control half-up rounding', ([['8.0', 3]], 9), ['8.0', '3.38']),
  ('regression: outs notation', ([['8.2', 3], ['4.0', 3]], 9), ['12.2', '4.26']),
  ('variant scenario 1', ([['1', 0], ['4.0', 4]], 9), ['5.0', '7.20']),
  ('variant scenario 2', ([['4.1', 0], ['5.2', 3], ['7.1', 4], ['4.0', 2]], 7), ['21.1', '2.95'])],
 [('control complete game', ([['9.0', 2]], 9), ['9.0', '2.00']),
  ('boundary thirds carry', ([['5.2', 1], ['1.1', 0]], 9), ['7.0', '1.29']),
  ('boundary seven-inning game', ([['7.0', 3]], 7), ['7.0', '3.00']),
  ('boundary no outs with runs', ([['0.0', 2]], 9), ['0.0', 'INF']),
  ('boundary invalid out digit', ([['4.3', 1]], 9), 'invalid ip 4.3'),
  ('control half-up rounding', ([['8.0', 3]], 9), ['8.0', '3.38']),
  ('regression: outs notation', ([['4.1', 1], ['4.2', 1], ['0.1', 0]], 7), ['9.1', '1.50']),
  ('variant scenario 1', ([['8.3', 1], ['4.2', 4], ['9', 2]], 9), 'invalid ip 8.3'),
  ('variant scenario 2', ([['6.3', 0]], 7), 'invalid ip 6.3')],
 [('control complete game', ([['9.0', 2]], 9), ['9.0', '2.00']),
  ('boundary thirds carry', ([['5.2', 1], ['1.1', 0]], 9), ['7.0', '1.29']),
  ('boundary seven-inning game', ([['7.0', 3]], 7), ['7.0', '3.00']),
  ('boundary no outs with runs', ([['0.0', 2]], 9), ['0.0', 'INF']),
  ('boundary invalid out digit', ([['4.3', 1]], 9), 'invalid ip 4.3'),
  ('control half-up rounding', ([['8.0', 3]], 9), ['8.0', '3.38']),
  ('regression: outs notation', ([['3.2', 0], ['6.0', 0], ['2.1', 4]], 7), ['12.0', '2.33']),
  ('variant scenario 1',
   ([['9.2', 4], ['0.2', 1], ['6.2', 1], ['3.3', 3], ['3.1', 4], ['9.1', 1]], 7),
   'invalid ip 3.3'),
  ('variant scenario 2',
   ([['6.3', 4], ['4.1', 3], ['7.0', 0], ['7.0', 2], ['2.1', 4], ['7.2', 4], ['0.0', 0]], 9),
   'invalid ip 6.3')]]
for label, args, expected in cases[N - 1]:
    check(label, run(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:
Two outings of 5.2 and 1.1 innings total 6.3 instead of 7.0.

Pitching line aggregation. outings rows are [innings_pitched, earned_runs] where innings pitched use baseball notation "6.2" = 6 innings and 2 outs (the digit after the point is 0-2; otherwise return "invalid ip <text>"). Sum outs exactly. ERA = innings_per_game * earned runs / innings, rounded half up to two decimals. Return [total innings "I.O", ERA string]; with zero outs ERA is "INF" if any earned runs else "0.00".

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(outings, innings_per_game):
    outs = er = 0
    for ip, runs in outings:
        whole, _, part = ip.partition('.')
        part = int(part or 0)
        if part > 2:
            return 'invalid ip ' + ip
        outs += int(whole) * 3 + part
        er += runs
    ip_str = '%.1f' % (outs / 3)
    if outs == 0:
        return [ip_str, 'INF' if er else '0.00']
    v = Fraction(innings_per_game * er * 3, outs)
    cents = math.floor(v * 100 + Fraction(1, 2))
    return [ip_str, '%d.%02d' % (cents // 100, cents % 100)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control complete game', ([['9.0', 2]], 9), ['9.0', '2.00']),
  ('boundary thirds carry', ([['5.2', 1], ['1.1', 0]], 9), ['7.0', '1.29']),
  ('boundary seven-inning game', ([['7.0', 3]], 7), ['7.0', '3.00']),
  ('boundary no outs with runs', ([['0.0', 2]], 9), ['0.0', 'INF']),
  ('boundary invalid out digit', ([['4.3', 1]], 9), 'invalid ip 4.3'),
  ('control half-up rounding', ([['8.0', 3]], 9), ['8.0', '3.38']),
  ('regression: innings display', ([['0.1', 0]], 9), ['0.1', '0.00']),
  ('regression: innings display', ([['7.0', 2], ['6.2', 1], ['5', 3]], 7), ['18.2', '2.25']),
  ('variant scenario 1', ([['8.1', 3], ['0.1', 0]], 9), ['8.2', '3.12']),
  ('variant scenario 2', ([['0.3', 1], ['6.2', 3]], 9), 'invalid ip 0.3')],
 [('control complete game', ([['9.0', 2]], 9), ['9.0', '2.00']),
  ('boundary thirds carry', ([['5.2', 1], ['1.1', 0]], 9), ['7.0', '1.29']),
  ('boundary seven-inning game', ([['7.0', 3]], 7), ['7.0', '3.00']),
  ('boundary no outs with runs', ([['0.0', 2]], 9), ['0.0', 'INF']),
  ('boundary invalid out digit', ([['4.3', 1]], 9), 'invalid ip 4.3'),
  ('control half-up rounding', ([['8.0', 3]], 9), ['8.0', '3.38']),
  ('regression: innings display', ([['7.2', 3]], 9), ['7.2', '3.52']),
  ('variant scenario 1', ([['3.3', 3], ['0.2', 1], ['6.0', 4], ['8.1', 1]], 9), 'invalid ip 3.3'),
  ('variant scenario 2', ([['1.3', 4]], 9), 'invalid ip 1.3')],
 [('control complete game', ([['9.0', 2]], 9), ['9.0', '2.00']),
  ('boundary thirds carry', ([['5.2', 1], ['1.1', 0]], 9), ['7.0', '1.29']),
  ('boundary seven-inning game', ([['7.0', 3]], 7), ['7.0', '3.00']),
  ('boundary no outs with runs', ([['0.0', 2]], 9), ['0.0', 'INF']),
  ('boundary invalid out digit', ([['4.3', 1]], 9), 'invalid ip 4.3'),
  ('control half-up rounding', ([['8.0', 3]], 9), ['8.0', '3.38']),
  ('regression: innings display', ([['1.0', 1], ['8.2', 4], ['8.0', 4]], 9), ['17.2', '4.58']),
  ('variant scenario 1', ([['0.1', 2], ['4.1', 4], ['8.1', 1]], 9), ['13.0', '4.85']),
  ('variant scenario 2',
   ([['1.2', 1], ['4.3', 1], ['7.1', 1], ['4.2', 2], ['2.0', 0]], 9),
   'invalid ip 4.3')],
 [('control complete game', ([['9.0', 2]], 9), ['9.0', '2.00']),
  ('boundary thirds carry', ([['5.2', 1], ['1.1', 0]], 9), ['7.0', '1.29']),
  ('boundary seven-inning game', ([['7.0', 3]], 7), ['7.0', '3.00']),
  ('boundary no outs with runs', ([['0.0', 2]], 9), ['0.0', 'INF']),
  ('boundary invalid out digit', ([['4.3', 1]], 9), 'invalid ip 4.3'),
  ('control half-up rounding', ([['8.0', 3]], 9), ['8.0', '3.38']),
  ('regression: innings display',
   ([['3.2', 3], ['6.1', 1], ['3.2', 0], ['6.0', 4]], 7),
   ['19.2', '2.85']),
  ('variant scenario 1', ([['5.3', 0], ['8.1', 2], ['1.2', 2]], 9), 'invalid ip 5.3'),
  ('variant scenario 2', ([['3.2', 4], ['9.1', 2]], 9), ['13.0', '4.15'])],
 [('control complete game', ([['9.0', 2]], 9), ['9.0', '2.00']),
  ('boundary thirds carry', ([['5.2', 1], ['1.1', 0]], 9), ['7.0', '1.29']),
  ('boundary seven-inning game', ([['7.0', 3]], 7), ['7.0', '3.00']),
  ('boundary no outs with runs', ([['0.0', 2]], 9), ['0.0', 'INF']),
  ('boundary invalid out digit', ([['4.3', 1]], 9), 'invalid ip 4.3'),
  ('control half-up rounding', ([['8.0', 3]], 9), ['8.0', '3.38']),
  ('regression: innings display', ([['4', 4], ['3.2', 2], ['0.0', 0]], 7), ['7.2', '5.48']),
  ('variant scenario 1', ([['9', 1], ['8.3', 3], ['7.1', 4]], 7), 'invalid ip 8.3'),
  ('variant scenario 2', ([['9.1', 3], ['4.2', 1]], 9), ['14.0', '2.57'])]]
for label, args, expected in cases[N - 1]:
    check(label, run(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(outings, innings_per_game):
    outs = er = 0
    for ip, runs in outings:
        whole, _, part = ip.partition('.')
        part = int(part or 0)
        if part > 2:
            return 'invalid ip ' + ip
        outs += int(whole) * 3 + part
        er += runs
    ip_str = '%d.%d' % (round(outs / 3), outs % 3)
    if outs == 0:
        return [ip_str, 'INF' if er else '0.00']
    v = Fraction(innings_per_game * er * 3, outs)
    cents = math.floor(v * 100 + Fraction(1, 2))
    return [ip_str, '%d.%02d' % (cents // 100, cents % 100)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control complete game', ([['9.0', 2]], 9), ['9.0', '2.00']),
  ('boundary thirds carry', ([['5.2', 1], ['1.1', 0]], 9), ['7.0', '1.29']),
  ('boundary seven-inning game', ([['7.0', 3]], 7), ['7.0', '3.00']),
  ('boundary no outs with runs', ([['0.0', 2]], 9), ['0.0', 'INF']),
  ('boundary invalid out digit', ([['4.3', 1]], 9), 'invalid ip 4.3'),
  ('control half-up rounding', ([['8.0', 3]], 9), ['8.0', '3.38']),
  ('regression: innings display', ([['0.1', 0]], 9), ['0.1', '0.00']),
  ('regression: innings display', ([['7.0', 2], ['6.2', 1], ['5', 3]], 7), ['18.2', '2.25']),
  ('variant scenario 1', ([['8.1', 3], ['0.1', 0]], 9), ['8.2', '3.12']),
  ('variant scenario 2', ([['0.3', 1], ['6.2', 3]], 9), 'invalid ip 0.3')],
 [('control complete game', ([['9.0', 2]], 9), ['9.0', '2.00']),
  ('boundary thirds carry', ([['5.2', 1], ['1.1', 0]], 9), ['7.0', '1.29']),
  ('boundary seven-inning game', ([['7.0', 3]], 7), ['7.0', '3.00']),
  ('boundary no outs with runs', ([['0.0', 2]], 9), ['0.0', 'INF']),
  ('boundary invalid out digit', ([['4.3', 1]], 9), 'invalid ip 4.3'),
  ('control half-up rounding', ([['8.0', 3]], 9), ['8.0', '3.38']),
  ('regression: innings display', ([['7.2', 3]], 9), ['7.2', '3.52']),
  ('variant scenario 1', ([['3.3', 3], ['0.2', 1], ['6.0', 4], ['8.1', 1]], 9), 'invalid ip 3.3'),
  ('variant scenario 2', ([['1.3', 4]], 9), 'invalid ip 1.3')],
 [('control complete game', ([['9.0', 2]], 9), ['9.0', '2.00']),
  ('boundary thirds carry', ([['5.2', 1], ['1.1', 0]], 9), ['7.0', '1.29']),
  ('boundary seven-inning game', ([['7.0', 3]], 7), ['7.0', '3.00']),
  ('boundary no outs with runs', ([['0.0', 2]], 9), ['0.0', 'INF']),
  ('boundary invalid out digit', ([['4.3', 1]], 9), 'invalid ip 4.3'),
  ('control half-up rounding', ([['8.0', 3]], 9), ['8.0', '3.38']),
  ('regression: innings display', ([['1.0', 1], ['8.2', 4], ['8.0', 4]], 9), ['17.2', '4.58']),
  ('variant scenario 1', ([['0.1', 2], ['4.1', 4], ['8.1', 1]], 9), ['13.0', '4.85']),
  ('variant scenario 2',
   ([['1.2', 1], ['4.3', 1], ['7.1', 1], ['4.2', 2], ['2.0', 0]], 9),
   'invalid ip 4.3')],
 [('control complete game', ([['9.0', 2]], 9), ['9.0', '2.00']),
  ('boundary thirds carry', ([['5.2', 1], ['1.1', 0]], 9), ['7.0', '1.29']),
  ('boundary seven-inning game', ([['7.0', 3]], 7), ['7.0', '3.00']),
  ('boundary no outs with runs', ([['0.0', 2]], 9), ['0.0', 'INF']),
  ('boundary invalid out digit', ([['4.3', 1]], 9), 'invalid ip 4.3'),
  ('control half-up rounding', ([['8.0', 3]], 9), ['8.0', '3.38']),
  ('regression: innings display',
   ([['3.2', 3], ['6.1', 1], ['3.2', 0], ['6.0', 4]], 7),
   ['19.2', '2.85']),
  ('variant scenario 1', ([['5.3', 0], ['8.1', 2], ['1.2', 2]], 9), 'invalid ip 5.3'),
  ('variant scenario 2', ([['3.2', 4], ['9.1', 2]], 9), ['13.0', '4.15'])],
 [('control complete game', ([['9.0', 2]], 9), ['9.0', '2.00']),
  ('boundary thirds carry', ([['5.2', 1], ['1.1', 0]], 9), ['7.0', '1.29']),
  ('boundary seven-inning game', ([['7.0', 3]], 7), ['7.0', '3.00']),
  ('boundary no outs with runs', ([['0.0', 2]], 9), ['0.0', 'INF']),
  ('boundary invalid out digit', ([['4.3', 1]], 9), 'invalid ip 4.3'),
  ('control half-up rounding', ([['8.0', 3]], 9), ['8.0', '3.38']),
  ('regression: innings display', ([['4', 4], ['3.2', 2], ['0.0', 0]], 7), ['7.2', '5.48']),
  ('variant scenario 1', ([['9', 1], ['8.3', 3], ['7.1', 4]], 7), 'invalid ip 8.3'),
  ('variant scenario 2', ([['9.1', 3], ['4.2', 1]], 9), ['14.0', '2.57'])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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 total of 20 outs is shown as "6.7" instead of "6.2".

Pitching line aggregation. outings rows are [innings_pitched, earned_runs] where innings pitched use baseball notation "6.2" = 6 innings and 2 outs (the digit after the point is 0-2; otherwise return "invalid ip <text>"). Sum outs exactly. ERA = innings_per_game * earned runs / innings, rounded half up to two decimals. Return [total innings "I.O", ERA string]; with zero outs ERA is "INF" if any earned runs else "0.00".

split: open-access