{
  "schemaVersion": 1,
  "slug": "carpet-calculator",
  "category": "construction",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "5f88cfbc2b81c51a807e96f2b440db5a69dfd46c157f635aae4985646c094049",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/carpet-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": "Total = L × W × (1 + w ÷ 100) ÷ 9 × (p + p_pad)",
    "vars": [
      [
        "L",
        "Room length (ft)"
      ],
      [
        "W",
        "Room width (ft)"
      ],
      [
        "w",
        "Waste allowance (%)"
      ],
      [
        "p",
        "Carpet price per sq yd"
      ],
      [
        "p_pad",
        "Padding price per sq yd"
      ],
      [
        "Total",
        "Total carpet cost"
      ]
    ],
    "note": "Room area = length × width. Estimate the shorter carpet roll run in either room orientation; purchased carpet area = roll width × roll run × (1 + waste%). Carpet and padding costs use the estimated purchase area. Layout details such as stairs, doorways and pattern matching are not modeled."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "if(length<=0||width<=0||rollWidth<=0)return{areaSqft:null,areaSqyd:null,carpetCost:null,paddingCost:null,totalCost:null,__error:'inputError'};const roomArea=length*width;const lengthIfWidthRunsWithRoll=length*Math.ceil(width/rollWidth);const lengthIfLengthRunsWithRoll=width*Math.ceil(length/rollWidth);const purchasedRun=Math.min(lengthIfWidthRunsWithRoll,lengthIfLengthRunsWithRoll);const purchasedSqft=rollWidth*purchasedRun*(1+waste/100);const areaSqyd=purchasedSqft/9;return{areaSqft:roomArea,areaSqyd,carpetCost:areaSqyd*pricePerSqyd,paddingCost:areaSqyd*paddingPrice,totalCost:areaSqyd*(pricePerSqyd+paddingPrice)};",
    "inputs": [
      {
        "name": "length",
        "type": "number",
        "default": 15,
        "min": 0,
        "max": 500,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "width",
        "type": "number",
        "default": 12,
        "min": 0,
        "max": 500,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "waste",
        "type": "number",
        "default": 10,
        "min": 0,
        "max": 30,
        "step": 1,
        "slider": true
      },
      {
        "name": "rollWidth",
        "type": "number",
        "default": 12,
        "min": 6,
        "max": 20,
        "step": 1,
        "slider": true
      },
      {
        "name": "pricePerSqyd",
        "type": "number",
        "default": 22,
        "min": 0,
        "max": 300,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "paddingPrice",
        "type": "number",
        "default": 5,
        "min": 0,
        "max": 100,
        "step": 0.5,
        "slider": true
      }
    ],
    "outputs": [
      {
        "name": "areaSqft",
        "precision": 1,
        "unit": "sq ft"
      },
      {
        "name": "areaSqyd",
        "precision": 2,
        "unit": "sq yd"
      },
      {
        "name": "carpetCost",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "paddingCost",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "totalCost",
        "precision": 2,
        "unit": "$"
      }
    ],
    "interpret": null
  }
}
