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

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

s13-3-data-1.txt

600
large-model 12 1800 4000
small-model 6 1800 4000
small+cache 4 1800 4400
What your program must print for s13-3-data-1.txt
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

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < s13-3-data-1.txt

Windows PowerShell does not understand <:

Get-Content s13-3-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

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.