TARGET = list("ABCDEF")


def greedy_round(length, mismatch):
    # Greedy prefix illustration, not stochastic speculative sampling.
    draft = TARGET[:length]
    if 1 <= mismatch <= length:
        draft[mismatch - 1] = "X"
    accepted = 0
    while accepted < length and draft[accepted] == TARGET[accepted]:
        accepted += 1
    correction = TARGET[accepted] if accepted < length else None
    committed = draft[:accepted] + ([correction] if correction else [])
    return {"draft": draft, "accepted": accepted,
            "correction": correction, "committed": committed}


# Verification: prefix-only acceptance; no stochastic sampling claim.
assert greedy_round(4, 3)["committed"] == list("ABC")
assert greedy_round(4, 1)["accepted"] == 0
assert greedy_round(4, 0)["committed"] == list("ABCD")
fixtures = []
for length in (2, 4, 6):
    for mismatch in range(7):
        value = greedy_round(length, mismatch)
        assert value["committed"] == TARGET[:len(value["committed"])]
        fixtures.append({"inputs": {"length": str(length),
                                    "mismatch": str(mismatch)},
                         "expected": value})

import json
print(json.dumps({"fixtures": fixtures, "checks_passed": True}))
