{
  "schemaVersion": 1,
  "slug": "gas-trip-calculator",
  "category": "travel",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "550290a2bfe9e03b8ca52f6e0cbce185b5048777fdcbfe33d97315777214c5f6",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/gas-trip-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 × k × (1 + b/100); gal = D/mpg; C = gal × p; perPerson = C/n_p; refuels = max(0, ceil(gal/T) − 1)",
    "vars": [
      [
        "d",
        "One-way distance (mi)"
      ],
      [
        "k",
        "Trip factor (1 or 2)"
      ],
      [
        "b",
        "User-chosen extra-distance percentage"
      ],
      [
        "mpg",
        "US miles per gallon"
      ],
      [
        "p",
        "US dollars per gallon"
      ],
      [
        "T",
        "Tank size (US gal)"
      ],
      [
        "n_p",
        "Passengers splitting the cost"
      ],
      [
        "C",
        "Total fuel cost (USD)"
      ]
    ],
    "note": "The buffer is an editable scenario input, not a guarantee. Stops assume departure with a full tank and full refills; ceil(gal/T) − 1 estimates stops after the initial tank. Cost per person splits the total equally across entered passengers."
  },
  "externalEvidence": {
    "reviewedAt": "2026-09-28",
    "sources": [
      {
        "name": "U.S. Energy Information Administration — Retail gasoline prices",
        "url": "https://www.eia.gov/dnav/pet/pet_pri_gnd_a_epm0_pte_dpgal_w.htm"
      },
      {
        "name": "NIST — Fuel economy conversion factors",
        "url": "https://www.nist.gov/pml/special-publication-811/nist-guide-si-appendix-b-conversion-factors"
      }
    ]
  },
  "contract": {
    "compute": "const totalDistance = distance*(roundTrip === 'yes' ? 2 : 1)*(1+buffer/100); const gallons = mpg > 0 ? totalDistance/mpg : 0; const totalCost = gallons*fuelPrice; return { totalDistance, gallons, totalCost, costPerPerson: totalCost/passengers, refuels: tankSize > 0 ? Math.max(0, Math.ceil(gallons/tankSize)-1) : 0, costPerMile: totalDistance > 0 ? totalCost/totalDistance : 0 };",
    "inputs": [
      {
        "name": "distance",
        "type": "number",
        "default": 450,
        "min": 1,
        "max": 20000,
        "step": 5,
        "slider": true
      },
      {
        "name": "mpg",
        "type": "number",
        "default": 28,
        "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": "yes",
        "options": [
          {
            "value": "no"
          },
          {
            "value": "yes"
          }
        ]
      },
      {
        "name": "buffer",
        "type": "number",
        "default": 10,
        "min": 0,
        "max": 30,
        "step": 1,
        "slider": true
      },
      {
        "name": "tankSize",
        "type": "number",
        "default": 15,
        "min": 1,
        "max": 200,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "passengers",
        "type": "number",
        "default": 2,
        "min": 1,
        "max": 12,
        "step": 1,
        "slider": true
      }
    ],
    "outputs": [
      {
        "name": "totalDistance",
        "precision": 0,
        "unit": "mi"
      },
      {
        "name": "gallons",
        "precision": 2,
        "unit": "gal"
      },
      {
        "name": "totalCost",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "costPerPerson",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "refuels",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "costPerMile",
        "precision": 3,
        "unit": "$"
      }
    ],
    "interpret": null
  }
}
