{
  "schemaVersion": 1,
  "slug": "sleep-calculator",
  "category": "health",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "da17e2098c4ef3f25e7e63f6e827605319f339c6565c54162fa48cf53b11a765",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/sleep-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "B_n = [W − (90n + t)] mod 1440, n = 3…6",
    "vars": [
      [
        "W",
        "Wake time (minutes of the day)"
      ],
      [
        "n",
        "Number of 90-min cycles"
      ],
      [
        "t",
        "Minutes to fall asleep"
      ],
      [
        "B_n",
        "Suggested bedtime (minutes)"
      ]
    ],
    "note": "Each cycle is 90 minutes; the value wraps modulo 1440 and is shown as HH:MM; five cycles give 7.5 h of sleep."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const pad=(n)=>String(n).padStart(2,'0'); const bed=(cycles)=>{ let m = wakeHour*60+wakeMinute - (cycles*90 + fallAsleep); m = ((m%1440)+1440)%1440; return pad(Math.floor(m/60))+':'+pad(m%60); }; return { sixCycles: bed(6), fiveCycles: bed(5), fourCycles: bed(4), threeCycles: bed(3) };",
    "inputs": [
      {
        "name": "wakeHour",
        "type": "number",
        "default": 7,
        "min": 0,
        "max": 23,
        "step": 1,
        "slider": true
      },
      {
        "name": "wakeMinute",
        "type": "number",
        "default": 0,
        "min": 0,
        "max": 59,
        "step": 1,
        "slider": true
      },
      {
        "name": "fallAsleep",
        "type": "number",
        "default": 15,
        "min": 0,
        "max": 120,
        "step": 1,
        "slider": true
      }
    ],
    "outputs": [
      {
        "name": "sixCycles",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "fiveCycles",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "fourCycles",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "threeCycles",
        "precision": 0,
        "unit": "",
        "type": "text"
      }
    ],
    "interpret": null
  }
}
