Drill

ProblemsC# › machines

Machine uptime per thousand

easymachinesMathC#

Maintenance reports uptime as parts per thousand so a single line reads as 993 instead of a harder-to-compare 99.3%.

UptimePermille(upHours: int, downHours: int) → int

C# 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.

Solve it in Python →

Where you start

public int UptimePermille(int upHours, int downHours) {
    
}

Worked examples

CallResult
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 C#
public int UptimePermille(int upHours, int downHours) {
    if (upHours + downHours == 0) return 1000;
    return (upHours * 1000) / (upHours + downHours);
}

The same problem in another language

More machines problems in C#