Machine uptime per thousand
Maintenance reports uptime as parts per thousand so a single line reads as 993 instead of a harder-to-compare 99.3%.
- Uptime is the running hours out of every thousand, truncated down.
- A plant that neither ran nor stopped for the whole window reads as full uptime: 1000.
uptimePermille(upHours: int, downHours: int) → int
Java needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.
Where you start
int uptimePermille(int upHours, int downHours) {
}
Worked examples
| Call | Result |
|---|---|
uptimePermille(1000, 0) | 1000 |
uptimePermille(993, 7) | 993 |
uptimePermille(750, 250) | 750 |
uptimePermille(3, 1) | 750 |
Hint
upHours * 1000 / total — but a total of zero is a special case that must come first.
Reference solution in Java
int uptimePermille(int upHours, int downHours) {
if (upHours + downHours == 0) return 1000;
return (upHours * 1000) / (upHours + downHours);
}