Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Minimal Bridge solution in Clear category for Microwave Ovens by r.bathoorn
from abc import ABC, abstractmethod
class MicrowaveBase(ABC):
seconds = 0
@abstractmethod
def show_time(self):
raise NotImplementedError(NOT_IMPLEMENTED)
class Microwave1(MicrowaveBase):
def show_time(self):
time = f'{self.seconds//60:0>2d}:{self.seconds%60:0>2d}'
return '_'+time[1:]
class Microwave2(MicrowaveBase):
def show_time(self):
time = f'{self.seconds//60:0>2d}:{self.seconds%60:0>2d}'
return time[:-1]+'_'
class Microwave3(MicrowaveBase):
def show_time(self):
time = f'{self.seconds//60:0>2d}:{self.seconds%60:0>2d}'
return time
class RemoteControl:
def __init__(self, microwave):
self.microwave = microwave
def set_time(self, time):
minutes, seconds = time.split(':')
self.microwave.seconds = int(minutes) * 60 + int(seconds)
def add_time(self, time):
if time[-1]=='s':
self.microwave.seconds += int(time[:-1])
if time[-1]=='m':
self.microwave.seconds += int(time[:-1])*60
if self.microwave.seconds > 90*60:
self.microwave.seconds = 90 * 60
def del_time(self, time):
if time[-1]=='s':
self.microwave.seconds -= int(time[:-1])
if time[-1]=='m':
self.microwave.seconds -= int(time[:-1])*60
if self.microwave.seconds < 0:
self.microwave.seconds = 0
def show_time(self):
return self.microwave.show_time()
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
microwave_1 = Microwave1()
microwave_2 = Microwave2()
microwave_3 = Microwave3()
remote_control_1 = RemoteControl(microwave_1)
remote_control_1.set_time("01:00")
remote_control_2 = RemoteControl(microwave_2)
remote_control_2.add_time("90s")
remote_control_3 = RemoteControl(microwave_3)
remote_control_3.del_time("300s")
remote_control_3.add_time("100s")
assert remote_control_1.show_time() == "_1:00"
assert remote_control_2.show_time() == "01:3_"
assert remote_control_3.show_time() == "01:40"
print("Coding complete? Let's try tests!")
Jan. 18, 2021