#!/usr/bin/env python3 """Exhaustive verifier for covering designs C(v,k,t). Usage: python verify_covering.py v k t [blockfile] Block file format: one block per line, ascending 0-based integers separated by whitespace. Reads stdin if no filename is given. Checks, with no shortcuts: 1. every line parses to exactly k distinct integers in {0..v-1}; 2. every t-subset of {0..v-1} is contained in at least one block. Prints VERDICT: VALID/INVALID and statistics. No dependencies. """ import itertools import sys def main() -> int: if len(sys.argv) < 4: print(__doc__) return 2 v, k, t = int(sys.argv[1]), int(sys.argv[2]), int(sys.argv[3]) data = open(sys.argv[4]).read() if len(sys.argv) > 4 else sys.stdin.read() blocks = [] malformed = 0 for lineno, line in enumerate(data.splitlines(), 1): parts = line.split() if not parts or parts[0].startswith("#"): continue try: b = [int(x) for x in parts] except ValueError: malformed += 1 continue if len(b) != k or any(x < 0 or x >= v for x in b) or any( b[i] >= b[i + 1] for i in range(k - 1) ): malformed += 1 continue blocks.append(b) covered = set() for b in blocks: for ts in itertools.combinations(b, t): covered.add(ts) total = sum(1 for _ in itertools.combinations(range(v), t)) uncovered = total - len(covered) ok = (malformed == 0) and (uncovered == 0) print(f"blocks={len(blocks)} malformed={malformed} " f"t_subsets={total} covered={len(covered)} uncovered={uncovered}") print("VERDICT: VALID" if ok else "VERDICT: INVALID") return 0 if ok else 1 if __name__ == "__main__": sys.exit(main())