Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Microwave Ovens by mozurin
import functools
class MicrowaveBase:
BROKEN = None
def __init__(self):
self.seconds = 0
def set_time(self, minSecs):
self.seconds = functools.reduce(
lambda m, s: m * 60 + s,
map(int, minSecs.split(':'))
)
def _parse_diff(self, diff):
return (
int(diff.rstrip('m')) * 60 if diff.endswith('m')
else int(diff.rstrip('s'))
)
def add_time(self, diff):
self.seconds = min(90 * 60, self.seconds + self._parse_diff(diff))
def del_time(self, diff):
self.seconds = max(0, self.seconds - self._parse_diff(diff))
def show_time(self):
minSecs = f'{self.seconds // 60:02d}:{self.seconds % 60:02d}'
return (
minSecs if self.BROKEN is None
else minSecs[:self.BROKEN] + '_' + minSecs[self.BROKEN + 1:]
)
class Microwave1(MicrowaveBase):
BROKEN = 0
class Microwave2(MicrowaveBase):
BROKEN = 4
class Microwave3(MicrowaveBase):
pass
class RemoteControl:
def __init__(self, oven):
self.oven = oven
def __getattr__(self, name):
return getattr(self.oven, name)
July 3, 2018
Comments: