THINK FIRST·CODE LATER

← All labs

Software Carbon Intensity calculator

Problem

Compare the Software Carbon Intensity of design options for Buddy using the SCI formula SCI = ((E × I) + M) / R.

Input: first line gridIntensity (gCO₂e per kWh). Then scenarios until the end of input, one per line:

name energyKWh embodiedGrams questions

For each scenario print

name: operational X g, embodied Y g, total Z g, SCI S g/question

(X = E × I, total = X + Y; X, Y, Z with one decimal, S with three decimals; if questions is 0, print SCI n/a instead of the value). Then print Best: name (S g/question) for the lowest SCI (first on a tie, scenarios with 0 questions excluded) and, for every other valid scenario, name is +P% vs best with P = (S − best) / best × 100 rounded to the nearest integer (Math.round).

Input:

600
large-model 12 1800 4000
small-model 6 1800 4000
small+cache 4 1800 4400

Output:

large-model: operational 7200.0 g, embodied 1800.0 g, total 9000.0 g, SCI 2.250 g/question
small-model: operational 3600.0 g, embodied 1800.0 g, total 5400.0 g, SCI 1.350 g/question
small+cache: operational 2400.0 g, embodied 1800.0 g, total 4200.0 g, SCI 0.955 g/question
Best: small+cache (0.955 g/question)
large-model is +136% vs best
small-model is +41% vs best

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.