# Check it yourself: The Invisible Golden Snitch

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. Why a recipe and not our program: https://gocheckyourself.org/how-to-check/

You do not have to trust our results or our programs. This page tells you, step by step, how to check the published files with tools you already have. The full written recipe is the chapter 'Verify: The Invisible Golden Snitch' in https://gocheckyourself.org/text/golden-snitch-experts.txt.

Steps 1 to 5, 7 have the command for Windows PowerShell and for macOS or Linux (bash), the output you should see, and a plain sentence on what a match means and what it does not. Steps 6 have no copy-paste script yet: each names the recipe to write yourself and the output to expect. If your output is different, the step has failed; do not skip it.

You need: a command line, and Python 3.8 or later (python on Windows, python3 on macOS or Linux) for the steps that run a script. Windows PowerShell 5.1 or later (pwsh also works). Scripts are short; read them before you run them.

## What is known not to work today

- 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).

## Step 1: Make an empty working folder and say where the files are.

Windows PowerShell:

```powershell
$ProgressPreference = "SilentlyContinue"
$BASE = "https://gocheckyourself.org/data/files/golden-snitch"
New-Item -ItemType Directory -Force check-golden-snitch | Out-Null
Set-Location check-golden-snitch
```

macOS or Linux (bash):

```bash
BASE="https://gocheckyourself.org/data/files/golden-snitch"
mkdir -p check-golden-snitch && cd check-golden-snitch
```

You should see:

```
No output.
```

What a match shows, and what it does not: Nothing; this just makes a folder.

Cost: instant.

## Step 2: Download the list of fingerprints (SHA-256) that the book publishes for its files.

Files used (SHA-256):
- https://gocheckyourself.org/data/files/golden-snitch/certificates/SHA256SUMS.txt  f150949b9008cdcda7e4dc8e499993005140c65a07b2ad0d4236d46def21f5f7

Windows PowerShell:

```powershell
New-Item -ItemType Directory -Force certificates | Out-Null
Invoke-WebRequest -UseBasicParsing -UserAgent "Mozilla/5.0" "$BASE/certificates/SHA256SUMS.txt" -OutFile certificates/SHA256SUMS.txt
Set-Location certificates
```

macOS or Linux (bash):

```bash
mkdir -p certificates
curl -fsSL "$BASE/certificates/SHA256SUMS.txt" -o certificates/SHA256SUMS.txt
cd certificates
```

You should see:

```
No output. The file certificates/SHA256SUMS.txt exists. Each line is 64 hex digits, a space, an optional star, and a file path.
```

What a match shows, and what it does not: 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.

## Step 3: Download the one certificate file, results.json.

Files used (SHA-256):
- https://gocheckyourself.org/data/files/golden-snitch/certificates/results.json  930b36406c03aedc4045cf9d6fe8253fd680c778412a19ddcb124781793816ad

Windows PowerShell:

```powershell
Invoke-WebRequest -UseBasicParsing -UserAgent "Mozilla/5.0" "$BASE/certificates/results.json" -OutFile results.json
```

macOS or Linux (bash):

```bash
curl -fsSL "$BASE/certificates/results.json" -o results.json
```

You should see:

```
No output.
```

What a match shows, and what it does not: See the hash step.

Cost: instant.

## Step 4: Compare the SHA-256 fingerprint of every downloaded file with the published list.

Files used (SHA-256):
- https://gocheckyourself.org/data/files/golden-snitch/certificates/SHA256SUMS.txt  f150949b9008cdcda7e4dc8e499993005140c65a07b2ad0d4236d46def21f5f7

Windows PowerShell:

```powershell
$ok = 0; $bad = 0
Get-Content SHA256SUMS.txt | Where-Object { $_.Trim() } | ForEach-Object {
  $h = $_.Substring(0,64).ToLower()
  $rel = ($_ -replace '^[0-9a-fA-F]{64} [ *]','') -replace '^\./',''
  $f = Get-FileHash -Algorithm SHA256 -LiteralPath $rel -ErrorAction SilentlyContinue
  if ($f -and $f.Hash.ToLower() -eq $h) { $ok++ } else { $bad++; "NOT OK: $rel" }
}
"$ok OK, $bad not OK"
```

macOS or Linux (bash):

```bash
# Linux: sha256sum.  macOS: use "shasum -a 256 -c" instead of "sha256sum -c".
if command -v sha256sum >/dev/null; then C="sha256sum -c"; else C="shasum -a 256 -c"; fi
$C SHA256SUMS.txt 2>&1 | grep -v ": OK$" ; echo "$($C SHA256SUMS.txt 2>/dev/null | grep -c ": OK$") OK"
```

You should see:

```
PowerShell prints a line "1 OK, 0 not OK". bash prints every line that is not OK, then "1 OK".
```

What a match shows, and what it does not: 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.

## Step 5: Recipe 1: the spiral time, the closed formula against the equation it solves.

Windows PowerShell:

```powershell
@'
# Golden Snitch, recipe 1: the spiral time, formula against the equation. d = v = 1, V = alpha.
import math
for alpha in (1.25, 1.5, 2, 3, 5, 7):
    formula = alpha / (alpha - 1) * math.exp(2 * math.pi / math.sqrt(alpha**2 - 1)) - 1
    # solve sqrt(alpha^2-1) * ln((1+T)/(1+1/(alpha-1))) = 2 pi by bisection
    lo, hi = 0.0, 1e9
    for _ in range(300):
        mid = (lo + hi) / 2
        if math.sqrt(alpha**2 - 1) * math.log((1 + mid) / (1 + 1 / (alpha - 1))) < 2 * math.pi:
            lo = mid
        else:
            hi = mid
    print("alpha=%-4s formula %.4f   equation %.4f   relative difference %.1e" % (alpha, formula, lo, abs(formula - lo) / formula))
'@ | Set-Content -Encoding utf8 golden_recipe1_spiral_time.py
python golden_recipe1_spiral_time.py
```

macOS or Linux (bash):

```bash
cat > golden_recipe1_spiral_time.py <<'EOF'
# Golden Snitch, recipe 1: the spiral time, formula against the equation. d = v = 1, V = alpha.
import math
for alpha in (1.25, 1.5, 2, 3, 5, 7):
    formula = alpha / (alpha - 1) * math.exp(2 * math.pi / math.sqrt(alpha**2 - 1)) - 1
    # solve sqrt(alpha^2-1) * ln((1+T)/(1+1/(alpha-1))) = 2 pi by bisection
    lo, hi = 0.0, 1e9
    for _ in range(300):
        mid = (lo + hi) / 2
        if math.sqrt(alpha**2 - 1) * math.log((1 + mid) / (1 + 1 / (alpha - 1))) < 2 * math.pi:
            lo = mid
        else:
            hi = mid
    print("alpha=%-4s formula %.4f   equation %.4f   relative difference %.1e" % (alpha, formula, lo, abs(formula - lo) / formula))
EOF
python3 golden_recipe1_spiral_time.py
```

You should see:

```
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)
```

What a match shows, and what it does not: 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.

## Step 6: Recipes 2 to 6: closed form against direct integration, the corner, the length of the curve, the chase of sample Snitches, the stretching identity.

Files used (SHA-256):
- https://gocheckyourself.org/data/files/golden-snitch/certificates/results.json  930b36406c03aedc4045cf9d6fe8253fd680c778412a19ddcb124781793816ad

Commands (same on both platforms; not run by us unless stated):

```
No copy-paste script yet. Write it yourself from the written recipe:
Chapter headings 'Recipe 2' to 'Recipe 6'. Needs your own ODE integrator and bisection (the standard library is enough).
```

You should see:

```
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.
```

What a match shows, and what it does not: 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.

## Step 7: See for yourself that a one-byte change is caught: change one byte in a copy of results.json and look at the fingerprint.

Files used (SHA-256):
- https://gocheckyourself.org/data/files/golden-snitch/certificates/results.json  930b36406c03aedc4045cf9d6fe8253fd680c778412a19ddcb124781793816ad

Windows PowerShell:

```powershell
python -c "b=bytearray(open('results.json','rb').read()); b[0]^=1; open('tampered.copy','wb').write(b)"
"published : 930b36406c03aedc4045cf9d6fe8253fd680c778412a19ddcb124781793816ad"
"your copy : " + (Get-FileHash -Algorithm SHA256 tampered.copy).Hash.ToLower()
```

macOS or Linux (bash):

```bash
python3 -c "b=bytearray(open('results.json','rb').read()); b[0]^=1; open('tampered.copy','wb').write(b)"
echo "published : 930b36406c03aedc4045cf9d6fe8253fd680c778412a19ddcb124781793816ad"
echo "your copy : $( (sha256sum tampered.copy 2>/dev/null || shasum -a 256 tampered.copy) | cut -c1-64 )"
```

You should see:

```
Two different 64-digit values; the 'published' value ends 793816ad and your copy's value is different.
```

What a match shows, and what it does not: It shows the fingerprint step would notice that change. It says nothing about the file you did not change.

Cost: instant.

