Absolute Zero, Approximately
Stardate 55112.3 ยท UES Magnanimous
Briefing
The long-range sensor package reports temperature in Celsius. Lt. Skree's analysis suite requires Kelvin, and Skree has requested the conversion be done "correctly, to two decimal places, and without any of the drama that attended the last attempt".
The last attempt, for the record, returned 273.14999999999998 for a reading of zero, and Skree filed a formal complaint about the "aesthetic and moral" quality of the number. Commander Raghunathan has asked that you round it. She has also asked that nobody mention floating point to Skree ever again.
Mission objectives
ARCHIE checks all five every time you run diagnostics.
- โขZero Celsius is 273.15 K
- โขAbsolute zero, minus 273.15, is 0.0 K
- โขBoiling water at 100 is 373.15 K
- โขRoom temperature, 21.5, is 294.65 K
- โขThe result is rounded to two decimal places
Objective
Write to_kelvin(celsius): add 273.15 and return the result
rounded to two decimal places. So to_kelvin(0) is
273.15 and to_kelvin(-273.15) is 0.0.
Press Run Diagnostics and I will tell you which objectives you actually met.
Objective
Write to_kelvin(celsius: f64) -> f64: add 273.15 and return the result
rounded to two decimal places. So to_kelvin(0.0) is
273.15 and to_kelvin(-273.15) is 0.0.
Press Run Diagnostics and I will tell you which objectives you actually met.
Ask Commander Raghunathan for a hint
Add 273.15, then round to two decimal places. Python has round(x, 2). Rust does not round to places directly: multiply by 100, .round(), divide by 100.
Debrief
Kelvin readings are arriving rounded to two decimal places, and Lt. Skree has withdrawn the complaint. Skree has, however, opened a new one about the phrase "approximately absolute zero", which Skree considers a contradiction in terms. It is addressed to the universe.