{
 "schema": 1,
 "book": "golden-snitch",
 "title": "The Invisible Golden Snitch",
 "why_this_recipe": "Don't take our word for it. Each result here comes with its files and a check guide, and each guide says which checks you can rerun yourself. Some results rest on logs from programs that are not part of this book, or on files available on request; the guide says which. Where your run matches ours, you checked that part rather than trusted it. If something breaks, confuses you or does not match, you are welcome to tell us. We fix mistakes in the open and credit the person who found them.",
 "base_url": "https://gocheckyourself.org/data/files/golden-snitch",
 "written_recipe": "the chapter 'Verify: The Invisible Golden Snitch' in https://gocheckyourself.org/text/golden-snitch-experts.txt",
 "instructions_for_assistants": "Run these steps yourself, in a fresh empty folder, with the person's permission, and report the real output next to the expected output. Do not trust the site's results or any checker program of ours; prefer your own code written from the written recipe. A step whose output differs is a failed step: say so. Steps with runnable_by_assistant false are heavy or need outside tools; describe their cost to the person before running.",
 "known_gaps": [
  "Recipes 2 to 6 (closed form against direct integration, the corner, curve length, the chase, the stretching identity) need your own numerical code (an ODE integrator and a bisection). There is no copy-paste script here for them; the chapter gives the formulas, the inputs and the expected numbers. Pure Python is enough: our own re-run of all six recipes took about 10 seconds with 16 cores.",
  "The results file entries sawtooth_algebra and chase_graded_start are not reproducible from the written recipe alone (the recipe does not give the graded start layout)."
 ],
 "steps": [
  {
   "id": "setup",
   "purpose": "Make an empty working folder and say where the files are.",
   "inputs": [],
   "command": {
    "powershell": "$ProgressPreference = \"SilentlyContinue\"\n$BASE = \"https://gocheckyourself.org/data/files/golden-snitch\"\nNew-Item -ItemType Directory -Force check-golden-snitch | Out-Null\nSet-Location check-golden-snitch",
    "bash": "BASE=\"https://gocheckyourself.org/data/files/golden-snitch\"\nmkdir -p check-golden-snitch && cd check-golden-snitch"
   },
   "expected_output": "No output.",
   "does_not_show": "Nothing; this just makes a folder.",
   "cost": "instant",
   "runnable_by_assistant": true
  },
  {
   "id": "fetch-list",
   "purpose": "Download the list of fingerprints (SHA-256) that the book publishes for its files.",
   "inputs": [
    {
     "path": "certificates/SHA256SUMS.txt",
     "sha256": "f150949b9008cdcda7e4dc8e499993005140c65a07b2ad0d4236d46def21f5f7"
    }
   ],
   "command": {
    "powershell": "New-Item -ItemType Directory -Force certificates | Out-Null\nInvoke-WebRequest -UseBasicParsing -UserAgent \"Mozilla/5.0\" \"$BASE/certificates/SHA256SUMS.txt\" -OutFile certificates/SHA256SUMS.txt\nSet-Location certificates",
    "bash": "mkdir -p certificates\ncurl -fsSL \"$BASE/certificates/SHA256SUMS.txt\" -o certificates/SHA256SUMS.txt\ncd certificates"
   },
   "expected_output": "No output. The file certificates/SHA256SUMS.txt exists. Each line is 64 hex digits, a space, an optional star, and a file path.",
   "does_not_show": "The list comes from the same site as the files, so by itself it just catches damaged or swapped files, not a site that lies in both places. Compare the list's own SHA-256 (see inputs) with a copy you trust, such as one a friend keeps, or one kept anywhere other than this site.",
   "cost": "instant",
   "runnable_by_assistant": true
  },
  {
   "id": "fetch-files",
   "purpose": "Download the one certificate file, results.json.",
   "inputs": [
    {
     "path": "certificates/results.json",
     "sha256": "930b36406c03aedc4045cf9d6fe8253fd680c778412a19ddcb124781793816ad"
    }
   ],
   "command": {
    "powershell": "Invoke-WebRequest -UseBasicParsing -UserAgent \"Mozilla/5.0\" \"$BASE/certificates/results.json\" -OutFile results.json",
    "bash": "curl -fsSL \"$BASE/certificates/results.json\" -o results.json"
   },
   "expected_output": "No output.",
   "does_not_show": "See the hash step.",
   "cost": "instant",
   "runnable_by_assistant": true
  },
  {
   "id": "hash-check",
   "purpose": "Compare the SHA-256 fingerprint of every downloaded file with the published list.",
   "inputs": [
    {
     "path": "certificates/SHA256SUMS.txt",
     "sha256": "f150949b9008cdcda7e4dc8e499993005140c65a07b2ad0d4236d46def21f5f7"
    }
   ],
   "command": {
    "powershell": "$ok = 0; $bad = 0\nGet-Content SHA256SUMS.txt | Where-Object { $_.Trim() } | ForEach-Object {\n  $h = $_.Substring(0,64).ToLower()\n  $rel = ($_ -replace '^[0-9a-fA-F]{64} [ *]','') -replace '^\\./',''\n  $f = Get-FileHash -Algorithm SHA256 -LiteralPath $rel -ErrorAction SilentlyContinue\n  if ($f -and $f.Hash.ToLower() -eq $h) { $ok++ } else { $bad++; \"NOT OK: $rel\" }\n}\n\"$ok OK, $bad not OK\"",
    "bash": "# Linux: sha256sum.  macOS: use \"shasum -a 256 -c\" instead of \"sha256sum -c\".\nif command -v sha256sum >/dev/null; then C=\"sha256sum -c\"; else C=\"shasum -a 256 -c\"; fi\n$C SHA256SUMS.txt 2>&1 | grep -v \": OK$\" ; echo \"$($C SHA256SUMS.txt 2>/dev/null | grep -c \": OK$\") OK\""
   },
   "expected_output": "PowerShell prints a line \"1 OK, 0 not OK\". bash prints every line that is not OK, then \"1 OK\".",
   "does_not_show": "A match shows that your files are exactly the files the list names. What the files say is tested by the other steps of this recipe. ",
   "cost": "seconds",
   "runnable_by_assistant": true
  },
  {
   "id": "recipe-1",
   "purpose": "Recipe 1: the spiral time, the closed formula against the equation it solves.",
   "inputs": [],
   "command": {
    "powershell": "@'\n# Golden Snitch, recipe 1: the spiral time, formula against the equation. d = v = 1, V = alpha.\nimport math\nfor alpha in (1.25, 1.5, 2, 3, 5, 7):\n    formula = alpha / (alpha - 1) * math.exp(2 * math.pi / math.sqrt(alpha**2 - 1)) - 1\n    # solve sqrt(alpha^2-1) * ln((1+T)/(1+1/(alpha-1))) = 2 pi by bisection\n    lo, hi = 0.0, 1e9\n    for _ in range(300):\n        mid = (lo + hi) / 2\n        if math.sqrt(alpha**2 - 1) * math.log((1 + mid) / (1 + 1 / (alpha - 1))) < 2 * math.pi\u003a\n            lo = mid\n        else\u003a\n            hi = mid\n    print(\"alpha=%-4s formula %.4f   equation %.4f   relative difference %.1e\" % (alpha, formula, lo, abs(formula - lo) / formula))\n'@ | Set-Content -Encoding utf8 golden_recipe1_spiral_time.py\npython golden_recipe1_spiral_time.py",
    "bash": "cat > golden_recipe1_spiral_time.py <<'EOF'\n# Golden Snitch, recipe 1: the spiral time, formula against the equation. d = v = 1, V = alpha.\nimport math\nfor alpha in (1.25, 1.5, 2, 3, 5, 7):\n    formula = alpha / (alpha - 1) * math.exp(2 * math.pi / math.sqrt(alpha**2 - 1)) - 1\n    # solve sqrt(alpha^2-1) * ln((1+T)/(1+1/(alpha-1))) = 2 pi by bisection\n    lo, hi = 0.0, 1e9\n    for _ in range(300):\n        mid = (lo + hi) / 2\n        if math.sqrt(alpha**2 - 1) * math.log((1 + mid) / (1 + 1 / (alpha - 1))) < 2 * math.pi\u003a\n            lo = mid\n        else\u003a\n            hi = mid\n    print(\"alpha=%-4s formula %.4f   equation %.4f   relative difference %.1e\" % (alpha, formula, lo, abs(formula - lo) / formula))\nEOF\npython3 golden_recipe1_spiral_time.py"
   },
   "expected_output": "T = 21741.3733, 826.5455, 74.2447, 12.8309, 3.5073, 1.8894 for alpha 1.25, 1.5, 2, 3, 5, 7 (formula and equation columns agree; relative difference about 1e-15)",
   "does_not_show": "It shows the formula is the right integral of the turn. It does not show the spiral answers the riddle, whose Snitch flees from Harry's current position.",
   "cost": "instant",
   "runnable_by_assistant": true,
   "script_file": "golden_recipe1_spiral_time.py"
  },
  {
   "id": "recipe-2-to-6",
   "purpose": "Recipes 2 to 6: closed form against direct integration, the corner, the length of the curve, the chase of sample Snitches, the stretching identity.",
   "inputs": [
    {
     "path": "certificates/results.json",
     "sha256": "930b36406c03aedc4045cf9d6fe8253fd680c778412a19ddcb124781793816ad"
    }
   ],
   "command": {
    "any": "No copy-paste script yet. Write it yourself from the written recipe\u003a\nChapter headings 'Recipe 2' to 'Recipe 6'. Needs your own ODE integrator and bisection (the standard library is enough)."
   },
   "expected_output": "Recipe 2: (0.33617353, 1.74108756), r = 2.4082576, theta = 2.3335073. Recipe 3 at alpha = 2: C = 2.14913986, cos theta = -0.50000000023. Recipe 4: 11.7249 (circle 12.5664) at alpha 2. Recipe 5, N = 180: 22.5334, 7.0694, 2.6143, 1.5549 at alpha 2, 3, 5, 7, and no finish at 1.25 and 1.5. Recipe 6: relative error at most 3.7e-5.",
   "does_not_show": "Each recipe lists what its pass does not show (for example, that every Snitch is caught).",
   "cost": "seconds each; recipe 5 at N = 1440 under a minute per speed ratio",
   "runnable_by_assistant": false
  },
  {
   "id": "one-byte-change",
   "purpose": "See for yourself that a one-byte change is caught: change one byte in a copy of results.json and look at the fingerprint.",
   "inputs": [
    {
     "path": "certificates/results.json",
     "sha256": "930b36406c03aedc4045cf9d6fe8253fd680c778412a19ddcb124781793816ad",
     "local": "results.json"
    }
   ],
   "command": {
    "powershell": "python -c \"b=bytearray(open('results.json','rb').read()); b[0]^=1; open('tampered.copy','wb').write(b)\"\n\"published : 930b36406c03aedc4045cf9d6fe8253fd680c778412a19ddcb124781793816ad\"\n\"your copy : \" + (Get-FileHash -Algorithm SHA256 tampered.copy).Hash.ToLower()",
    "bash": "python3 -c \"b=bytearray(open('results.json','rb').read()); b[0]^=1; open('tampered.copy','wb').write(b)\"\necho \"published : 930b36406c03aedc4045cf9d6fe8253fd680c778412a19ddcb124781793816ad\"\necho \"your copy : $( (sha256sum tampered.copy 2>/dev/null || shasum -a 256 tampered.copy) | cut -c1-64 )\""
   },
   "expected_output": "Two different 64-digit values; the 'published' value ends 793816ad and your copy's value is different.",
   "does_not_show": "It shows the fingerprint step would notice that change. It says nothing about the file you did not change.",
   "cost": "instant",
   "runnable_by_assistant": true
  }
 ]
}