Drill

ProblemsPython › machines

Machine uptime per thousand

easymachinesPython

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

uptime_permille(up_hours: int, down_hours: int) → int

Solve it in the editor →

Where you start

def uptime_permille(up_hours: int, down_hours: int) -> int:
    

Worked examples

CallResult
uptime_permille(1000, 0)1000
uptime_permille(993, 7)993
uptime_permille(750, 250)750
uptime_permille(3, 1)750

Hint

upHours * 1000 / total — but a total of zero is a special case that must come first.

Reference solution in Python
def uptime_permille(up_hours: int, down_hours: int) -> int:
    if up_hours + down_hours == 0:
        return 1000
    return (up_hours * 1000) // (up_hours + down_hours)

The same problem in another language

More machines problems in Python