"""The challenge rescored after the reviews of 2026-11-30 21:11 (PRAXIS, LABOR, ARCHIVE). score.py and challenge.json stand as the first
scoring. Changes, each from a review checked in the seat:
 1. Relational scoring throughout: a member counts when the relation stands, in other words or turned (Mark 14:20, the shared dish).
 2. Every member also scored on extant letters for the scroll (1QS VI 5 has the priest's hand first, extant; only 1QSa II 18's
    prohibition is restored).
 3. A second table with an allowance for connected passages, the same allowance the scroll gets (1QS and 1QSa are on one scroll):
    the same section of the same work, or a passage the candidate itself names.
 4. 1 Chronicles 29:20-23, found by the ungated search (search_ungated.py), added.
Writes challenge2.json with the full binary matrix."""
import json
F = ["F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9"]
NAMES = {"F1": "company", "F2": "evening/feast", "F3": "bread and wine", "F4": "presider blesses first", "F5": "messianic figure",
         "F6": "the hand", "F7": "seats by rank or glory", "F8": "the end", "F9": "the many/covenant"}
def row(**kw): return {f: kw.get(f, "") for f in F}
STRICT = {
 "1QS VI 2-9 with 1QSa I 1, II 11-22": row(F1="ten men, 1QS VI 3 (extant)", F3="הלחם והתירוש, 1QS VI 4-6 (extant)",
   F4="הכוהן ישלח ידו לרשונה להברך, 1QS VI 5 (extant)", F5="משיח ישראל, 1QSa II 20 (extant)",
   F6="the priest stretches out his hand first, 1QS VI 5 (extant); no one before him, 1QSa II 18 (restored)",
   F7="איש כתכונו ישבו, 1QS VI 4; לפי כבודו, 1QSa II 14, 21 (extant)", F8="באחרית הימים, 1QSa I 1 (extant)", F9="הרבים, 1QS VI 8 (extant)"),
 "Josephus, War 2.128-133": row(F1="members only, 2.129", F2="dinner on return at evening, 2.131-132", F4="προκατεύχεται ὁ ἱερεύς, 2.131",
   F6="γεύσασθαί τινα πρὶν τῆς εὐχῆς ἀθέμιτον, 2.131"),
 "Philo, De vita contemplativa 64-89": row(F1="the company", F2="the feast; the all-night vigil", F7="reclining by order of admission, 67, 75"),
 "Genesis 14:18-20": row(F3="ἄρτους καὶ οἶνον", F4="ηὐλόγησεν", F5="king of Salem and priest of the Most High"),
 "1 Chronicles 29:20-23": row(F1="πᾶσα ἡ ἐκκλησία", F2="that day; with joy (a feast, AJ 7.382 ἑώρτασεν)", F4="David bids the assembly bless; they bless",
   F5="ἔχρισαν … εἰς βασιλέα καὶ Σαδὼκ εἰς ἱερωσύνην: the anointed king and the priest, at the meal", F7="Solomon sat on the throne of David his father"),
 "Revelation 3:20-21": row(F5="the speaker dines with him", F7="καθίσαι μετ' ἐμοῦ ἐν τῷ θρόνῳ μου", F8="ὁ νικῶν: the promise at the end"),
 "Revelation 19:7-9": row(F5="the Lamb", F8="the marriage supper of the Lamb"),
 "Exodus 12:1-14": row(F1="πᾶσα συναγωγή, by number of souls", F2="πρὸς ἑσπέραν; that night"),
 "Exodus 24:1-11": row(F1="Moses, Aaron, Nadab, Abihu, seventy elders", F9="τὸ αἷμα τῆς διαθήκης, 24:8"),
 "Joseph and Aseneth 8 (Latin, as seated)": row(F3="panem benedictum vite … calicem benedictum incorruptionis", F8="the rest prepared for the elect; for ever"),
}
ALLOW = {  # connected passages: same section of the same work, or a passage the candidate names
 "Josephus, War 2.119-161 (the Essene section)": dict(STRICT["Josephus, War 2.128-133"], F9="2.139: awful oaths sworn before touching the common food; 2.146: they obey the majority (τοῖς πλείοσιν)"),
 "Genesis 14:18-20 with Psalm 109(110):1-4 (named there)": dict(STRICT["Genesis 14:18-20"], F7="Κάθου ἐκ δεξιῶν μου, 109:1", F8="ἐν ἡμέρᾳ ὀργῆς … κρινεῖ ἐν τοῖς ἔθνεσιν, 109:5-6"),
 "Exodus 12 with Exodus 24": dict(STRICT["Exodus 12:1-14"], F9="the blood of the covenant, 24:8"),
 "Revelation 3:20-21 with 19:7-9": dict(STRICT["Revelation 3:20-21"]),
}
TELL = {
 "Matthew 26:17-30": row(F1="μετὰ τῶν δώδεκα", F2="ὀψίας; τὸ πάσχα", F3="ἄρτον; ποτήριον; γενήματος τῆς ἀμπέλου", F4="εὐλογήσας ἔκλασεν",
   F5="the Christ", F6="ὁ ἐμβάψας μετ' ἐμοῦ τὴν χεῖρα ἐν τῷ τρυβλίῳ", F8="καινὸν ἐν τῇ βασιλείᾳ τοῦ Πατρός μου", F9="διαθήκης; περὶ πολλῶν"),
 "Mark 14:17-26": row(F1="μετὰ τῶν δώδεκα", F2="ὀψίας; τὸ πάσχα", F3="ἄρτον; ποτήριον", F4="εὐλογήσας ἔκλασεν", F5="the Christ",
   F6="ὁ ἐμβαπτόμενος μετ' ἐμοῦ εἰς τὸ τρύβλιον (relational: the shared dish, no word for the hand)", F8="καινὸν ἐν τῇ βασιλείᾳ τοῦ Θεοῦ", F9="διαθήκης; ὑπὲρ πολλῶν"),
 "Luke 22:14-30": row(F1="οἱ ἀπόστολοι; the twelve tribes, 22:30", F2="ἡ ὥρα; τὸ πάσχα", F3="ἄρτον; ποτήριον", F4="εὐχαριστήσας (the cup first, then the bread)",
   F5="the Christ", F6="ἡ χεὶρ τοῦ παραδιδόντος με μετ' ἐμοῦ ἐπὶ τῆς τραπέζης, 22:21", F7="τίς … μείζων, 22:24-27; ἐπὶ θρόνων, 22:30",
   F8="ἕως ὅτου ἡ βασιλεία τοῦ Θεοῦ ἔλθῃ; at my table in my kingdom", F9="ἡ καινὴ διαθήκη"),
 "1 Corinthians 11:17-34": row(F1="ἐν ἐκκλησίᾳ", F2="ἐν τῇ νυκτὶ ᾗ παρεδίδετο", F3="ἄρτον; ποτήριον", F4="εὐχαριστήσας", F5="the Lord",
   F6="ἕκαστος τὸ ἴδιον δεῖπνον προλαμβάνει, 11:21; ἀλλήλους ἐκδέχεσθε, 11:33 (relational: who takes first)", F8="ἄχρι οὗ ἔλθῃ", F9="ἡ καινὴ διαθήκη"),
}
def mat(D): return {k: {"score": sum(1 for f in F if v[f]), "binary": {f: int(bool(v[f])) for f in F}, "words": {f: v[f] for f in F if v[f]}} for k, v in D.items()}
out = {"features": NAMES, "strict": mat(STRICT), "with_connected_passages": mat(ALLOW), "tellings": mat(TELL),
       "scroll_on_extant_letters_only": 8,
       "note": "The features were drawn from the reading of Matthew's supper beside the scroll (DSS-AND-MATTHEW §1.3), so the test measures how distinctive that configuration is; a feature set built blind from Matthew alone is in ../challenge/blind2/."}
json.dump(out, open("challenge2.json", "w"), ensure_ascii=False, indent=1)
for t in ("strict", "with_connected_passages", "tellings"):
    print("==", t)
    for k, v in out[t].items(): print(v["score"], "".join(str(v["binary"][f]) for f in F), k)
