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

N = 1
observations = []
def solve(x):
    text, default = x
    paras = []
    cur = ''
    i = 0
    while i < len(text):
        ch = text[i]
        if ch == '\r' and text[i + 1:i + 2] == '\n':
            cur += '\r\n'
            paras.append(cur)
            cur = ''
            i += 2
            continue
        cur += ch
        if ch in '\n\r\u2029':
            paras.append(cur)
            cur = ''
        i += 1
    if cur:
        paras.append(cur)
    out = []
    for p in paras:
        level = default
        for ch in text:
            if ch.isalpha():
                level = 1 if ch.isupper() else 0
                break
        out.append([p, level])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('regression: per-paragraph first strong', ['bX12\nYX\r\n2\u2029b\nXa', 1], [['bX12\n', 0], ['YX\r\n', 1], ['2\u2029', 1], ['b\n', 0], ['Xa', 1]]), ('regression: per-paragraph first strong', ['XX\r\nc!,,1\n.1,Y', 0], [['XX\r\n', 1], ['c!,,1\n', 0], ['.1,Y', 1]]), ('regression: per-paragraph first strong', ['\ncZ2.\na..X!\n!Z,.', 0], [['\n', 0], ['cZ2.\n', 0], ['a..X!\n', 0], ['!Z,.', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('control layout', ['cZZ2\n1\u2029!', 0], [['cZZ2\n', 0], ['1\u2029', 0], ['!', 0]]), ('control layout', ['2\n,,.1!', 0], [['2\n', 0], [',,.1!', 0]])], [('regression: per-paragraph first strong', ['1Xab,X,\r21\u2029!c', 0], [['1Xab,X,\r', 1], ['21\u2029', 0], ['!c', 0]]), ('regression: per-paragraph first strong', ['Xa!cZ!,\n22\u2029Za', 0], [['Xa!cZ!,\n', 1], ['22\u2029', 0], ['Za', 1]]), ('partial-repair probe', [' !.Yb!X,a', 0], [[' !.Yb!X,a', 1]]), ('regression: per-paragraph first strong', ['Z\u2029\r\n Z', 0], [['Z\u2029', 1], ['\r\n', 0], [' Z', 1]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('control layout', ['a1!X!', 1], [['a1!X!', 0]]), ('control layout', ['2,\r\n\n\u2029.', 1], [['2,\r\n', 1], ['\n', 1], ['\u2029', 1], ['.', 1]])], [('regression: per-paragraph first strong', ['\n\na', 1], [['\n', 1], ['\n', 1], ['a', 0]]), ('regression: per-paragraph first strong', ['b\n\n\u2029..\r\na.!bZ\nXc1', 0], [['b\n', 0], ['\n', 0], ['\u2029', 0], ['..\r\n', 0], ['a.!bZ\n', 0], ['Xc1', 1]]), ('partial-repair probe', ['1 2a,\n', 1], [['1 2a,\n', 0]]), ('regression: per-paragraph first strong', ['\r\nZ\r\nZ\n,!!.X\r\nb!YZ', 0], [['\r\n', 0], ['Z\r\n', 1], ['Z\n', 1], [',!!.X\r\n', 1], ['b!YZ', 0]]), ('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('control layout', ['\n ..Y\n.,2\nY', 1], [['\n', 1], [' ..Y\n', 1], ['.,2\n', 1], ['Y', 1]]), ('control layout', ['bY\r \r\nb', 0], [['bY\r', 0], [' \r\n', 0], ['b', 0]])], [('regression: per-paragraph first strong', ['!c\r\n2bb\n22', 1], [['!c\r\n', 0], ['2bb\n', 0], ['22', 1]]), ('regression: per-paragraph first strong', ['cX1 \nXX', 1], [['cX1 \n', 0], ['XX', 1]]), ('partial-repair probe', ['X\u20291Y..\u2029!2Z', 0], [['X\u2029', 1], ['1Y..\u2029', 1], ['!2Z', 1]]), ('regression: per-paragraph first strong', ['!c\n\n\r\naY', 1], [['!c\n', 0], ['\n', 1], ['\r\n', 1], ['aY', 0]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('control layout', ['b!X!2Y', 0], [['b!X!2Y', 0]]), ('control layout', [' Y,1Y\n\r\n', 1], [[' Y,1Y\n', 1], ['\r\n', 1]])], [('regression: per-paragraph first strong', ['!c\r\n2bb\n22', 1], [['!c\r\n', 0], ['2bb\n', 0], ['22', 1]]), ('regression: per-paragraph first strong', ['Z.,\n\n2Y\r!b,', 1], [['Z.,\n', 1], ['\n', 1], ['2Y\r', 1], ['!b,', 0]]), ('regression: per-paragraph first strong', ['\r\n.\n!!Y2c', 0], [['\r\n', 0], ['.\n', 0], ['!!Y2c', 1]]), ('regression: per-paragraph first strong', ['.bca\n \n\r\n \n\r2', 1], [['.bca\n', 0], [' \n', 1], ['\r\n', 1], [' \n', 1], ['\r', 1], ['2', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('control layout', ['bZY!\n! cc\n', 0], [['bZY!\n', 0], ['! cc\n', 0]]), ('control layout', ['\n\r,YX12Y.\r\n\n', 1], [['\n', 1], ['\r', 1], [',YX12Y.\r\n', 1], ['\n', 1]])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    text, default = x
    paras = []
    cur = ''
    i = 0
    while i < len(text):
        ch = text[i]
        if ch == '\r' and text[i + 1:i + 2] == '\n':
            cur += '\r\n'
            paras.append(cur)
            cur = ''
            i += 2
            continue
        cur += ch
        if ch in '\n\r\u2029':
            paras.append(cur)
            cur = ''
        i += 1
    if cur:
        paras.append(cur)
    out = []
    for p in paras:
        level = default
        for ch in p[:1]:
            if ch.isalpha():
                level = 1 if ch.isupper() else 0
                break
        out.append([p, level])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('regression: per-paragraph first strong', ['bX12\nYX\r\n2\u2029b\nXa', 1], [['bX12\n', 0], ['YX\r\n', 1], ['2\u2029', 1], ['b\n', 0], ['Xa', 1]]), ('regression: per-paragraph first strong', ['XX\r\nc!,,1\n.1,Y', 0], [['XX\r\n', 1], ['c!,,1\n', 0], ['.1,Y', 1]]), ('regression: per-paragraph first strong', ['\ncZ2.\na..X!\n!Z,.', 0], [['\n', 0], ['cZ2.\n', 0], ['a..X!\n', 0], ['!Z,.', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('control layout', ['cZZ2\n1\u2029!', 0], [['cZZ2\n', 0], ['1\u2029', 0], ['!', 0]]), ('control layout', ['2\n,,.1!', 0], [['2\n', 0], [',,.1!', 0]])], [('regression: per-paragraph first strong', ['1Xab,X,\r21\u2029!c', 0], [['1Xab,X,\r', 1], ['21\u2029', 0], ['!c', 0]]), ('regression: per-paragraph first strong', ['Xa!cZ!,\n22\u2029Za', 0], [['Xa!cZ!,\n', 1], ['22\u2029', 0], ['Za', 1]]), ('partial-repair probe', [' !.Yb!X,a', 0], [[' !.Yb!X,a', 1]]), ('regression: per-paragraph first strong', ['Z\u2029\r\n Z', 0], [['Z\u2029', 1], ['\r\n', 0], [' Z', 1]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('control layout', ['a1!X!', 1], [['a1!X!', 0]]), ('control layout', ['2,\r\n\n\u2029.', 1], [['2,\r\n', 1], ['\n', 1], ['\u2029', 1], ['.', 1]])], [('regression: per-paragraph first strong', ['\n\na', 1], [['\n', 1], ['\n', 1], ['a', 0]]), ('regression: per-paragraph first strong', ['b\n\n\u2029..\r\na.!bZ\nXc1', 0], [['b\n', 0], ['\n', 0], ['\u2029', 0], ['..\r\n', 0], ['a.!bZ\n', 0], ['Xc1', 1]]), ('partial-repair probe', ['1 2a,\n', 1], [['1 2a,\n', 0]]), ('regression: per-paragraph first strong', ['\r\nZ\r\nZ\n,!!.X\r\nb!YZ', 0], [['\r\n', 0], ['Z\r\n', 1], ['Z\n', 1], [',!!.X\r\n', 1], ['b!YZ', 0]]), ('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('control layout', ['\n ..Y\n.,2\nY', 1], [['\n', 1], [' ..Y\n', 1], ['.,2\n', 1], ['Y', 1]]), ('control layout', ['bY\r \r\nb', 0], [['bY\r', 0], [' \r\n', 0], ['b', 0]])], [('regression: per-paragraph first strong', ['!c\r\n2bb\n22', 1], [['!c\r\n', 0], ['2bb\n', 0], ['22', 1]]), ('regression: per-paragraph first strong', ['cX1 \nXX', 1], [['cX1 \n', 0], ['XX', 1]]), ('partial-repair probe', ['X\u20291Y..\u2029!2Z', 0], [['X\u2029', 1], ['1Y..\u2029', 1], ['!2Z', 1]]), ('regression: per-paragraph first strong', ['!c\n\n\r\naY', 1], [['!c\n', 0], ['\n', 1], ['\r\n', 1], ['aY', 0]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('control layout', ['b!X!2Y', 0], [['b!X!2Y', 0]]), ('control layout', [' Y,1Y\n\r\n', 1], [[' Y,1Y\n', 1], ['\r\n', 1]])], [('regression: per-paragraph first strong', ['!c\r\n2bb\n22', 1], [['!c\r\n', 0], ['2bb\n', 0], ['22', 1]]), ('regression: per-paragraph first strong', ['Z.,\n\n2Y\r!b,', 1], [['Z.,\n', 1], ['\n', 1], ['2Y\r', 1], ['!b,', 0]]), ('regression: per-paragraph first strong', ['\r\n.\n!!Y2c', 0], [['\r\n', 0], ['.\n', 0], ['!!Y2c', 1]]), ('regression: per-paragraph first strong', ['.bca\n \n\r\n \n\r2', 1], [['.bca\n', 0], [' \n', 1], ['\r\n', 1], [' \n', 1], ['\r', 1], ['2', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('control layout', ['bZY!\n! cc\n', 0], [['bZY!\n', 0], ['! cc\n', 0]]), ('control layout', ['\n\r,YX12Y.\r\n\n', 1], [['\n', 1], ['\r', 1], [',YX12Y.\r\n', 1], ['\n', 1]])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
All paragraphs get the direction of the first paragraph.

Input [text, default level]. Paragraph separators (\n, \r, U+2029; \r\n counts once) end a paragraph and stay with it. A trailing non-empty remainder is a paragraph. Each paragraph takes level 1 if its first letter is uppercase (stand-in for RTL), 0 if lowercase, else the default. Return [[paragraph, level]].

split: open-access


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

N = 1
observations = []
def solve(x):
    text, default = x
    paras = []
    cur = ''
    i = 0
    while i < len(text):
        ch = text[i]
        if ch == '\r' and text[i + 1:i + 2] == '\n':
            cur += '\r\n'
            paras.append(cur)
            cur = ''
            i += 2
            continue
        cur += ch
        if ch in '\n\r\u2029':
            paras.append(cur)
            cur = ''
        i += 1
    paras.append(cur)
    out = []
    for p in paras:
        level = default
        for ch in p:
            if ch.isalpha():
                level = 1 if ch.isupper() else 0
                break
        out.append([p, level])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('regression: trailing empty paragraph', ['.b\r\n1\r', 0], [['.b\r\n', 0], ['1\r', 0]]), ('partial-repair probe', ['bXY.b\n ', 1], [['bXY.b\n', 0], [' ', 1]]), ('partial-repair probe', ['\n\raa\r\ncY \r\n ', 1], [['\n', 1], ['\r', 1], ['aa\r\n', 0], ['cY \r\n', 0], [' ', 1]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('control layout', ['.a1Y\r\r\nY2a,,,\r\n2', 0], [['.a1Y\r', 0], ['\r\n', 0], ['Y2a,,,\r\n', 1], ['2', 0]]), ('control layout', ['b  \r\nc2,\u202911\na,', 1], [['b  \r\n', 0], ['c2,\u2029', 0], ['11\n', 1], ['a,', 0]])], [('regression: trailing empty paragraph', ['XY\r \r\n', 0], [['XY\r', 1], [' \r\n', 0]]), ('regression: trailing empty paragraph', ['\n\r\n \nc2\r\n', 0], [['\n', 0], ['\r\n', 0], [' \n', 0], ['c2\r\n', 0]]), ('partial-repair probe', ['\n,Y\u2029 ', 0], [['\n', 0], [',Y\u2029', 1], [' ', 0]]), ('partial-repair probe', [', \n \r\n ', 0], [[', \n', 0], [' \r\n', 0], [' ', 0]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('control layout', [',\u2029 Z', 1], [[',\u2029', 1], [' Z', 1]]), ('control layout', [' .X', 0], [[' .X', 1]])], [('regression: trailing empty paragraph', ['\nbcY\n', 1], [['\n', 1], ['bcY\n', 0]]), ('regression: trailing empty paragraph', ['2,\r\n', 0], [['2,\r\n', 0]]), ('partial-repair probe', [', \n \r\n ', 0], [[', \n', 0], [' \r\n', 0], [' ', 0]]), ('partial-repair probe', ['\n,Y\u2029 ', 0], [['\n', 0], [',Y\u2029', 1], [' ', 0]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('control layout', ['1XcXc\r11b', 0], [['1XcXc\r', 1], ['11b', 0]]), ('control layout', ['X.\r\n\r\n\rX,c Y c1', 0], [['X.\r\n', 1], ['\r\n', 0], ['\r', 0], ['X,c Y c1', 1]])], [('regression: trailing empty paragraph', [',,.,Y \u2029', 0], [[',,.,Y \u2029', 1]]), ('regression: trailing empty paragraph', ['b \r\n1\n,\ncbb\n\n!\n\n', 0], [['b \r\n', 0], ['1\n', 0], [',\n', 0], ['cbb\n', 0], ['\n', 0], ['!\n', 0], ['\n', 0]]), ('partial-repair probe', ['\n,Y\u2029 ', 0], [['\n', 0], [',Y\u2029', 1], [' ', 0]]), ('partial-repair probe', ['ZcZ\u2029. !\n ', 0], [['ZcZ\u2029', 1], ['. !\n', 0], [' ', 0]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('control layout', ['2 c.ZZ\n\u2029Y.\n\r\nb2b ', 0], [['2 c.ZZ\n', 0], ['\u2029', 0], ['Y.\n', 1], ['\r\n', 0], ['b2b ', 0]]), ('control layout', [',c2aaYZZ\u2029\r\nX.X', 0], [[',c2aaYZZ\u2029', 0], ['\r\n', 0], ['X.X', 1]])], [('regression: trailing empty paragraph', ['Z\r\r\n\rcX!X12.!.c\u2029', 0], [['Z\r', 1], ['\r\n', 0], ['\r', 0], ['cX!X12.!.c\u2029', 0]]), ('regression: trailing empty paragraph', [' Y,1Y\n\r\n', 1], [[' Y,1Y\n', 1], ['\r\n', 1]]), ('partial-repair probe', [', \n \r\n ', 0], [[', \n', 0], [' \r\n', 0], [' ', 0]]), ('partial-repair probe', ['bXY.b\n ', 1], [['bXY.b\n', 0], [' ', 1]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('control layout', ['\nYc!', 0], [['\n', 0], ['Yc!', 1]]), ('control layout', ['Z,!', 0], [['Z,!', 1]])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(x):
    text, default = x
    paras = []
    cur = ''
    i = 0
    while i < len(text):
        ch = text[i]
        if ch == '\r' and text[i + 1:i + 2] == '\n':
            cur += '\r\n'
            paras.append(cur)
            cur = ''
            i += 2
            continue
        cur += ch
        if ch in '\n\r\u2029':
            paras.append(cur)
            cur = ''
        i += 1
    if cur.strip():
        paras.append(cur)
    out = []
    for p in paras:
        level = default
        for ch in p:
            if ch.isalpha():
                level = 1 if ch.isupper() else 0
                break
        out.append([p, level])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('regression: trailing empty paragraph', ['.b\r\n1\r', 0], [['.b\r\n', 0], ['1\r', 0]]), ('partial-repair probe', ['bXY.b\n ', 1], [['bXY.b\n', 0], [' ', 1]]), ('partial-repair probe', ['\n\raa\r\ncY \r\n ', 1], [['\n', 1], ['\r', 1], ['aa\r\n', 0], ['cY \r\n', 0], [' ', 1]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('control layout', ['.a1Y\r\r\nY2a,,,\r\n2', 0], [['.a1Y\r', 0], ['\r\n', 0], ['Y2a,,,\r\n', 1], ['2', 0]]), ('control layout', ['b  \r\nc2,\u202911\na,', 1], [['b  \r\n', 0], ['c2,\u2029', 0], ['11\n', 1], ['a,', 0]])], [('regression: trailing empty paragraph', ['XY\r \r\n', 0], [['XY\r', 1], [' \r\n', 0]]), ('regression: trailing empty paragraph', ['\n\r\n \nc2\r\n', 0], [['\n', 0], ['\r\n', 0], [' \n', 0], ['c2\r\n', 0]]), ('partial-repair probe', ['\n,Y\u2029 ', 0], [['\n', 0], [',Y\u2029', 1], [' ', 0]]), ('partial-repair probe', [', \n \r\n ', 0], [[', \n', 0], [' \r\n', 0], [' ', 0]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('control layout', [',\u2029 Z', 1], [[',\u2029', 1], [' Z', 1]]), ('control layout', [' .X', 0], [[' .X', 1]])], [('regression: trailing empty paragraph', ['\nbcY\n', 1], [['\n', 1], ['bcY\n', 0]]), ('regression: trailing empty paragraph', ['2,\r\n', 0], [['2,\r\n', 0]]), ('partial-repair probe', [', \n \r\n ', 0], [[', \n', 0], [' \r\n', 0], [' ', 0]]), ('partial-repair probe', ['\n,Y\u2029 ', 0], [['\n', 0], [',Y\u2029', 1], [' ', 0]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('control layout', ['1XcXc\r11b', 0], [['1XcXc\r', 1], ['11b', 0]]), ('control layout', ['X.\r\n\r\n\rX,c Y c1', 0], [['X.\r\n', 1], ['\r\n', 0], ['\r', 0], ['X,c Y c1', 1]])], [('regression: trailing empty paragraph', [',,.,Y \u2029', 0], [[',,.,Y \u2029', 1]]), ('regression: trailing empty paragraph', ['b \r\n1\n,\ncbb\n\n!\n\n', 0], [['b \r\n', 0], ['1\n', 0], [',\n', 0], ['cbb\n', 0], ['\n', 0], ['!\n', 0], ['\n', 0]]), ('partial-repair probe', ['\n,Y\u2029 ', 0], [['\n', 0], [',Y\u2029', 1], [' ', 0]]), ('partial-repair probe', ['ZcZ\u2029. !\n ', 0], [['ZcZ\u2029', 1], ['. !\n', 0], [' ', 0]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('control layout', ['2 c.ZZ\n\u2029Y.\n\r\nb2b ', 0], [['2 c.ZZ\n', 0], ['\u2029', 0], ['Y.\n', 1], ['\r\n', 0], ['b2b ', 0]]), ('control layout', [',c2aaYZZ\u2029\r\nX.X', 0], [[',c2aaYZZ\u2029', 0], ['\r\n', 0], ['X.X', 1]])], [('regression: trailing empty paragraph', ['Z\r\r\n\rcX!X12.!.c\u2029', 0], [['Z\r', 1], ['\r\n', 0], ['\r', 0], ['cX!X12.!.c\u2029', 0]]), ('regression: trailing empty paragraph', [' Y,1Y\n\r\n', 1], [[' Y,1Y\n', 1], ['\r\n', 1]]), ('partial-repair probe', [', \n \r\n ', 0], [[', \n', 0], [' \r\n', 0], [' ', 0]]), ('partial-repair probe', ['bXY.b\n ', 1], [['bXY.b\n', 0], [' ', 1]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('control layout', ['\nYc!', 0], [['\n', 0], ['Yc!', 1]]), ('control layout', ['Z,!', 0], [['Z,!', 1]])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Text ending with a separator gains a phantom empty paragraph.

Input [text, default level]. Paragraph separators (\n, \r, U+2029; \r\n counts once) end a paragraph and stay with it. A trailing non-empty remainder is a paragraph. Each paragraph takes level 1 if its first letter is uppercase (stand-in for RTL), 0 if lowercase, else the default. Return [[paragraph, level]].

split: open-access


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

N = 1
observations = []
def solve(x):
    text, default = x
    paras = []
    cur = ''
    i = 0
    while i < len(text):
        ch = text[i]
        if ch == '\r' and text[i + 1:i + 2] == '\n':
            cur += '\r\n'
            paras.append(cur)
            cur = ''
            i += 2
            continue
        cur += ch
        if ch in '\n\r\u2029':
            paras.append(cur)
            cur = ''
        i += 1
    if cur:
        paras.append(cur)
    out = []
    level = default
    for p in paras:
        for ch in p:
            if ch.isalpha():
                level = 1 if ch.isupper() else 0
                break
        out.append([p, level])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('regression: default level per paragraph', ['22 \n\nY!!ab1\u2029Z\n\n', 0], [['22 \n', 0], ['\n', 0], ['Y!!ab1\u2029', 1], ['Z\n', 1], ['\n', 0]]), ('regression: default level per paragraph', ['2 X\u2029Yb\ra\n\n', 1], [['2 X\u2029', 1], ['Yb\r', 1], ['a\n', 0], ['\n', 1]]), ('regression: default level per paragraph', ['bXY.b\n ', 1], [['bXY.b\n', 0], [' ', 1]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('control layout', ['b\n !Z', 0], [['b\n', 0], [' !Z', 1]]), ('control layout', ['.ZY,', 1], [['.ZY,', 1]])], [('regression: default level per paragraph', ['.a,2cbY\n2', 1], [['.a,2cbY\n', 0], ['2', 1]]), ('regression: default level per paragraph', ['1 a!.\u2029\nc1X 1YZa1', 1], [['1 a!.\u2029', 0], ['\n', 1], ['c1X 1YZa1', 0]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('regression: default level per paragraph', [',a\r\n\r\nab.\r,a\rYb,', 1], [[',a\r\n', 0], ['\r\n', 1], ['ab.\r', 0], [',a\r', 0], ['Yb,', 1]]), ('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('control layout', ['.\n.bZ\n1Z ', 0], [['.\n', 0], ['.bZ\n', 0], ['1Z ', 1]]), ('control layout', ['Zb!b\n', 0], [['Zb!b\n', 1]])], [('regression: default level per paragraph', ['!!c,XaZ c2\u2029,\r', 1], [['!!c,XaZ c2\u2029', 0], [',\r', 1]]), ('regression: default level per paragraph', ['a2bY\r\n\u20291', 1], [['a2bY\r\n', 0], ['\u2029', 1], ['1', 1]]), ('partial-repair probe', ['X\n\n\nZa\r.\u2029X\nZXbZ', 1], [['X\n', 1], ['\n', 1], ['\n', 1], ['Za\r', 1], ['.\u2029', 1], ['X\n', 1], ['ZXbZ', 1]]), ('partial-repair probe', ['Z.,\n\n2Y\r!b,', 1], [['Z.,\n', 1], ['\n', 1], ['2Y\r', 1], ['!b,', 0]]), ('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('control layout', ['1acX1X!, \r\nXY', 1], [['1acX1X!, \r\n', 0], ['XY', 1]]), ('control layout', ['bb\n.Z. ', 1], [['bb\n', 0], ['.Z. ', 1]])], [('regression: default level per paragraph', ['Z\r\r\n\rcX!X12.!.c\u2029', 0], [['Z\r', 1], ['\r\n', 0], ['\r', 0], ['cX!X12.!.c\u2029', 0]]), ('regression: default level per paragraph', ['Z\u2029\r\n Z', 0], [['Z\u2029', 1], ['\r\n', 0], [' Z', 1]]), ('partial-repair probe', [' \n.X,!,2,\r\n2\n.', 1], [[' \n', 1], ['.X,!,2,\r\n', 1], ['2\n', 1], ['.', 1]]), ('regression: default level per paragraph', ['aX\n,1c\n.\ncX!a', 1], [['aX\n', 0], [',1c\n', 0], ['.\n', 1], ['cX!a', 0]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('control layout', ['Zbb\na1', 0], [['Zbb\n', 1], ['a1', 0]]), ('control layout', ['ZZ,a', 0], [['ZZ,a', 1]])], [('regression: default level per paragraph', ['Z\r\r\n\rcX!X12.!.c\u2029', 0], [['Z\r', 1], ['\r\n', 0], ['\r', 0], ['cX!X12.!.c\u2029', 0]]), ('regression: default level per paragraph', ['Z!Y\u2029X\n,\nc\n! b!', 0], [['Z!Y\u2029', 1], ['X\n', 1], [',\n', 0], ['c\n', 0], ['! b!', 0]]), ('partial-repair probe', ['\r\n.! 12\u2029\n', 1], [['\r\n', 1], ['.! 12\u2029', 1], ['\n', 1]]), ('partial-repair probe', ['!\r\n \nXX1.b', 1], [['!\r\n', 1], [' \n', 1], ['XX1.b', 1]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('control layout', ['Zbb\na1', 0], [['Zbb\n', 1], ['a1', 0]]), ('control layout', ['1c\nbb\r\nbZY\r\na\nc,XY', 0], [['1c\n', 0], ['bb\r\n', 0], ['bZY\r\n', 0], ['a\n', 0], ['c,XY', 0]])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    text, default = x
    paras = []
    cur = ''
    i = 0
    while i < len(text):
        ch = text[i]
        if ch == '\r' and text[i + 1:i + 2] == '\n':
            cur += '\r\n'
            paras.append(cur)
            cur = ''
            i += 2
            continue
        cur += ch
        if ch in '\n\r\u2029':
            paras.append(cur)
            cur = ''
        i += 1
    if cur:
        paras.append(cur)
    out = []
    for p in paras:
        level = 0
        for ch in p:
            if ch.isalpha():
                level = 1 if ch.isupper() else 0
                break
        out.append([p, level])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('regression: default level per paragraph', ['22 \n\nY!!ab1\u2029Z\n\n', 0], [['22 \n', 0], ['\n', 0], ['Y!!ab1\u2029', 1], ['Z\n', 1], ['\n', 0]]), ('regression: default level per paragraph', ['2 X\u2029Yb\ra\n\n', 1], [['2 X\u2029', 1], ['Yb\r', 1], ['a\n', 0], ['\n', 1]]), ('regression: default level per paragraph', ['bXY.b\n ', 1], [['bXY.b\n', 0], [' ', 1]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('control layout', ['b\n !Z', 0], [['b\n', 0], [' !Z', 1]]), ('control layout', ['.ZY,', 1], [['.ZY,', 1]])], [('regression: default level per paragraph', ['.a,2cbY\n2', 1], [['.a,2cbY\n', 0], ['2', 1]]), ('regression: default level per paragraph', ['1 a!.\u2029\nc1X 1YZa1', 1], [['1 a!.\u2029', 0], ['\n', 1], ['c1X 1YZa1', 0]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('regression: default level per paragraph', [',a\r\n\r\nab.\r,a\rYb,', 1], [[',a\r\n', 0], ['\r\n', 1], ['ab.\r', 0], [',a\r', 0], ['Yb,', 1]]), ('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('control layout', ['.\n.bZ\n1Z ', 0], [['.\n', 0], ['.bZ\n', 0], ['1Z ', 1]]), ('control layout', ['Zb!b\n', 0], [['Zb!b\n', 1]])], [('regression: default level per paragraph', ['!!c,XaZ c2\u2029,\r', 1], [['!!c,XaZ c2\u2029', 0], [',\r', 1]]), ('regression: default level per paragraph', ['a2bY\r\n\u20291', 1], [['a2bY\r\n', 0], ['\u2029', 1], ['1', 1]]), ('partial-repair probe', ['X\n\n\nZa\r.\u2029X\nZXbZ', 1], [['X\n', 1], ['\n', 1], ['\n', 1], ['Za\r', 1], ['.\u2029', 1], ['X\n', 1], ['ZXbZ', 1]]), ('partial-repair probe', ['Z.,\n\n2Y\r!b,', 1], [['Z.,\n', 1], ['\n', 1], ['2Y\r', 1], ['!b,', 0]]), ('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('control layout', ['1acX1X!, \r\nXY', 1], [['1acX1X!, \r\n', 0], ['XY', 1]]), ('control layout', ['bb\n.Z. ', 1], [['bb\n', 0], ['.Z. ', 1]])], [('regression: default level per paragraph', ['Z\r\r\n\rcX!X12.!.c\u2029', 0], [['Z\r', 1], ['\r\n', 0], ['\r', 0], ['cX!X12.!.c\u2029', 0]]), ('regression: default level per paragraph', ['Z\u2029\r\n Z', 0], [['Z\u2029', 1], ['\r\n', 0], [' Z', 1]]), ('partial-repair probe', [' \n.X,!,2,\r\n2\n.', 1], [[' \n', 1], ['.X,!,2,\r\n', 1], ['2\n', 1], ['.', 1]]), ('regression: default level per paragraph', ['aX\n,1c\n.\ncX!a', 1], [['aX\n', 0], [',1c\n', 0], ['.\n', 1], ['cX!a', 0]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('control layout', ['Zbb\na1', 0], [['Zbb\n', 1], ['a1', 0]]), ('control layout', ['ZZ,a', 0], [['ZZ,a', 1]])], [('regression: default level per paragraph', ['Z\r\r\n\rcX!X12.!.c\u2029', 0], [['Z\r', 1], ['\r\n', 0], ['\r', 0], ['cX!X12.!.c\u2029', 0]]), ('regression: default level per paragraph', ['Z!Y\u2029X\n,\nc\n! b!', 0], [['Z!Y\u2029', 1], ['X\n', 1], [',\n', 0], ['c\n', 0], ['! b!', 0]]), ('partial-repair probe', ['\r\n.! 12\u2029\n', 1], [['\r\n', 1], ['.! 12\u2029', 1], ['\n', 1]]), ('partial-repair probe', ['!\r\n \nXX1.b', 1], [['!\r\n', 1], [' \n', 1], ['XX1.b', 1]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('control layout', ['Zbb\na1', 0], [['Zbb\n', 1], ['a1', 0]]), ('control layout', ['1c\nbb\r\nbZY\r\na\nc,XY', 0], [['1c\n', 0], ['bb\r\n', 0], ['bZY\r\n', 0], ['a\n', 0], ['c,XY', 0]])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A paragraph with no letters inherits the previous paragraph direction.

Input [text, default level]. Paragraph separators (\n, \r, U+2029; \r\n counts once) end a paragraph and stay with it. A trailing non-empty remainder is a paragraph. Each paragraph takes level 1 if its first letter is uppercase (stand-in for RTL), 0 if lowercase, else the default. Return [[paragraph, level]].

split: open-access


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

N = 1
observations = []
def solve(x):
    text, default = x
    paras = []
    cur = ''
    i = 0
    while i < len(text):
        ch = text[i]
        if ch == '\r' and text[i + 1:i + 2] == '\n':
            cur += '\r\n'
            paras.append(cur)
            cur = ''
            i += 2
            continue
        cur += ch
        if ch in '\n\r\u2029':
            paras.append(cur)
            cur = ''
        i += 1
    if cur:
        paras.append(cur)
    out = []
    for p in paras:
        level = default
        for ch in p:
            if ch.isalnum():
                level = 1 if ch.isupper() else 0
                break
        out.append([p, level])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('regression: strong character test', [' ,.1ZaYZ,,2ca1', 1], [[' ,.1ZaYZ,,2ca1', 1]]), ('regression: strong character test', ['b  \r\nc2,\u202911\na,', 1], [['b  \r\n', 0], ['c2,\u2029', 0], ['11\n', 1], ['a,', 0]]), ('partial-repair probe', ['\ncZ2.\na..X!\n!Z,.', 0], [['\n', 0], ['cZ2.\n', 0], ['a..X!\n', 0], ['!Z,.', 1]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('control layout', ['YX\na\r\n \naZa', 0], [['YX\n', 1], ['a\r\n', 0], [' \n', 0], ['aZa', 0]]), ('control layout', ['\n\r\nb\n', 1], [['\n', 1], ['\r\n', 1], ['b\n', 0]])], [('regression: strong character test', ['\r\n1,X1 \r\n.b,', 1], [['\r\n', 1], ['1,X1 \r\n', 1], ['.b,', 0]]), ('regression: strong character test', ['2\nX\r\n\naX\r\nb\nY', 1], [['2\n', 1], ['X\r\n', 1], ['\n', 1], ['aX\r\n', 0], ['b\n', 0], ['Y', 1]]), ('partial-repair probe', ['Xac!\nZ2\u2029aYa.\r,Z!', 0], [['Xac!\n', 1], ['Z2\u2029', 1], ['aYa.\r', 0], [',Z!', 1]]), ('regression: strong character test', ['1!X\r\n', 1], [['1!X\r\n', 1]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('control layout', ['\n.! 1!b!,21Z\n1', 0], [['\n', 0], ['.! 1!b!,21Z\n', 0], ['1', 0]]), ('control layout', ['a\r\n\nY1X111,2Z', 1], [['a\r\n', 0], ['\n', 1], ['Y1X111,2Z', 1]])], [('regression: strong character test', ['2X1aXb 2!Z2,\rX', 1], [['2X1aXb 2!Z2,\r', 1], ['X', 1]]), ('regression: strong character test', ['12. \r\n', 1], [['12. \r\n', 1]]), ('partial-repair probe', ['\r,cb\r\u2029a\n.Z\r', 1], [['\r', 1], [',cb\r', 0], ['\u2029', 1], ['a\n', 0], ['.Z\r', 1]]), ('regression: strong character test', ['!c\r\n2bb\n22', 1], [['!c\r\n', 0], ['2bb\n', 0], ['22', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('control layout', ['Z.1bYYb!ZYXZ\rZ', 1], [['Z.1bYYb!ZYXZ\r', 1], ['Z', 1]]), ('control layout', ['cZ!', 0], [['cZ!', 0]])], [('regression: strong character test', ['1XZ. ', 0], [['1XZ. ', 1]]), ('regression: strong character test', ['a \n\n,\n,1\r\n\ncXccZX', 1], [['a \n', 0], ['\n', 1], [',\n', 1], [',1\r\n', 1], ['\n', 1], ['cXccZX', 0]]), ('partial-repair probe', ['\r\nc2\r.\nXY!Z\u2029Xa', 1], [['\r\n', 1], ['c2\r', 0], ['.\n', 1], ['XY!Z\u2029', 1], ['Xa', 1]]), ('regression: strong character test', ['2\r\n\r\n!,!Y\u2029', 1], [['2\r\n', 1], ['\r\n', 1], ['!,!Y\u2029', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('control layout', ['aXb\u2029 b\na1b\n', 0], [['aXb\u2029', 0], [' b\n', 0], ['a1b\n', 0]]), ('control layout', ['aXXa,\n\r\n\n\n ,', 0], [['aXXa,\n', 0], ['\r\n', 0], ['\n', 0], ['\n', 0], [' ,', 0]])], [('regression: strong character test', ['Z.,\n\n2Y\r!b,', 1], [['Z.,\n', 1], ['\n', 1], ['2Y\r', 1], ['!b,', 0]]), ('regression: strong character test', ['Y\n c\u20291 ', 1], [['Y\n', 1], [' c\u2029', 0], ['1 ', 1]]), ('regression: strong character test', ['XX\r\nc!,,1\n.1,Y', 0], [['XX\r\n', 1], ['c!,,1\n', 0], ['.1,Y', 1]]), ('regression: strong character test', ['.\r! \n22,\n.XYb', 1], [['.\r', 1], ['! \n', 1], ['22,\n', 1], ['.XYb', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('control layout', ['ZZc!,Z ', 1], [['ZZc!,Z ', 1]]), ('control layout', ['!\r,', 0], [['!\r', 0], [',', 0]])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    text, default = x
    paras = []
    cur = ''
    i = 0
    while i < len(text):
        ch = text[i]
        if ch == '\r' and text[i + 1:i + 2] == '\n':
            cur += '\r\n'
            paras.append(cur)
            cur = ''
            i += 2
            continue
        cur += ch
        if ch in '\n\r\u2029':
            paras.append(cur)
            cur = ''
        i += 1
    if cur:
        paras.append(cur)
    out = []
    for p in paras:
        level = default
        for ch in p:
            if not ch.isspace():
                level = 1 if ch.isupper() else 0
                break
        out.append([p, level])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('regression: strong character test', [' ,.1ZaYZ,,2ca1', 1], [[' ,.1ZaYZ,,2ca1', 1]]), ('regression: strong character test', ['b  \r\nc2,\u202911\na,', 1], [['b  \r\n', 0], ['c2,\u2029', 0], ['11\n', 1], ['a,', 0]]), ('partial-repair probe', ['\ncZ2.\na..X!\n!Z,.', 0], [['\n', 0], ['cZ2.\n', 0], ['a..X!\n', 0], ['!Z,.', 1]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('control layout', ['YX\na\r\n \naZa', 0], [['YX\n', 1], ['a\r\n', 0], [' \n', 0], ['aZa', 0]]), ('control layout', ['\n\r\nb\n', 1], [['\n', 1], ['\r\n', 1], ['b\n', 0]])], [('regression: strong character test', ['\r\n1,X1 \r\n.b,', 1], [['\r\n', 1], ['1,X1 \r\n', 1], ['.b,', 0]]), ('regression: strong character test', ['2\nX\r\n\naX\r\nb\nY', 1], [['2\n', 1], ['X\r\n', 1], ['\n', 1], ['aX\r\n', 0], ['b\n', 0], ['Y', 1]]), ('partial-repair probe', ['Xac!\nZ2\u2029aYa.\r,Z!', 0], [['Xac!\n', 1], ['Z2\u2029', 1], ['aYa.\r', 0], [',Z!', 1]]), ('regression: strong character test', ['1!X\r\n', 1], [['1!X\r\n', 1]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('control layout', ['\n.! 1!b!,21Z\n1', 0], [['\n', 0], ['.! 1!b!,21Z\n', 0], ['1', 0]]), ('control layout', ['a\r\n\nY1X111,2Z', 1], [['a\r\n', 0], ['\n', 1], ['Y1X111,2Z', 1]])], [('regression: strong character test', ['2X1aXb 2!Z2,\rX', 1], [['2X1aXb 2!Z2,\r', 1], ['X', 1]]), ('regression: strong character test', ['12. \r\n', 1], [['12. \r\n', 1]]), ('partial-repair probe', ['\r,cb\r\u2029a\n.Z\r', 1], [['\r', 1], [',cb\r', 0], ['\u2029', 1], ['a\n', 0], ['.Z\r', 1]]), ('regression: strong character test', ['!c\r\n2bb\n22', 1], [['!c\r\n', 0], ['2bb\n', 0], ['22', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('digits then letter', ['12 X\n', 0], [['12 X\n', 1]]), ('control layout', ['Z.1bYYb!ZYXZ\rZ', 1], [['Z.1bYYb!ZYXZ\r', 1], ['Z', 1]]), ('control layout', ['cZ!', 0], [['cZ!', 0]])], [('regression: strong character test', ['1XZ. ', 0], [['1XZ. ', 1]]), ('regression: strong character test', ['a \n\n,\n,1\r\n\ncXccZX', 1], [['a \n', 0], ['\n', 1], [',\n', 1], [',1\r\n', 1], ['\n', 1], ['cXccZX', 0]]), ('partial-repair probe', ['\r\nc2\r.\nXY!Z\u2029Xa', 1], [['\r\n', 1], ['c2\r', 0], ['.\n', 1], ['XY!Z\u2029', 1], ['Xa', 1]]), ('regression: strong character test', ['2\r\n\r\n!,!Y\u2029', 1], [['2\r\n', 1], ['\r\n', 1], ['!,!Y\u2029', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('control layout', ['aXb\u2029 b\na1b\n', 0], [['aXb\u2029', 0], [' b\n', 0], ['a1b\n', 0]]), ('control layout', ['aXXa,\n\r\n\n\n ,', 0], [['aXXa,\n', 0], ['\r\n', 0], ['\n', 0], ['\n', 0], [' ,', 0]])], [('regression: strong character test', ['Z.,\n\n2Y\r!b,', 1], [['Z.,\n', 1], ['\n', 1], ['2Y\r', 1], ['!b,', 0]]), ('regression: strong character test', ['Y\n c\u20291 ', 1], [['Y\n', 1], [' c\u2029', 0], ['1 ', 1]]), ('regression: strong character test', ['XX\r\nc!,,1\n.1,Y', 0], [['XX\r\n', 1], ['c!,,1\n', 0], ['.1,Y', 1]]), ('regression: strong character test', ['.\r! \n22,\n.XYb', 1], [['.\r', 1], ['! \n', 1], ['22,\n', 1], ['.XYb', 1]]), ('separator only paragraph', ['a\n\nZ', 1], [['a\n', 0], ['\n', 1], ['Z', 1]]), ('CRLF is one separator', ['ab\r\nXY', 0], [['ab\r\n', 0], ['XY', 1]]), ('control layout', ['ZZc!,Z ', 1], [['ZZc!,Z ', 1]]), ('control layout', ['!\r,', 0], [['!\r', 0], [',', 0]])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Paragraphs starting with digits or punctuation are forced LTR.

Input [text, default level]. Paragraph separators (\n, \r, U+2029; \r\n counts once) end a paragraph and stay with it. A trailing non-empty remainder is a paragraph. Each paragraph takes level 1 if its first letter is uppercase (stand-in for RTL), 0 if lowercase, else the default. Return [[paragraph, level]].

split: open-access


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

N = 1
observations = []
def solve(x):
    names = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    if not isinstance(x, str) or len(x) < 2 or x[0] not in names:
        return None
    i = 1
    acc = 0
    while i < len(x) and x[i] in '#bx':
        acc += {'#': 1, 'b': -1, 'x': 2}[x[i]]
        i += 1
    tail = x[i:]
    neg = tail.startswith('-')
    digits = tail[1:] if neg else tail
    if not digits.isdigit():
        return None
    octave = -int(digits) if neg else int(digits)
    midi = octave * 12 + names[x[0]] + acc
    if midi < 0 or midi > 127:
        return None
    return midi
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('C4', 60), ('C-1', 0), ('Cb-1', None), ('C0', 12), ('H4', None), ('C', None), ('c4', None), ('C-2', None)], [('A4', 69), ('G9', 127), ('C0', 12), ('D#0', 15), ('c4', None), ('C#', None), ('C4x', None), ('C--1', None)], [('C4', 60), ('A4', 69), ('C-1', 0), ('G9', 127), ('G#9', None), ('D#0', 15), ('A0', 21), ('C--1', None)], [('C-1', 0), ('G9', 127), ('G#9', None), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('A0', 21), ('C-2', None)], [('G#9', None), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('Fx4', 67), ('Ebb4', 62), ('C0', 12), ('C-2', None)]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    names = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    if not isinstance(x, str) or len(x) < 2 or x[0] not in names:
        return None
    i = 1
    acc = 0
    while i < len(x) and x[i] in '#bx':
        acc += {'#': 1, 'b': -1, 'x': 2}[x[i]]
        i += 1
    tail = x[i:]
    neg = tail.startswith('-')
    digits = tail[1:] if neg else tail
    if not digits.isdigit():
        return None
    octave = -int(digits) if neg else int(digits)
    midi = (octave * 12 + 12 if octave > 0 else 0) + names[x[0]] + acc
    if midi < 0 or midi > 127:
        return None
    return midi
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('C4', 60), ('C-1', 0), ('Cb-1', None), ('C0', 12), ('H4', None), ('C', None), ('c4', None), ('C-2', None)], [('A4', 69), ('G9', 127), ('C0', 12), ('D#0', 15), ('c4', None), ('C#', None), ('C4x', None), ('C--1', None)], [('C4', 60), ('A4', 69), ('C-1', 0), ('G9', 127), ('G#9', None), ('D#0', 15), ('A0', 21), ('C--1', None)], [('C-1', 0), ('G9', 127), ('G#9', None), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('A0', 21), ('C-2', None)], [('G#9', None), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('Fx4', 67), ('Ebb4', 62), ('C0', 12), ('C-2', None)]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Every spelled pitch lands exactly one octave low, so C4 reports 48 and A4 reports 57.

Input a spelled pitch string: uppercase letter A-G, any run of accidentals (# = +1, b = -1, x = +2), then a signed integer octave where C4 = 60 and C-1 = 0. Return the MIDI key number, or None for malformed text or results outside 0..127.

split: open-access


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

N = 1
observations = []
def solve(x):
    names = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    if not isinstance(x, str) or len(x) < 2 or x[0] not in names:
        return None
    i = 1
    acc = 0
    while i < len(x) and x[i] in '#bx':
        acc += {'#': 1, 'b': -1, 'x': 2}[x[i]]
        i += 1
    tail = x[i:]
    neg = tail.startswith('-')
    digits = tail[1:] if neg else tail
    if not digits.isdigit():
        return None
    octave = -int(digits) if neg else int(digits)
    midi = (octave + 1) * 12 + 'CDEFGAB'.index(x[0]) * 2 + acc
    if midi < 0 or midi > 127:
        return None
    return midi
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('C4', 60), ('A4', 69), ('C-1', 0), ('G#9', None), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('B4', 71)], [('G9', 127), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('Fx4', 67), ('Ebb4', 62), ('Dbbb4', 59), ('Bb3', 58)], [('B#3', 60), ('Dbbb4', 59), ('Cb-1', None), ('B-1', 11), ('E4', 64), ('C0', 12), ('D#0', 15), ('A0', 21)], [('Fx4', 67), ('F4', 65), ('B4', 71), ('C0', 12), ('D#0', 15), ('Cx-1', 2), ('H4', None), ('Bx-1', 13)], [('B-1', 11), ('B4', 71), ('Bb3', 58), ('H4', None), ('C', None), ('c4', None), ('C#', None), ('Ab-1', 8)]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    names = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    if not isinstance(x, str) or len(x) < 2 or x[0] not in names:
        return None
    i = 1
    acc = 0
    while i < len(x) and x[i] in '#bx':
        acc += {'#': 1, 'b': -1, 'x': 2}[x[i]]
        i += 1
    tail = x[i:]
    neg = tail.startswith('-')
    digits = tail[1:] if neg else tail
    if not digits.isdigit():
        return None
    octave = -int(digits) if neg else int(digits)
    midi = (octave + 1) * 12 + 'CDEFGAB'.index(x[0]) * 2 - (1 if x[0] > 'E' else 0) + acc
    if midi < 0 or midi > 127:
        return None
    return midi
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('C4', 60), ('A4', 69), ('C-1', 0), ('G#9', None), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('B4', 71)], [('G9', 127), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('Fx4', 67), ('Ebb4', 62), ('Dbbb4', 59), ('Bb3', 58)], [('B#3', 60), ('Dbbb4', 59), ('Cb-1', None), ('B-1', 11), ('E4', 64), ('C0', 12), ('D#0', 15), ('A0', 21)], [('Fx4', 67), ('F4', 65), ('B4', 71), ('C0', 12), ('D#0', 15), ('Cx-1', 2), ('H4', None), ('Bx-1', 13)], [('B-1', 11), ('B4', 71), ('Bb3', 58), ('H4', None), ('C', None), ('c4', None), ('C#', None), ('Ab-1', 8)]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
F, G, A and B read one semitone sharp (F4 reports 66) while C, D and E stay correct.

Input a spelled pitch string: uppercase letter A-G, any run of accidentals (# = +1, b = -1, x = +2), then a signed integer octave where C4 = 60 and C-1 = 0. Return the MIDI key number, or None for malformed text or results outside 0..127.

split: open-access


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

N = 1
observations = []
def solve(x):
    names = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    if not isinstance(x, str) or len(x) < 2 or x[0] not in names:
        return None
    i = 1
    acc = 0
    while i < len(x) and x[i] in '#bx':
        acc += {'#': 1, 'b': -1, 'x': 2}[x[i]]
        i += 1
    tail = x[i:]
    neg = False
    digits = tail[1:] if neg else tail
    if not digits.isdigit():
        return None
    octave = -int(digits) if neg else int(digits)
    midi = (octave + 1) * 12 + names[x[0]] + acc
    if midi < 0 or midi > 127:
        return None
    return midi
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('C4', 60), ('A4', 69), ('C-1', 0), ('G9', 127), ('G#9', None), ('Ab9', None), ('Cx-1', 2), ('Bx-1', 13)], [('G#9', None), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('Fx4', 67), ('B-1', 11), ('Bx-1', 13), ('G-1', 7)], [('Cb4', 59), ('Fx4', 67), ('Ebb4', 62), ('Dbbb4', 59), ('Cb-1', None), ('Cx-1', 2), ('G-1', 7), ('Ab-1', 8)], [('C-1', 0), ('Dbbb4', 59), ('Cb-1', None), ('E4', 64), ('F4', 65), ('B4', 71), ('Bx-1', 13), ('Ab-1', 8)], [('C-1', 0), ('B-1', 11), ('F4', 65), ('B4', 71), ('Bb3', 58), ('C0', 12), ('D#0', 15), ('G-1', 7)]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    names = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    if not isinstance(x, str) or len(x) < 2 or x[0] not in names:
        return None
    i = 1
    acc = 0
    while i < len(x) and x[i] in '#bx':
        acc += {'#': 1, 'b': -1, 'x': 2}[x[i]]
        i += 1
    tail = x[i:]
    neg = tail.startswith('-') and len(tail) > 2
    digits = tail[1:] if neg else tail
    if not digits.isdigit():
        return None
    octave = -int(digits) if neg else int(digits)
    midi = (octave + 1) * 12 + names[x[0]] + acc
    if midi < 0 or midi > 127:
        return None
    return midi
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('C4', 60), ('A4', 69), ('C-1', 0), ('G9', 127), ('G#9', None), ('Ab9', None), ('Cx-1', 2), ('Bx-1', 13)], [('G#9', None), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('Fx4', 67), ('B-1', 11), ('Bx-1', 13), ('G-1', 7)], [('Cb4', 59), ('Fx4', 67), ('Ebb4', 62), ('Dbbb4', 59), ('Cb-1', None), ('Cx-1', 2), ('G-1', 7), ('Ab-1', 8)], [('C-1', 0), ('Dbbb4', 59), ('Cb-1', None), ('E4', 64), ('F4', 65), ('B4', 71), ('Bx-1', 13), ('Ab-1', 8)], [('C-1', 0), ('B-1', 11), ('F4', 65), ('B4', 71), ('Bb3', 58), ('C0', 12), ('D#0', 15), ('G-1', 7)]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Every pitch in octave -1 (C-1 through B-1) is rejected even though keys 0..11 are valid.

Input a spelled pitch string: uppercase letter A-G, any run of accidentals (# = +1, b = -1, x = +2), then a signed integer octave where C4 = 60 and C-1 = 0. Return the MIDI key number, or None for malformed text or results outside 0..127.

split: open-access


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

N = 1
observations = []
def solve(x):
    names = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    if not isinstance(x, str) or len(x) < 2 or x[0] not in names:
        return None
    i = 1
    acc = 0
    while i < len(x) and x[i] in '#bx':
        acc += {'#': 1, 'b': -1, 'x': 2}[x[i]]
        i += 1
    tail = x[i:]
    neg = tail.startswith('-')
    digits = tail[1:] if neg else tail
    if not digits.isdigit():
        return None
    octave = -int(digits) if neg else int(digits)
    midi = (octave + 1) * 12 + names[x[0]] + acc
    if midi < 0 or midi > 128:
        return None
    return midi
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('C4', 60), ('A4', 69), ('C-1', 0), ('G9', 127), ('G#9', None), ('B#3', 60), ('Cb4', 59), ('Fx4', 67)], [('G9', 127), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('Fx4', 67), ('Ebb4', 62), ('Dbbb4', 59), ('Cb-1', None)], [('G9', 127), ('G#9', None), ('Ebb4', 62), ('Dbbb4', 59), ('Cb-1', None), ('B-1', 11), ('E4', 64), ('F4', 65)], [('G9', 127), ('Ab9', None), ('B-1', 11), ('E4', 64), ('F4', 65), ('B4', 71), ('Bb3', 58), ('C0', 12)], [('G9', 127), ('G#9', None), ('B4', 71), ('Bb3', 58), ('C0', 12), ('D#0', 15), ('Cx-1', 2), ('H4', None)]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    names = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    if not isinstance(x, str) or len(x) < 2 or x[0] not in names:
        return None
    i = 1
    acc = 0
    while i < len(x) and x[i] in '#bx':
        acc += {'#': 1, 'b': -1, 'x': 2}[x[i]]
        i += 1
    tail = x[i:]
    neg = tail.startswith('-')
    digits = tail[1:] if neg else tail
    if not digits.isdigit():
        return None
    octave = -int(digits) if neg else int(digits)
    midi = (octave + 1) * 12 + names[x[0]] + acc
    if midi < 0 or midi >= 127:
        return None
    return midi
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('C4', 60), ('A4', 69), ('C-1', 0), ('G9', 127), ('G#9', None), ('B#3', 60), ('Cb4', 59), ('Fx4', 67)], [('G9', 127), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('Fx4', 67), ('Ebb4', 62), ('Dbbb4', 59), ('Cb-1', None)], [('G9', 127), ('G#9', None), ('Ebb4', 62), ('Dbbb4', 59), ('Cb-1', None), ('B-1', 11), ('E4', 64), ('F4', 65)], [('G9', 127), ('Ab9', None), ('B-1', 11), ('E4', 64), ('F4', 65), ('B4', 71), ('Bb3', 58), ('C0', 12)], [('G9', 127), ('G#9', None), ('B4', 71), ('Bb3', 58), ('C0', 12), ('D#0', 15), ('Cx-1', 2), ('H4', None)]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
G#9 and Ab9 are returned as key 128 instead of being rejected as out of range.

Input a spelled pitch string: uppercase letter A-G, any run of accidentals (# = +1, b = -1, x = +2), then a signed integer octave where C4 = 60 and C-1 = 0. Return the MIDI key number, or None for malformed text or results outside 0..127.

split: open-access


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

N = 1
observations = []
def solve(x):
    names = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    if not isinstance(x, str) or len(x) < 2 or x[0] not in names:
        return None
    i = 1
    acc = 0
    while i < len(x) and x[i] in '#b':
        acc += {'#': 1, 'b': -1, 'x': 2}[x[i]]
        i += 1
    tail = x[i:]
    neg = tail.startswith('-')
    digits = tail[1:] if neg else tail
    if not digits.isdigit():
        return None
    octave = -int(digits) if neg else int(digits)
    midi = (octave + 1) * 12 + names[x[0]] + acc
    if midi < 0 or midi > 127:
        return None
    return midi
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('C4', 60), ('A4', 69), ('C-1', 0), ('G9', 127), ('G#9', None), ('Fx4', 67), ('Dbbb4', 59), ('Cxx4', 64)], [('G9', 127), ('G#9', None), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('Dbbb4', 59), ('Cx-1', 2), ('Bx-1', 13)], [('B#3', 60), ('Cb4', 59), ('Fx4', 67), ('Ebb4', 62), ('Dbbb4', 59), ('Cb-1', None), ('B-1', 11), ('Cxx4', 64)], [('Dbbb4', 59), ('Cb-1', None), ('B-1', 11), ('E4', 64), ('F4', 65), ('B4', 71), ('Cx-1', 2), ('Bx-1', 13)], [('Fx4', 67), ('Dbbb4', 59), ('F4', 65), ('B4', 71), ('Bb3', 58), ('C0', 12), ('D#0', 15), ('Cxx4', 64)]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    names = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    if not isinstance(x, str) or len(x) < 2 or x[0] not in names:
        return None
    i = 1
    acc = 0
    while i < len(x) and x[i] in '#bx' and i < 3:
        acc += {'#': 1, 'b': -1, 'x': 2}[x[i]]
        i += 1
    tail = x[i:]
    neg = tail.startswith('-')
    digits = tail[1:] if neg else tail
    if not digits.isdigit():
        return None
    octave = -int(digits) if neg else int(digits)
    midi = (octave + 1) * 12 + names[x[0]] + acc
    if midi < 0 or midi > 127:
        return None
    return midi
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('C4', 60), ('A4', 69), ('C-1', 0), ('G9', 127), ('G#9', None), ('Fx4', 67), ('Dbbb4', 59), ('Cxx4', 64)], [('G9', 127), ('G#9', None), ('Ab9', None), ('B#3', 60), ('Cb4', 59), ('Dbbb4', 59), ('Cx-1', 2), ('Bx-1', 13)], [('B#3', 60), ('Cb4', 59), ('Fx4', 67), ('Ebb4', 62), ('Dbbb4', 59), ('Cb-1', None), ('B-1', 11), ('Cxx4', 64)], [('Dbbb4', 59), ('Cb-1', None), ('B-1', 11), ('E4', 64), ('F4', 65), ('B4', 71), ('Cx-1', 2), ('Bx-1', 13)], [('Fx4', 67), ('Dbbb4', 59), ('F4', 65), ('B4', 71), ('Bb3', 58), ('C0', 12), ('D#0', 15), ('Cxx4', 64)]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Any spelling with an x double sharp (Fx4, Cx-1) is rejected as malformed.

Input a spelled pitch string: uppercase letter A-G, any run of accidentals (# = +1, b = -1, x = +2), then a signed integer octave where C4 = 60 and C-1 = 0. Return the MIDI key number, or None for malformed text or results outside 0..127.

split: open-access


prompt:
Middle C is labelled C5 and every other key also reports an octave one too high.

Input [midi, fifths] with midi 0..127 and fifths -7..7. Use flat names when fifths < 0, sharp names otherwise; in keys with at least six sharps pitch class 5 is E#, with seven sharps pitch class 0 is B# of the previous octave, and with at least six flats pitch class 11 is Cb of the next octave. Octave -1 starts at key 0. Invalid input returns None.

split: open-access


prompt:
In a key with no sharps or flats, key 61 is spelled Db4 instead of the stipulated C#4.

Input [midi, fifths] with midi 0..127 and fifths -7..7. Use flat names when fifths < 0, sharp names otherwise; in keys with at least six sharps pitch class 5 is E#, with seven sharps pitch class 0 is B# of the previous octave, and with at least six flats pitch class 11 is Cb of the next octave. Octave -1 starts at key 0. Invalid input returns None.

split: open-access


prompt:
C# major and Cb major (seven accidentals) are rejected although both are legal key signatures.

Input [midi, fifths] with midi 0..127 and fifths -7..7. Use flat names when fifths < 0, sharp names otherwise; in keys with at least six sharps pitch class 5 is E#, with seven sharps pitch class 0 is B# of the previous octave, and with at least six flats pitch class 11 is Cb of the next octave. Octave -1 starts at key 0. Invalid input returns None.

split: open-access


prompt:
In C# major, middle C is spelled B#4, an octave above the sounding pitch, instead of B#3.

Input [midi, fifths] with midi 0..127 and fifths -7..7. Use flat names when fifths < 0, sharp names otherwise; in keys with at least six sharps pitch class 5 is E#, with seven sharps pitch class 0 is B# of the previous octave, and with at least six flats pitch class 11 is Cb of the next octave. Octave -1 starts at key 0. Invalid input returns None.

split: open-access


prompt:
In F# major, key 65 is spelled F4 instead of the stipulated E#4.

Input [midi, fifths] with midi 0..127 and fifths -7..7. Use flat names when fifths < 0, sharp names otherwise; in keys with at least six sharps pitch class 5 is E#, with seven sharps pitch class 0 is B# of the previous octave, and with at least six flats pitch class 11 is Cb of the next octave. Octave -1 starts at key 0. Invalid input returns None.

split: open-access


prompt:
C4 to E4 is named AA2 instead of M3, because every generic number comes out one too small.

Input [lower, upper] spelled pitches (letter, # or b accidentals, nonnegative octave). The generic number counts letter steps plus 7 per spelled octave plus one; quality compares the semitone span with the major/perfect reference (compounds add 12 per octave). Perfect class for simple numbers 1, 4, 5: P, A, d, AA, dd; others: M, m, A, d, AA, dd. Descending letter order or unrepresentable quality returns None.

split: open-access


prompt:
Intervals from B#3 are measured as if the B were in octave 4, so B#3 to C4 is rejected as descending.

Input [lower, upper] spelled pitches (letter, # or b accidentals, nonnegative octave). The generic number counts letter steps plus 7 per spelled octave plus one; quality compares the semitone span with the major/perfect reference (compounds add 12 per octave). Perfect class for simple numbers 1, 4, 5: P, A, d, AA, dd; others: M, m, A, d, AA, dd. Descending letter order or unrepresentable quality returns None.

split: open-access


prompt:
Double-octave compounds such as C4 to C6 lose one octave of reference span and return None.

Input [lower, upper] spelled pitches (letter, # or b accidentals, nonnegative octave). The generic number counts letter steps plus 7 per spelled octave plus one; quality compares the semitone span with the major/perfect reference (compounds add 12 per octave). Perfect class for simple numbers 1, 4, 5: P, A, d, AA, dd; others: M, m, A, d, AA, dd. Descending letter order or unrepresentable quality returns None.

split: open-access


prompt:
The perfect fourth C4-F4 is named M4 and the augmented fourth C4-F#4 becomes an A4 only by accident of offsets.

Input [lower, upper] spelled pitches (letter, # or b accidentals, nonnegative octave). The generic number counts letter steps plus 7 per spelled octave plus one; quality compares the semitone span with the major/perfect reference (compounds add 12 per octave). Perfect class for simple numbers 1, 4, 5: P, A, d, AA, dd; others: M, m, A, d, AA, dd. Descending letter order or unrepresentable quality returns None.

split: open-access


prompt:
B#3 to Cb4 (letters ascend, pitch descends) is rejected, while C4 to B#3 slips through and produces a bogus label.

Input [lower, upper] spelled pitches (letter, # or b accidentals, nonnegative octave). The generic number counts letter steps plus 7 per spelled octave plus one; quality compares the semitone span with the major/perfect reference (compounds add 12 per octave). Perfect class for simple numbers 1, 4, 5: P, A, d, AA, dd; others: M, m, A, d, AA, dd. Descending letter order or unrepresentable quality returns None.

split: open-access


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

N = 1
observations = []
def solve(x):
    base = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    if not isinstance(x, list) or len(x) != 3:
        return None
    note, ivl, direction = x
    if direction not in ('up', 'down'):
        return None
    if not isinstance(note, str) or len(note) < 2 or note[0] not in base:
        return None
    i = 1
    acc = 0
    while i < len(note) and note[i] in '#b':
        acc += 1 if note[i] == '#' else -1
        i += 1
    if not note[i:].isdigit():
        return None
    octave = int(note[i:])
    if not isinstance(ivl, str) or len(ivl) < 2 or not ivl[1:].isdigit():
        return None
    quality = ivl[0]
    number = int(ivl[1:])
    if number < 1:
        return None
    simple = (number - 1) % 7 + 1
    perfect = simple in (1, 4, 5)
    offsets = {'P': 0, 'A': 1, 'd': -1} if perfect else {'M': 0, 'm': -1, 'A': 1, 'd': -2}
    if quality not in offsets:
        return None
    size = [0, 2, 4, 5, 7, 9, 11][simple - 1] + 12 * ((number - 1) // 7) + offsets[quality]
    sign = 1 if direction == 'up' else -1
    idx = 'CDEFGAB'.index(note[0]) + 7 * octave + sign * number
    pitch = 12 * octave + base[note[0]] + acc + sign * size
    letter = 'CDEFGAB'[idx % 7]
    new_octave = idx // 7
    new_acc = pitch - (12 * new_octave + base[letter])
    if abs(new_acc) > 2 or new_octave < 0:
        return None
    return letter + ('#' * new_acc if new_acc > 0 else 'b' * -new_acc) + str(new_octave)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[(['C4', 'M3', 'up'], 'E4'), (['C4', 'M3', 'down'], 'Ab3'), (['B3', 'm2', 'up'], 'C4'), (['Cb4', 'd3', 'up'], None), (['C4', 'M9', 'up'], 'D5'), (['C0', 'm2', 'down'], None), (['C4', 'X3', 'up'], None), (['C4', 'M4', 'up'], None)], [(['C4', 'M3', 'up'], 'E4'), (['C4', 'M3', 'down'], 'Ab3'), (['B3', 'm2', 'up'], 'C4'), (['C4', 'm2', 'down'], 'B3'), (['C4', 'M10', 'down'], 'Ab2'), (['C4', 'M4', 'up'], None), (['C4', 'P3', 'up'], None), (['C4', 'M3', 'sideways'], None)], [(['C4', 'M3', 'up'], 'E4'), (['C4', 'M3', 'down'], 'Ab3'), (['B3', 'm2', 'up'], 'C4'), (['C4', 'm2', 'down'], 'B3'), (['E4', 'A4', 'up'], 'A#4'), (['F#4', 'A4', 'up'], 'B#4'), (['C4', 'P8', 'up'], 'C5'), (['C5', 'P15', 'down'], 'C3')], [(['C4', 'm2', 'down'], 'B3'), (['E4', 'A4', 'up'], 'A#4'), (['F#4', 'A4', 'up'], 'B#4'), (['C4', 'd5', 'up'], 'Gb4'), (['C4', 'd7', 'up'], 'Bbb4'), (['C4', 'd3', 'up'], 'Ebb4'), (['C4', 'M9', 'up'], 'D5'), (['D4', 'd4', 'down'], 'A#3')], [(['E4', 'A4', 'up'], 'A#4'), (['C4', 'd5', 'up'], 'Gb4'), (['C4', 'd7', 'up'], 'Bbb4'), (['C4', 'd3', 'up'], 'Ebb4'), (['Db4', 'd3', 'up'], 'Fbb4'), (['C4', 'P8', 'up'], 'C5'), (['C4', 'M10', 'down'], 'Ab2'), (['F4', 'A4', 'down'], 'Cb4')]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    base = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    if not isinstance(x, list) or len(x) != 3:
        return None
    note, ivl, direction = x
    if direction not in ('up', 'down'):
        return None
    if not isinstance(note, str) or len(note) < 2 or note[0] not in base:
        return None
    i = 1
    acc = 0
    while i < len(note) and note[i] in '#b':
        acc += 1 if note[i] == '#' else -1
        i += 1
    if not note[i:].isdigit():
        return None
    octave = int(note[i:])
    if not isinstance(ivl, str) or len(ivl) < 2 or not ivl[1:].isdigit():
        return None
    quality = ivl[0]
    number = int(ivl[1:])
    if number < 1:
        return None
    simple = (number - 1) % 7 + 1
    perfect = simple in (1, 4, 5)
    offsets = {'P': 0, 'A': 1, 'd': -1} if perfect else {'M': 0, 'm': -1, 'A': 1, 'd': -2}
    if quality not in offsets:
        return None
    size = [0, 2, 4, 5, 7, 9, 11][simple - 1] + 12 * ((number - 1) // 7) + offsets[quality]
    sign = 1 if direction == 'up' else -1
    idx = 'CDEFGAB'.index(note[0]) + 7 * octave + sign * (number - 1) % 7
    pitch = 12 * octave + base[note[0]] + acc + sign * size
    letter = 'CDEFGAB'[idx % 7]
    new_octave = idx // 7
    new_acc = pitch - (12 * new_octave + base[letter])
    if abs(new_acc) > 2 or new_octave < 0:
        return None
    return letter + ('#' * new_acc if new_acc > 0 else 'b' * -new_acc) + str(new_octave)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[(['C4', 'M3', 'up'], 'E4'), (['C4', 'M3', 'down'], 'Ab3'), (['B3', 'm2', 'up'], 'C4'), (['Cb4', 'd3', 'up'], None), (['C4', 'M9', 'up'], 'D5'), (['C0', 'm2', 'down'], None), (['C4', 'X3', 'up'], None), (['C4', 'M4', 'up'], None)], [(['C4', 'M3', 'up'], 'E4'), (['C4', 'M3', 'down'], 'Ab3'), (['B3', 'm2', 'up'], 'C4'), (['C4', 'm2', 'down'], 'B3'), (['C4', 'M10', 'down'], 'Ab2'), (['C4', 'M4', 'up'], None), (['C4', 'P3', 'up'], None), (['C4', 'M3', 'sideways'], None)], [(['C4', 'M3', 'up'], 'E4'), (['C4', 'M3', 'down'], 'Ab3'), (['B3', 'm2', 'up'], 'C4'), (['C4', 'm2', 'down'], 'B3'), (['E4', 'A4', 'up'], 'A#4'), (['F#4', 'A4', 'up'], 'B#4'), (['C4', 'P8', 'up'], 'C5'), (['C5', 'P15', 'down'], 'C3')], [(['C4', 'm2', 'down'], 'B3'), (['E4', 'A4', 'up'], 'A#4'), (['F#4', 'A4', 'up'], 'B#4'), (['C4', 'd5', 'up'], 'Gb4'), (['C4', 'd7', 'up'], 'Bbb4'), (['C4', 'd3', 'up'], 'Ebb4'), (['C4', 'M9', 'up'], 'D5'), (['D4', 'd4', 'down'], 'A#3')], [(['E4', 'A4', 'up'], 'A#4'), (['C4', 'd5', 'up'], 'Gb4'), (['C4', 'd7', 'up'], 'Bbb4'), (['C4', 'd3', 'up'], 'Ebb4'), (['Db4', 'd3', 'up'], 'Fbb4'), (['C4', 'P8', 'up'], 'C5'), (['C4', 'M10', 'down'], 'Ab2'), (['F4', 'A4', 'down'], 'Cb4')]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A major third up from C is spelled on F (Fb4) instead of E4, because the letter advances one step too far.

Input [note, interval, direction]. note: letter, # or b accidentals, nonnegative octave. interval: quality letter (P, M, m, A, d) and generic number >= 1 with perfect-class numbers 1, 4, 5 (compounds reduce by 7). Direction up or down moves the letter by number-1 steps and the pitch by the interval size; the result is spelled with the moved letter, octave taken from the letter position. Results needing more than two accidentals, or a negative octave, return None.

split: open-access


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

N = 1
observations = []
def solve(x):
    base = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    if not isinstance(x, list) or len(x) != 3:
        return None
    note, ivl, direction = x
    if direction not in ('up', 'down'):
        return None
    if not isinstance(note, str) or len(note) < 2 or note[0] not in base:
        return None
    i = 1
    acc = 0
    while i < len(note) and note[i] in '#b':
        acc += 1 if note[i] == '#' else -1
        i += 1
    if not note[i:].isdigit():
        return None
    octave = int(note[i:])
    if not isinstance(ivl, str) or len(ivl) < 2 or not ivl[1:].isdigit():
        return None
    quality = ivl[0]
    number = int(ivl[1:])
    if number < 1:
        return None
    simple = (number - 1) % 7 + 1
    perfect = simple in (1, 4, 5)
    offsets = {'P': 0, 'A': 1, 'd': -1} if perfect else {'M': 0, 'm': -1, 'A': 1, 'd': -2}
    if quality not in offsets:
        return None
    size = [0, 2, 4, 5, 7, 9, 11][simple - 1] + 12 * ((number - 1) // 7) + offsets[quality]
    sign = 1 if direction == 'up' else -1
    idx = 'CDEFGAB'.index(note[0]) + 7 * octave + sign * (number - 1)
    pitch = 12 * octave + base[note[0]] + acc + sign * size
    letter = 'CDEFGAB'[idx % 7]
    new_octave = octave + sign * ((number - 1) // 7)
    new_acc = pitch - (12 * new_octave + base[letter])
    if abs(new_acc) > 2 or new_octave < 0:
        return None
    return letter + ('#' * new_acc if new_acc > 0 else 'b' * -new_acc) + str(new_octave)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[(['C4', 'M3', 'up'], 'E4'), (['C4', 'M3', 'down'], 'Ab3'), (['C4', 'm2', 'down'], 'B3'), (['E4', 'A4', 'up'], 'A#4'), (['F#4', 'A4', 'up'], 'B#4'), (['C4', 'd5', 'up'], 'Gb4'), (['C4', 'd7', 'up'], 'Bbb4'), (['F4', 'A4', 'down'], 'Cb4')], [(['B3', 'm2', 'up'], 'C4'), (['C4', 'd7', 'up'], 'Bbb4'), (['C4', 'd3', 'up'], 'Ebb4'), (['Db4', 'd3', 'up'], 'Fbb4'), (['Cb4', 'd3', 'up'], None), (['C4', 'M10', 'down'], 'Ab2'), (['C4', 'd1', 'up'], 'Cb4'), (['Bb4', 'd2', 'up'], 'Cbb5')], [(['C4', 'm2', 'down'], 'B3'), (['F#4', 'A4', 'up'], 'B#4'), (['Cb4', 'd3', 'up'], None), (['C4', 'P8', 'up'], 'C5'), (['C4', 'M9', 'up'], 'D5'), (['G4', 'P5', 'up'], 'D5'), (['E#4', 'A6', 'up'], None), (['C4', 'A1', 'down'], 'Cb4')], [(['C4', 'M10', 'down'], 'Ab2'), (['A4', 'M6', 'up'], 'F#5'), (['E#4', 'A6', 'up'], None), (['C0', 'm2', 'down'], None), (['C4', 'X3', 'up'], None), (['C4', 'M4', 'up'], None), (['C4', 'd1', 'up'], 'Cb4'), (['F4', 'A4', 'down'], 'Cb4')], [(['G4', 'P5', 'up'], 'D5'), (['C4', 'M4', 'up'], None), (['C4', 'P3', 'up'], None), (['C4', 'M3', 'sideways'], None), (['Bb3', 'A2', 'up'], 'C#4'), (['C4', 'A1', 'down'], 'Cb4'), (['C4', 'd1', 'down'], 'C#4'), (['Bb4', 'd2', 'up'], 'Cbb5')]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    base = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    if not isinstance(x, list) or len(x) != 3:
        return None
    note, ivl, direction = x
    if direction not in ('up', 'down'):
        return None
    if not isinstance(note, str) or len(note) < 2 or note[0] not in base:
        return None
    i = 1
    acc = 0
    while i < len(note) and note[i] in '#b':
        acc += 1 if note[i] == '#' else -1
        i += 1
    if not note[i:].isdigit():
        return None
    octave = int(note[i:])
    if not isinstance(ivl, str) or len(ivl) < 2 or not ivl[1:].isdigit():
        return None
    quality = ivl[0]
    number = int(ivl[1:])
    if number < 1:
        return None
    simple = (number - 1) % 7 + 1
    perfect = simple in (1, 4, 5)
    offsets = {'P': 0, 'A': 1, 'd': -1} if perfect else {'M': 0, 'm': -1, 'A': 1, 'd': -2}
    if quality not in offsets:
        return None
    size = [0, 2, 4, 5, 7, 9, 11][simple - 1] + 12 * ((number - 1) // 7) + offsets[quality]
    sign = 1 if direction == 'up' else -1
    idx = 'CDEFGAB'.index(note[0]) + 7 * octave + sign * (number - 1)
    pitch = 12 * octave + base[note[0]] + acc + sign * size
    letter = 'CDEFGAB'[idx % 7]
    new_octave = pitch // 12
    new_acc = pitch - (12 * new_octave + base[letter])
    if abs(new_acc) > 2 or new_octave < 0:
        return None
    return letter + ('#' * new_acc if new_acc > 0 else 'b' * -new_acc) + str(new_octave)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[(['C4', 'M3', 'up'], 'E4'), (['C4', 'M3', 'down'], 'Ab3'), (['C4', 'm2', 'down'], 'B3'), (['E4', 'A4', 'up'], 'A#4'), (['F#4', 'A4', 'up'], 'B#4'), (['C4', 'd5', 'up'], 'Gb4'), (['C4', 'd7', 'up'], 'Bbb4'), (['F4', 'A4', 'down'], 'Cb4')], [(['B3', 'm2', 'up'], 'C4'), (['C4', 'd7', 'up'], 'Bbb4'), (['C4', 'd3', 'up'], 'Ebb4'), (['Db4', 'd3', 'up'], 'Fbb4'), (['Cb4', 'd3', 'up'], None), (['C4', 'M10', 'down'], 'Ab2'), (['C4', 'd1', 'up'], 'Cb4'), (['Bb4', 'd2', 'up'], 'Cbb5')], [(['C4', 'm2', 'down'], 'B3'), (['F#4', 'A4', 'up'], 'B#4'), (['Cb4', 'd3', 'up'], None), (['C4', 'P8', 'up'], 'C5'), (['C4', 'M9', 'up'], 'D5'), (['G4', 'P5', 'up'], 'D5'), (['E#4', 'A6', 'up'], None), (['C4', 'A1', 'down'], 'Cb4')], [(['C4', 'M10', 'down'], 'Ab2'), (['A4', 'M6', 'up'], 'F#5'), (['E#4', 'A6', 'up'], None), (['C0', 'm2', 'down'], None), (['C4', 'X3', 'up'], None), (['C4', 'M4', 'up'], None), (['C4', 'd1', 'up'], 'Cb4'), (['F4', 'A4', 'down'], 'Cb4')], [(['G4', 'P5', 'up'], 'D5'), (['C4', 'M4', 'up'], None), (['C4', 'P3', 'up'], None), (['C4', 'M3', 'sideways'], None), (['Bb3', 'A2', 'up'], 'C#4'), (['C4', 'A1', 'down'], 'Cb4'), (['C4', 'd1', 'down'], 'C#4'), (['Bb4', 'd2', 'up'], 'Cbb5')]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
B3 up a minor second returns None instead of C4, because the octave never carries past the letter B.

Input [note, interval, direction]. note: letter, # or b accidentals, nonnegative octave. interval: quality letter (P, M, m, A, d) and generic number >= 1 with perfect-class numbers 1, 4, 5 (compounds reduce by 7). Direction up or down moves the letter by number-1 steps and the pitch by the interval size; the result is spelled with the moved letter, octave taken from the letter position. Results needing more than two accidentals, or a negative octave, return None.

split: open-access


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

N = 1
observations = []
def solve(x):
    base = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    if not isinstance(x, list) or len(x) != 3:
        return None
    note, ivl, direction = x
    if direction not in ('up', 'down'):
        return None
    if not isinstance(note, str) or len(note) < 2 or note[0] not in base:
        return None
    i = 1
    acc = 0
    while i < len(note) and note[i] in '#b':
        acc += 1 if note[i] == '#' else -1
        i += 1
    if not note[i:].isdigit():
        return None
    octave = int(note[i:])
    if not isinstance(ivl, str) or len(ivl) < 2 or not ivl[1:].isdigit():
        return None
    quality = ivl[0]
    number = int(ivl[1:])
    if number < 1:
        return None
    simple = (number - 1) % 7 + 1
    perfect = simple in (1, 4, 5)
    offsets = {'P': 0, 'A': 1, 'd': -1} if perfect else {'M': 0, 'm': -1, 'A': 1, 'd': -2}
    if quality not in offsets:
        return None
    size = [0, 2, 4, 5, 7, 9, 11][simple - 1] + 12 * ((number - 1) // 7) + offsets[quality]
    sign = 1 if direction == 'up' else -1
    idx = 'CDEFGAB'.index(note[0]) + 7 * octave + sign * (number - 1)
    pitch = 12 * octave + base[note[0]] + acc + size
    letter = 'CDEFGAB'[idx % 7]
    new_octave = idx // 7
    new_acc = pitch - (12 * new_octave + base[letter])
    if abs(new_acc) > 2 or new_octave < 0:
        return None
    return letter + ('#' * new_acc if new_acc > 0 else 'b' * -new_acc) + str(new_octave)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[(['C4', 'M3', 'up'], 'E4'), (['C4', 'M3', 'down'], 'Ab3'), (['B3', 'm2', 'up'], 'C4'), (['E4', 'A4', 'up'], 'A#4'), (['F#4', 'A4', 'up'], 'B#4'), (['C4', 'd5', 'up'], 'Gb4'), (['C4', 'M9', 'up'], 'D5'), (['C4', 'M10', 'down'], 'Ab2')], [(['C4', 'm2', 'down'], 'B3'), (['F#4', 'A4', 'up'], 'B#4'), (['C4', 'd5', 'up'], 'Gb4'), (['C4', 'd7', 'up'], 'Bbb4'), (['C4', 'd3', 'up'], 'Ebb4'), (['Db4', 'd3', 'up'], 'Fbb4'), (['C4', 'M10', 'down'], 'Ab2'), (['C4', 'A1', 'down'], 'Cb4')], [(['C4', 'd3', 'up'], 'Ebb4'), (['Db4', 'd3', 'up'], 'Fbb4'), (['Cb4', 'd3', 'up'], None), (['C4', 'P8', 'up'], 'C5'), (['C4', 'M10', 'down'], 'Ab2'), (['G4', 'P5', 'up'], 'D5'), (['C4', 'd1', 'up'], 'Cb4'), (['C4', 'd1', 'down'], 'C#4')], [(['C4', 'M9', 'up'], 'D5'), (['G4', 'P5', 'up'], 'D5'), (['A4', 'M6', 'up'], 'F#5'), (['E#4', 'A6', 'up'], None), (['C0', 'm2', 'down'], None), (['C4', 'X3', 'up'], None), (['C4', 'A1', 'down'], 'Cb4'), (['C5', 'P15', 'down'], 'C3')], [(['C4', 'M10', 'down'], 'Ab2'), (['C0', 'm2', 'down'], None), (['C4', 'X3', 'up'], None), (['C4', 'M4', 'up'], None), (['C4', 'P3', 'up'], None), (['C4', 'd1', 'down'], 'C#4'), (['C5', 'P15', 'down'], 'C3'), (['D4', 'd4', 'down'], 'A#3')]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    base = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    if not isinstance(x, list) or len(x) != 3:
        return None
    note, ivl, direction = x
    if direction not in ('up', 'down'):
        return None
    if not isinstance(note, str) or len(note) < 2 or note[0] not in base:
        return None
    i = 1
    acc = 0
    while i < len(note) and note[i] in '#b':
        acc += 1 if note[i] == '#' else -1
        i += 1
    if not note[i:].isdigit():
        return None
    octave = int(note[i:])
    if not isinstance(ivl, str) or len(ivl) < 2 or not ivl[1:].isdigit():
        return None
    quality = ivl[0]
    number = int(ivl[1:])
    if number < 1:
        return None
    simple = (number - 1) % 7 + 1
    perfect = simple in (1, 4, 5)
    offsets = {'P': 0, 'A': 1, 'd': -1} if perfect else {'M': 0, 'm': -1, 'A': 1, 'd': -2}
    if quality not in offsets:
        return None
    size = [0, 2, 4, 5, 7, 9, 11][simple - 1] + 12 * ((number - 1) // 7) + offsets[quality]
    sign = 1 if direction == 'up' else -1
    idx = 'CDEFGAB'.index(note[0]) + 7 * octave + sign * (number - 1)
    pitch = 12 * octave + base[note[0]] + acc + sign * size % 12
    letter = 'CDEFGAB'[idx % 7]
    new_octave = idx // 7
    new_acc = pitch - (12 * new_octave + base[letter])
    if abs(new_acc) > 2 or new_octave < 0:
        return None
    return letter + ('#' * new_acc if new_acc > 0 else 'b' * -new_acc) + str(new_octave)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[(['C4', 'M3', 'up'], 'E4'), (['C4', 'M3', 'down'], 'Ab3'), (['B3', 'm2', 'up'], 'C4'), (['E4', 'A4', 'up'], 'A#4'), (['F#4', 'A4', 'up'], 'B#4'), (['C4', 'd5', 'up'], 'Gb4'), (['C4', 'M9', 'up'], 'D5'), (['C4', 'M10', 'down'], 'Ab2')], [(['C4', 'm2', 'down'], 'B3'), (['F#4', 'A4', 'up'], 'B#4'), (['C4', 'd5', 'up'], 'Gb4'), (['C4', 'd7', 'up'], 'Bbb4'), (['C4', 'd3', 'up'], 'Ebb4'), (['Db4', 'd3', 'up'], 'Fbb4'), (['C4', 'M10', 'down'], 'Ab2'), (['C4', 'A1', 'down'], 'Cb4')], [(['C4', 'd3', 'up'], 'Ebb4'), (['Db4', 'd3', 'up'], 'Fbb4'), (['Cb4', 'd3', 'up'], None), (['C4', 'P8', 'up'], 'C5'), (['C4', 'M10', 'down'], 'Ab2'), (['G4', 'P5', 'up'], 'D5'), (['C4', 'd1', 'up'], 'Cb4'), (['C4', 'd1', 'down'], 'C#4')], [(['C4', 'M9', 'up'], 'D5'), (['G4', 'P5', 'up'], 'D5'), (['A4', 'M6', 'up'], 'F#5'), (['E#4', 'A6', 'up'], None), (['C0', 'm2', 'down'], None), (['C4', 'X3', 'up'], None), (['C4', 'A1', 'down'], 'Cb4'), (['C5', 'P15', 'down'], 'C3')], [(['C4', 'M10', 'down'], 'Ab2'), (['C0', 'm2', 'down'], None), (['C4', 'X3', 'up'], None), (['C4', 'M4', 'up'], None), (['C4', 'P3', 'up'], None), (['C4', 'd1', 'down'], 'C#4'), (['C5', 'P15', 'down'], 'C3'), (['D4', 'd4', 'down'], 'A#3')]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Downward transpositions move the letter down but the pitch up, producing None or wild accidentals (C4 down M3 fails).

Input [note, interval, direction]. note: letter, # or b accidentals, nonnegative octave. interval: quality letter (P, M, m, A, d) and generic number >= 1 with perfect-class numbers 1, 4, 5 (compounds reduce by 7). Direction up or down moves the letter by number-1 steps and the pitch by the interval size; the result is spelled with the moved letter, octave taken from the letter position. Results needing more than two accidentals, or a negative octave, return None.

split: open-access


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

N = 1
observations = []
def solve(x):
    base = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    if not isinstance(x, list) or len(x) != 3:
        return None
    note, ivl, direction = x
    if direction not in ('up', 'down'):
        return None
    if not isinstance(note, str) or len(note) < 2 or note[0] not in base:
        return None
    i = 1
    acc = 0
    while i < len(note) and note[i] in '#b':
        acc += 1 if note[i] == '#' else -1
        i += 1
    if not note[i:].isdigit():
        return None
    octave = int(note[i:])
    if not isinstance(ivl, str) or len(ivl) < 2 or not ivl[1:].isdigit():
        return None
    quality = ivl[0]
    number = int(ivl[1:])
    if number < 1:
        return None
    simple = (number - 1) % 7 + 1
    perfect = simple in (1, 4, 5)
    offsets = {'P': 0, 'A': 1, 'd': -1} if perfect else {'M': 0, 'm': -1, 'A': 1, 'd': -1}
    if quality not in offsets:
        return None
    size = [0, 2, 4, 5, 7, 9, 11][simple - 1] + 12 * ((number - 1) // 7) + offsets[quality]
    sign = 1 if direction == 'up' else -1
    idx = 'CDEFGAB'.index(note[0]) + 7 * octave + sign * (number - 1)
    pitch = 12 * octave + base[note[0]] + acc + sign * size
    letter = 'CDEFGAB'[idx % 7]
    new_octave = idx // 7
    new_acc = pitch - (12 * new_octave + base[letter])
    if abs(new_acc) > 2 or new_octave < 0:
        return None
    return letter + ('#' * new_acc if new_acc > 0 else 'b' * -new_acc) + str(new_octave)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[(['C4', 'M3', 'up'], 'E4'), (['C4', 'M3', 'down'], 'Ab3'), (['B3', 'm2', 'up'], 'C4'), (['C4', 'm2', 'down'], 'B3'), (['E4', 'A4', 'up'], 'A#4'), (['C4', 'd7', 'up'], 'Bbb4'), (['Db4', 'd3', 'up'], 'Fbb4'), (['Bb4', 'd2', 'up'], 'Cbb5')], [(['C4', 'm2', 'down'], 'B3'), (['E4', 'A4', 'up'], 'A#4'), (['F#4', 'A4', 'up'], 'B#4'), (['C4', 'd5', 'up'], 'Gb4'), (['C4', 'd7', 'up'], 'Bbb4'), (['C4', 'd3', 'up'], 'Ebb4'), (['Cb4', 'd3', 'up'], None), (['C4', 'P8', 'up'], 'C5')], [(['C4', 'd5', 'up'], 'Gb4'), (['C4', 'd3', 'up'], 'Ebb4'), (['Db4', 'd3', 'up'], 'Fbb4'), (['C4', 'P8', 'up'], 'C5'), (['C4', 'M9', 'up'], 'D5'), (['C4', 'M10', 'down'], 'Ab2'), (['G4', 'P5', 'up'], 'D5'), (['Bb4', 'd2', 'up'], 'Cbb5')], [(['C4', 'd7', 'up'], 'Bbb4'), (['Db4', 'd3', 'up'], 'Fbb4'), (['Cb4', 'd3', 'up'], None), (['C4', 'M10', 'down'], 'Ab2'), (['G4', 'P5', 'up'], 'D5'), (['A4', 'M6', 'up'], 'F#5'), (['E#4', 'A6', 'up'], None), (['Bb4', 'd2', 'up'], 'Cbb5')], [(['C4', 'd7', 'up'], 'Bbb4'), (['C4', 'd3', 'up'], 'Ebb4'), (['E#4', 'A6', 'up'], None), (['C0', 'm2', 'down'], None), (['C4', 'X3', 'up'], None), (['C4', 'M4', 'up'], None), (['C4', 'P3', 'up'], None), (['Bb4', 'd2', 'up'], 'Cbb5')]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    base = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    if not isinstance(x, list) or len(x) != 3:
        return None
    note, ivl, direction = x
    if direction not in ('up', 'down'):
        return None
    if not isinstance(note, str) or len(note) < 2 or note[0] not in base:
        return None
    i = 1
    acc = 0
    while i < len(note) and note[i] in '#b':
        acc += 1 if note[i] == '#' else -1
        i += 1
    if not note[i:].isdigit():
        return None
    octave = int(note[i:])
    if not isinstance(ivl, str) or len(ivl) < 2 or not ivl[1:].isdigit():
        return None
    quality = ivl[0]
    number = int(ivl[1:])
    if number < 1:
        return None
    simple = (number - 1) % 7 + 1
    perfect = simple in (1, 4, 5)
    offsets = {'P': 0, 'A': 1, 'd': -1} if perfect else {'M': 0, 'm': -1, 'A': 1, 'd': -3}
    if quality not in offsets:
        return None
    size = [0, 2, 4, 5, 7, 9, 11][simple - 1] + 12 * ((number - 1) // 7) + offsets[quality]
    sign = 1 if direction == 'up' else -1
    idx = 'CDEFGAB'.index(note[0]) + 7 * octave + sign * (number - 1)
    pitch = 12 * octave + base[note[0]] + acc + sign * size
    letter = 'CDEFGAB'[idx % 7]
    new_octave = idx // 7
    new_acc = pitch - (12 * new_octave + base[letter])
    if abs(new_acc) > 2 or new_octave < 0:
        return None
    return letter + ('#' * new_acc if new_acc > 0 else 'b' * -new_acc) + str(new_octave)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[(['C4', 'M3', 'up'], 'E4'), (['C4', 'M3', 'down'], 'Ab3'), (['B3', 'm2', 'up'], 'C4'), (['C4', 'm2', 'down'], 'B3'), (['E4', 'A4', 'up'], 'A#4'), (['C4', 'd7', 'up'], 'Bbb4'), (['Db4', 'd3', 'up'], 'Fbb4'), (['Bb4', 'd2', 'up'], 'Cbb5')], [(['C4', 'm2', 'down'], 'B3'), (['E4', 'A4', 'up'], 'A#4'), (['F#4', 'A4', 'up'], 'B#4'), (['C4', 'd5', 'up'], 'Gb4'), (['C4', 'd7', 'up'], 'Bbb4'), (['C4', 'd3', 'up'], 'Ebb4'), (['Cb4', 'd3', 'up'], None), (['C4', 'P8', 'up'], 'C5')], [(['C4', 'd5', 'up'], 'Gb4'), (['C4', 'd3', 'up'], 'Ebb4'), (['Db4', 'd3', 'up'], 'Fbb4'), (['C4', 'P8', 'up'], 'C5'), (['C4', 'M9', 'up'], 'D5'), (['C4', 'M10', 'down'], 'Ab2'), (['G4', 'P5', 'up'], 'D5'), (['Bb4', 'd2', 'up'], 'Cbb5')], [(['C4', 'd7', 'up'], 'Bbb4'), (['Db4', 'd3', 'up'], 'Fbb4'), (['Cb4', 'd3', 'up'], None), (['C4', 'M10', 'down'], 'Ab2'), (['G4', 'P5', 'up'], 'D5'), (['A4', 'M6', 'up'], 'F#5'), (['E#4', 'A6', 'up'], None), (['Bb4', 'd2', 'up'], 'Cbb5')], [(['C4', 'd7', 'up'], 'Bbb4'), (['C4', 'd3', 'up'], 'Ebb4'), (['E#4', 'A6', 'up'], None), (['C0', 'm2', 'down'], None), (['C4', 'X3', 'up'], None), (['C4', 'M4', 'up'], None), (['C4', 'P3', 'up'], None), (['Bb4', 'd2', 'up'], 'Cbb5')]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
C4 up a diminished seventh returns Bb4 instead of Bbb4; diminished thirds and sixths collapse onto minor.

Input [note, interval, direction]. note: letter, # or b accidentals, nonnegative octave. interval: quality letter (P, M, m, A, d) and generic number >= 1 with perfect-class numbers 1, 4, 5 (compounds reduce by 7). Direction up or down moves the letter by number-1 steps and the pitch by the interval size; the result is spelled with the moved letter, octave taken from the letter position. Results needing more than two accidentals, or a negative octave, return None.

split: open-access


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

N = 1
observations = []
def solve(x):
    base = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    if not isinstance(x, list) or len(x) != 3:
        return None
    note, ivl, direction = x
    if direction not in ('up', 'down'):
        return None
    if not isinstance(note, str) or len(note) < 2 or note[0] not in base:
        return None
    i = 1
    acc = 0
    while i < len(note) and note[i] in '#b':
        acc += 1 if note[i] == '#' else -1
        i += 1
    if not note[i:].isdigit():
        return None
    octave = int(note[i:])
    if not isinstance(ivl, str) or len(ivl) < 2 or not ivl[1:].isdigit():
        return None
    quality = ivl[0]
    number = int(ivl[1:])
    if number < 1:
        return None
    simple = (number - 1) % 7 + 1
    perfect = simple in (1, 4, 5)
    offsets = {'P': 0, 'A': 1, 'd': -1} if perfect else {'M': 0, 'm': -1, 'A': 1, 'd': -2}
    if quality not in offsets:
        return None
    size = [0, 2, 4, 5, 7, 9, 11][simple - 1] + 12 * ((number - 1) // 7) + offsets[quality]
    sign = 1 if direction == 'up' else -1
    idx = 'CDEFGAB'.index(note[0]) + 7 * octave + sign * (number - 1)
    pitch = 12 * octave + base[note[0]] + acc + sign * size
    letter = 'CDEFGAB'[idx % 7]
    new_octave = idx // 7
    new_acc = pitch - (12 * new_octave + base[letter])
    if abs(new_acc) > 1 or new_octave < 0:
        return None
    return letter + ('#' * new_acc if new_acc > 0 else 'b' * -new_acc) + str(new_octave)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[(['C4', 'M3', 'up'], 'E4'), (['C4', 'M3', 'down'], 'Ab3'), (['B3', 'm2', 'up'], 'C4'), (['C4', 'm2', 'down'], 'B3'), (['E4', 'A4', 'up'], 'A#4'), (['C4', 'd7', 'up'], 'Bbb4'), (['Db4', 'd3', 'up'], 'Fbb4'), (['Cb4', 'd3', 'up'], None)], [(['C4', 'm2', 'down'], 'B3'), (['E4', 'A4', 'up'], 'A#4'), (['F#4', 'A4', 'up'], 'B#4'), (['C4', 'd5', 'up'], 'Gb4'), (['C4', 'd3', 'up'], 'Ebb4'), (['Cb4', 'd3', 'up'], None), (['C4', 'P8', 'up'], 'C5'), (['G#4', 'A5', 'up'], 'D##5')], [(['C4', 'd5', 'up'], 'Gb4'), (['Db4', 'd3', 'up'], 'Fbb4'), (['Cb4', 'd3', 'up'], None), (['C4', 'P8', 'up'], 'C5'), (['C4', 'M9', 'up'], 'D5'), (['C4', 'M10', 'down'], 'Ab2'), (['G4', 'P5', 'up'], 'D5'), (['Bb4', 'd2', 'up'], 'Cbb5')], [(['C4', 'd7', 'up'], 'Bbb4'), (['Cb4', 'd3', 'up'], None), (['C4', 'M10', 'down'], 'Ab2'), (['G4', 'P5', 'up'], 'D5'), (['A4', 'M6', 'up'], 'F#5'), (['E#4', 'A6', 'up'], None), (['C0', 'm2', 'down'], None), (['G#4', 'A5', 'up'], 'D##5')], [(['C4', 'd3', 'up'], 'Ebb4'), (['Cb4', 'd3', 'up'], None), (['E#4', 'A6', 'up'], None), (['C0', 'm2', 'down'], None), (['C4', 'X3', 'up'], None), (['C4', 'M4', 'up'], None), (['C4', 'P3', 'up'], None), (['Bb4', 'd2', 'up'], 'Cbb5')]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    base = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    if not isinstance(x, list) or len(x) != 3:
        return None
    note, ivl, direction = x
    if direction not in ('up', 'down'):
        return None
    if not isinstance(note, str) or len(note) < 2 or note[0] not in base:
        return None
    i = 1
    acc = 0
    while i < len(note) and note[i] in '#b':
        acc += 1 if note[i] == '#' else -1
        i += 1
    if not note[i:].isdigit():
        return None
    octave = int(note[i:])
    if not isinstance(ivl, str) or len(ivl) < 2 or not ivl[1:].isdigit():
        return None
    quality = ivl[0]
    number = int(ivl[1:])
    if number < 1:
        return None
    simple = (number - 1) % 7 + 1
    perfect = simple in (1, 4, 5)
    offsets = {'P': 0, 'A': 1, 'd': -1} if perfect else {'M': 0, 'm': -1, 'A': 1, 'd': -2}
    if quality not in offsets:
        return None
    size = [0, 2, 4, 5, 7, 9, 11][simple - 1] + 12 * ((number - 1) // 7) + offsets[quality]
    sign = 1 if direction == 'up' else -1
    idx = 'CDEFGAB'.index(note[0]) + 7 * octave + sign * (number - 1)
    pitch = 12 * octave + base[note[0]] + acc + sign * size
    letter = 'CDEFGAB'[idx % 7]
    new_octave = idx // 7
    new_acc = pitch - (12 * new_octave + base[letter])
    if new_acc > 2 or new_octave < 0:
        return None
    return letter + ('#' * new_acc if new_acc > 0 else 'b' * -new_acc) + str(new_octave)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[(['C4', 'M3', 'up'], 'E4'), (['C4', 'M3', 'down'], 'Ab3'), (['B3', 'm2', 'up'], 'C4'), (['C4', 'm2', 'down'], 'B3'), (['E4', 'A4', 'up'], 'A#4'), (['C4', 'd7', 'up'], 'Bbb4'), (['Db4', 'd3', 'up'], 'Fbb4'), (['Cb4', 'd3', 'up'], None)], [(['C4', 'm2', 'down'], 'B3'), (['E4', 'A4', 'up'], 'A#4'), (['F#4', 'A4', 'up'], 'B#4'), (['C4', 'd5', 'up'], 'Gb4'), (['C4', 'd3', 'up'], 'Ebb4'), (['Cb4', 'd3', 'up'], None), (['C4', 'P8', 'up'], 'C5'), (['G#4', 'A5', 'up'], 'D##5')], [(['C4', 'd5', 'up'], 'Gb4'), (['Db4', 'd3', 'up'], 'Fbb4'), (['Cb4', 'd3', 'up'], None), (['C4', 'P8', 'up'], 'C5'), (['C4', 'M9', 'up'], 'D5'), (['C4', 'M10', 'down'], 'Ab2'), (['G4', 'P5', 'up'], 'D5'), (['Bb4', 'd2', 'up'], 'Cbb5')], [(['C4', 'd7', 'up'], 'Bbb4'), (['Cb4', 'd3', 'up'], None), (['C4', 'M10', 'down'], 'Ab2'), (['G4', 'P5', 'up'], 'D5'), (['A4', 'M6', 'up'], 'F#5'), (['E#4', 'A6', 'up'], None), (['C0', 'm2', 'down'], None), (['G#4', 'A5', 'up'], 'D##5')], [(['C4', 'd3', 'up'], 'Ebb4'), (['Cb4', 'd3', 'up'], None), (['E#4', 'A6', 'up'], None), (['C0', 'm2', 'down'], None), (['C4', 'X3', 'up'], None), (['C4', 'M4', 'up'], None), (['C4', 'P3', 'up'], None), (['Bb4', 'd2', 'up'], 'Cbb5')]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Legitimate results like Bbb4 or D##5 are rejected even though two accidentals are within contract.

Input [note, interval, direction]. note: letter, # or b accidentals, nonnegative octave. interval: quality letter (P, M, m, A, d) and generic number >= 1 with perfect-class numbers 1, 4, 5 (compounds reduce by 7). Direction up or down moves the letter by number-1 steps and the pitch by the interval size; the result is spelled with the moved letter, octave taken from the letter position. Results needing more than two accidentals, or a negative octave, return None.

split: open-access