{
  "schemaVersion": 1,
  "slug": "birthday-probability-calculator",
  "category": "fun",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "01a54e7680f77dea7997fb1fd43dd5cef59da41c226786f9ea245833cb220bfa",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/birthday-probability-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": "P = 1 − Π_{i=0}^{n−1} (d−i)/d",
    "vars": [
      [
        "n",
        "Number of people"
      ],
      [
        "d",
        "Possible birthdays in the year"
      ],
      [
        "P",
        "Probability of at least one shared birthday"
      ]
    ],
    "note": "n is capped at 500 and d at 366; possible pairs = n(n−1)/2; peopleFor50 iterates multiplying by (d−k)/d until the no-match product first drops to ≤0.5."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const n=Math.min(500,Math.max(1,Math.round(people))),d=Math.min(366,Math.max(2,Math.round(days)));let p=1;for(let i=0;i<n;i++)p*=Math.max(0,(d-i)/d);const match=1-p,pairs=n*(n-1)/2,odds=match>0?p/match:0;let fifty=1,pp=1;while(pp>0.5&&fifty<d){pp*=(d-fifty)/d;fifty++}return{probability:match*100,noMatch:p*100,pairs,oddsAgainst:match>0?Math.round(odds)+' to 1':'no chance',peopleFor50:fifty};",
    "inputs": [
      {
        "name": "people",
        "type": "number",
        "default": 23,
        "min": 1,
        "max": 500,
        "step": 1,
        "slider": true
      },
      {
        "name": "days",
        "type": "number",
        "default": 365,
        "min": 2,
        "max": 366,
        "step": 1,
        "slider": true
      }
    ],
    "outputs": [
      {
        "name": "probability",
        "precision": 2,
        "unit": "%"
      },
      {
        "name": "noMatch",
        "precision": 2,
        "unit": "%"
      },
      {
        "name": "pairs",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "oddsAgainst",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "peopleFor50",
        "precision": 0,
        "unit": ""
      }
    ],
    "interpret": null
  }
}
