{
  "id": "combination",
  "version": "1dbc56b30e2e",
  "status": "published",
  "name": "Combination Calculator",
  "question": "How many combinations?",
  "summary": "Computes the number of combinations (nCr) of r items chosen from n, with or without repetition, and the matching number of permutations (nPr), exactly.",
  "category": "statistics",
  "subcategory": "probability",
  "url": "https://www.acalculator.org/statistics/combination-calculator",
  "markdown": "https://www.acalculator.org/statistics/combination-calculator.md",
  "kind": "function",
  "method": "Without repetition: C(n, r) = n! ÷ (r! (n − r)!) and P(n, r) = n! ÷ (n − r)!. With repetition: C(n + r − 1, r) and n^r.",
  "assumptions": [
    "The n items are all different from each other.",
    "Without repetition, choosing more items than there are (r > n) gives 0 combinations and 0 permutations.",
    "Results are exact whole numbers, however many digits they have."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "n": {
        "title": "Items to choose from (n)",
        "description": "How many different items there are to choose from.",
        "type": "integer",
        "minimum": 1,
        "maximum": 1000
      },
      "r": {
        "title": "Items chosen (r)",
        "description": "How many items are chosen each time.",
        "type": "integer",
        "minimum": 0,
        "maximum": 1000
      },
      "rep": {
        "title": "Can an item be chosen more than once?",
        "description": "No: each item at most once (the usual nCr). Yes: an item may be picked again.",
        "type": "string",
        "enum": [
          "no",
          "yes"
        ]
      }
    }
  },
  "outputs": {
    "combinations": {
      "label": "Combinations",
      "description": "The number of ways to choose r items from n when the order does not matter.",
      "format": "integer"
    },
    "permutations": {
      "label": "Permutations (order matters)",
      "description": "The number of ways to choose r items from n when the order does matter.",
      "format": "integer"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "n": 52,
      "r": 5,
      "rep": "no"
    },
    "outputs": {
      "combinations": "2598960",
      "permutations": "311875200"
    },
    "text": "There are 2,598,960 ways to choose 5 items from 52 when order does not matter."
  },
  "examples": [
    {
      "given": {
        "n": 52,
        "r": 5,
        "rep": "no"
      },
      "expect": {
        "combinations": 2598960,
        "permutations": 311875200
      },
      "source": "hand calculation in content.mdx: 52 × 51 × 50 × 49 × 48 ÷ 120 = 2,598,960 (DLMF 26.3.1); Python math.comb(52, 5) and math.perm(52, 5)"
    },
    {
      "given": {
        "n": 49,
        "r": 6,
        "rep": "no"
      },
      "expect": {
        "combinations": 13983816
      },
      "source": "hand calculation in content.mdx: 49 × 48 × 47 × 46 × 45 × 44 ÷ 720 = 13,983,816; Python math.comb(49, 6)"
    },
    {
      "given": {
        "n": 5,
        "r": 3,
        "rep": "yes"
      },
      "expect": {
        "combinations": 35,
        "permutations": 125
      },
      "source": "hand calculation in content.mdx: C(5 + 3 − 1, 3) = C(7, 3) = 35; 5³ = 125"
    },
    {
      "given": {
        "n": 5,
        "r": 7,
        "rep": "no"
      },
      "expect": {
        "combinations": 0,
        "permutations": 0
      },
      "source": "DLMF 26.3.2: C(m, n) = 0 when n > m; Python math.comb(5, 7) and math.perm(5, 7) are 0"
    },
    {
      "given": {
        "n": 10,
        "r": 0,
        "rep": "no"
      },
      "expect": {
        "combinations": 1,
        "permutations": 1
      },
      "source": "DLMF 26.3.1: C(10, 0) = 10! ÷ (10! 0!) = 1; choosing nothing can be done one way"
    }
  ],
  "sources": [
    "NIST Digital Library of Mathematical Functions, §26.3 Lattice Paths: Binomial Coefficients, equations 26.3.1 and 26.3.2. https://dlmf.nist.gov/26.3"
  ],
  "related": [
    "z-score",
    "average"
  ],
  "changelog": []
}
