"""Four deliberately small, nonvehicle implementations of a fictional rule."""

ALPHABET = ("FAULT", "HEALTHY", "UNKNOWN")


def run(samples, implementation):
    if implementation not in ("baseline", "corrected", "off_by_one", "unknown_pauses"):
        raise ValueError("unknown implementation")
    if not isinstance(samples, list) or any(s not in ALPHABET for s in samples):
        raise ValueError("samples must be a list drawn from the declared alphabet")
    count = 0
    flags = []
    for sample in samples:
        if implementation == "baseline":
            # Defect: total faults accumulate across sequence-breaking samples.
            if sample == "FAULT":
                count += 1
            flags.append(count >= 3)
        elif implementation == "corrected":
            count = min(count + 1, 3) if sample == "FAULT" else 0
            flags.append(count >= 3)
        elif implementation == "off_by_one":
            # Seeded alternative: the flag is one eligible sample too late.
            count = min(count + 1, 4) if sample == "FAULT" else 0
            flags.append(count >= 4)
        else:
            # Seeded alternative: UNKNOWN pauses rather than breaks the run.
            if sample == "FAULT":
                count = min(count + 1, 3)
            elif sample == "HEALTHY":
                count = 0
            flags.append(count >= 3)
    return flags
