{
  "schemaVersion": 1,
  "slug": "fuel-cost-calculator",
  "category": "automotive",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "c43563f4c8cb409625728533047f01f045d5cf5d9b6a0ef00aa685ff55414289",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/fuel-cost-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": "D = d x k; gal = D / mpg; L = gal x 3.785411784; C = gal x p; perMile = C / D",
    "vars": [
      [
        "d",
        "one-way distance (miles)"
      ],
      [
        "k",
        "trip factor: 1 or 2"
      ],
      [
        "D",
        "total distance"
      ],
      [
        "mpg",
        "fuel economy (US mpg)"
      ],
      [
        "p",
        "fuel price per gallon"
      ],
      [
        "C",
        "total fuel cost"
      ]
    ],
    "note": "k = 2 for a round trip. Gallons are US gallons (1 US gal = 3.785411784 L); fuel use and cost are 0 when mpg = 0."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const totalDistance = distance*(roundTrip === 'yes' ? 2 : 1); const gallonsUsed = mpg > 0 ? totalDistance/mpg : 0; const totalCost = gallonsUsed*fuelPrice; return { totalDistance, gallonsUsed, litresUsed: gallonsUsed*3.785411784, totalCost, costPerMile: totalDistance > 0 ? totalCost/totalDistance : 0 };",
    "inputs": [
      {
        "name": "distance",
        "type": "number",
        "default": 300,
        "min": 0,
        "max": 20000,
        "step": 1
      },
      {
        "name": "mpg",
        "type": "number",
        "default": 30,
        "min": 1,
        "max": 200,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "fuelPrice",
        "type": "number",
        "default": 3.5,
        "min": 0,
        "max": 30,
        "step": 0.01,
        "slider": true
      },
      {
        "name": "roundTrip",
        "type": "select",
        "default": "no",
        "options": [
          {
            "value": "no"
          },
          {
            "value": "yes"
          }
        ]
      }
    ],
    "outputs": [
      {
        "name": "totalCost",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "totalDistance",
        "precision": 0,
        "unit": "mi"
      },
      {
        "name": "gallonsUsed",
        "precision": 2,
        "unit": "gal"
      },
      {
        "name": "litresUsed",
        "precision": 2,
        "unit": "L"
      },
      {
        "name": "costPerMile",
        "precision": 3,
        "unit": "$"
      }
    ],
    "interpret": null
  }
}
