Ration Arithmetic
Stardate 55114.9 ยท UES Magnanimous
Briefing
Each ration crate feeds forty person-days: one person for forty days, forty people for one day, or any arrangement in between. The Captain has asked how long the current stores will last, and the computer has answered "9.756 days". The Captain does not want the point seven five six. The Captain wants to know whether to order more.
Chief T'Kala points out that a partial day is not a day anyone gets fed on, so the answer should round down. Ensign Tannenbaum suggested rounding to the nearest, "for morale". This was overruled by everyone present, including Gerald.
Mission objectives
ARCHIE checks all five every time you run diagnostics.
- โขTen crates for a crew of forty last exactly ten days
- โขTen crates for forty-one people: nine days, because a partial day does not count
- โขNo crates, no days
- โขSeven crates for twenty people last fourteen days
- โขOne crate for eighty people is zero whole days
Objective
Write days_of_rations(crates, crew): each crate is forty person-days.
Return how many whole days the crew can be fed, rounding
down. So days_of_rations(10, 41) is 9.
Press Run Diagnostics and I will tell you which objectives you actually met.
Objective
Write days_of_rations(crates: u32, crew: u32) -> u32: each crate is
forty person-days. Return how many whole days the crew can be fed,
rounding down. So days_of_rations(10, 41) is
9.
Press Run Diagnostics and I will tell you which objectives you actually met.
Ask Commander Raghunathan for a hint
Total person-days is crates times forty. Divide by the crew size and keep only the whole number: // in Python, plain / on integers in Rust, which already discards the remainder.
Debrief
Nine days. The Captain has ordered more rations, and has also ordered that in future the computer round down before anyone gets hopeful. Chief T'Kala has entered this into the ship's standing orders, directly beneath the one about Gerald's watering schedule.
You have completed the shakedown cruise. Report to the mission board: the Science station is now open to you.