"""Print every number the lesson quotes. Run it from this folder: python3 show_numbers.py"""
from toy import WORDINGS, Defences, all_settings, notes_leave, run


def verdict(result):
    return "notes sent" if notes_leave(result) else "stopped"


def got_through(d):
    return sum(notes_leave(run(text, d)) for _, _, text in WORDINGS)


print("== Words only: which wordings get the notes out (no limit is on)")
print("  wording | nothing on | instruction line | markers | both")
words = [Defences(), Defences(line=True), Defences(markers=True), Defences(line=True, markers=True)]
for _, name, text in WORDINGS:
    print(f"  {name} | " + " | ".join(verdict(run(text, d)) for d in words))
print("  wordings through (of 3) | " + " | ".join(str(got_through(d)) for d in words))

print("\n== Limits: with no word defence on, what each limit does to the three wordings and to your own email")
rows = [("nothing", Defences()), ("no send tool", Defences(no_tool=True)), ("allow-list", Defences(allow_list=True)),
        ("ask first, reader reads", Defences(ask=True)), ("ask first, reader answers yes to all", Defences(ask=True, reads=False))]
print("  limit | wordings through (of 3) | your own email")
for name, d in rows:
    mine = run(WORDINGS[0][2], d)[2]
    print(f"  {name} | {got_through(d)} | {mine}")

print("\n== The sweep: 64 settings x 3 wordings")
runs = [(d, text) for d in all_settings() for _, _, text in WORDINGS]
leaks = [(d, text) for d, text in runs if notes_leave(run(text, d))]
limit_works = [(d, text) for d, text in runs if d.no_tool or d.allow_list or (d.ask and d.reads)]
print(f"  runs: {len(runs)}; notes leave in {len(leaks)}")
print(f"  runs with a working limit (no tool, or allow-list, or ask first with a reader who reads): {len(limit_works)}; "
      f"notes leave in {sum(notes_leave(run(text, d)) for d, text in limit_works)}")
no_limit = [(d, text) for d, text in runs if (d, text) not in limit_works]
print(f"  runs with no working limit: {len(no_limit)}; notes leave in {sum(notes_leave(run(text, d)) for d, text in no_limit)}")
no_limit_words = [(d, text) for d, text in no_limit if d.line or d.markers]
print(f"  of those, with a word defence on: {len(no_limit_words)}; notes leave in "
      f"{sum(notes_leave(run(text, d)) for d, text in no_limit_words)}")
no_defence = [(d, text) for d, text in no_limit if not (d.line or d.markers)]
print(f"  of those, with no word defence either: {len(no_defence)}; notes leave in "
      f"{sum(notes_leave(run(text, d)) for d, text in no_defence)}")

print("\n== Your own email in each setting (64 settings)")
counts = {}
for d in all_settings():
    result = run(WORDINGS[0][2], d)[2]
    counts[result] = counts.get(result, 0) + 1
print("  " + "; ".join(f"{k}: {v}" for k, v in sorted(counts.items())))
