{
  "schemaVersion": 1,
  "slug": "bulk-vs-single-price-calculator",
  "category": "shopping",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "4d5bac34581cd0a04f582b3fbb7c103719b51fc6b51d8c7df3742bc81609e406",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/bulk-vs-single-price-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": "N = B/S; G = N·S − B; W = N·S·w; Net = N·S·(1−w) − B − C",
    "vars": [
      [
        "u_b",
        "Bulk unit price"
      ],
      [
        "u_s",
        "Single-unit price"
      ],
      [
        "P_b",
        "Bulk pack price"
      ],
      [
        "S_b",
        "Bulk pack size"
      ],
      [
        "P_s",
        "Single unit price"
      ],
      [
        "S_s",
        "Single unit size"
      ],
      [
        "G",
        "Gross saving before waste and storage costs"
      ]
    ],
    "note": "N is the bulk quantity converted to single-pack equivalents; w is the waste fraction and C is storage cost. Net savings subtract the value of wasted usable quantity once, plus storage cost."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const bulkUnitPrice = bulkSize > 0 ? bulkPrice/bulkSize : 0; const singleUnitPrice = singleSize > 0 ? singlePrice/singleSize : 0; const unitsPerBulk = singleSize > 0 ? bulkSize/singleSize : 0; const equivalentSingles = unitsPerBulk*singlePrice; const grossSaving = equivalentSingles-bulkPrice; const monthsOfSupply = monthlyUsage > 0 ? bulkSize/monthlyUsage : 0; const netSaving = grossSaving-equivalentSingles*wastePercent/100-storageCost; const verdict = netSaving > 0 && monthsOfSupply < 12 ? 'Buying in bulk saves about $'+netSaving.toFixed(2) : netSaving > 0 ? 'Saves money, but one pack is over a year of supply — check shelf life' : 'Not worth it once waste and storage are counted'; return { bulkUnitPrice, singleUnitPrice, unitsPerBulk, monthsOfSupply, grossSaving, netSaving, verdict };",
    "inputs": [
      {
        "name": "bulkPrice",
        "type": "number",
        "default": 24.99,
        "min": 0,
        "max": 100000,
        "step": 0.01
      },
      {
        "name": "bulkSize",
        "type": "number",
        "default": 2000,
        "min": 0.001,
        "max": 1000000,
        "step": 0.001
      },
      {
        "name": "singlePrice",
        "type": "number",
        "default": 3.49,
        "min": 0,
        "max": 100000,
        "step": 0.01
      },
      {
        "name": "singleSize",
        "type": "number",
        "default": 250,
        "min": 0.001,
        "max": 1000000,
        "step": 0.001
      },
      {
        "name": "monthlyUsage",
        "type": "number",
        "default": 300,
        "min": 0.001,
        "max": 1000000,
        "step": 0.001
      },
      {
        "name": "wastePercent",
        "type": "number",
        "default": 5,
        "min": 0,
        "max": 60,
        "step": 1,
        "slider": true
      },
      {
        "name": "storageCost",
        "type": "number",
        "default": 0,
        "min": 0,
        "max": 10000,
        "step": 1
      }
    ],
    "outputs": [
      {
        "name": "bulkUnitPrice",
        "precision": 5,
        "unit": "$"
      },
      {
        "name": "singleUnitPrice",
        "precision": 5,
        "unit": "$"
      },
      {
        "name": "unitsPerBulk",
        "precision": 2,
        "unit": ""
      },
      {
        "name": "monthsOfSupply",
        "precision": 1,
        "unit": "months"
      },
      {
        "name": "grossSaving",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "netSaving",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "verdict",
        "precision": 0,
        "unit": "",
        "type": "text"
      }
    ],
    "interpret": null
  }
}
