"""Lab to Code — Why the grid runs at high voltage, and how much CO2 one kWh costs.

1) Line loss: the same power P = V * I at a higher voltage needs less current, and the loss is I^2 * R.
   Simplified: one conductor, 100 km at about 0.05 ohm/km, single-phase equivalent (real lines are 3-phase).
2) CO2 per kWh: heat of combustion (NIST: CH4 -890.3 kJ/mol, C -393.5 kJ/mol) and the plant heat rate
   (EIA 2025 average operating heat rates: natural gas 7,781 Btu/kWh, coal 10,647 Btu/kWh; 1 kWh = 3,412 Btu).
   Coal is treated as pure carbon, so its number is an upper bound.
"""
P = 100e6          # W sent down the line (100 MW)
R = 5.0            # ohm: 100 km x 0.05 ohm/km

for kv in (13.8, 138, 345):
    I = P / (kv * 1e3)                    # amps needed
    loss = I ** 2 * R                     # watts turned into heat
    print(f"{kv:5} kV: {I:5.0f} A, loss {100 * loss / P:6.1f}%")

FUEL = {"gas": (890.3, 7781),             # kJ/mol released, Btu per kWh
        "coal": (393.5, 10647)}
for name, (dH, heat_rate) in FUEL.items():
    eff = 3412 / heat_rate                # plant efficiency
    mol = 3600 / (dH * eff)               # mol of fuel per kWh (3600 kJ)
    print(f"{name}: eff {eff:.0%}, {mol * 44.01:.0f} g CO2/kWh")
