My electric garage door works like this:
- There is just one push button to control the door
- If the door is fully closed and I hit the button, the door starts to open. It takes 10 seconds to open fully
- If the door is fully open and I hit the button, the door starts to close. It takes 10 seconds to close fully
- If the door is part way through opening or closing and I hit the button, then the door stops and is left partially open.
- Whenever the door stops moving, either from automatic completion of an open or close action, or from manual interruption by pushing the button partway through an action, then the mechanism will reverse and remember its direction for the next action.
- If the button is pushed when the door is stopped but partially open, then the amount of time for it to complete its action will be a fraction of 10 seconds in proportion to the amount it needs to move to complete the action.
Assume the door is fully closed at the start.
An input list of integers will be given. These integers are the number of seconds I wait between successive pushes of the control button.
Output two things:
- a percentage indicating the state of the door once all button pushes are completed and the door has reached a steady state. Output of
%symbol is optional.
- an unambiguous indication of what direction the door will travel on the next button push. This may be
0or whatever you choose.
You may assume the door takes infinitesimally less than 10 seconds to complete an open or close action.
<empty list> # button was pushed just once 20 # button was pushed twice with 20 seconds between 10 5 20 20 10 10 5 5 1 2 3 8 9 10 11 11 10 9 8 7
Expected outputs corresponding to above inputs
100% D 0% U 0% U 50% D 100% D 100% D 0% U 100% D 0% U 20% U
Worked example of the last test
- Door starts off closed. Button is pushed
- Wait 11 seconds. Door ends up fully opened. Button is pushed.
- Wait 10 seconds. Door ends up fully closed. Button is pushed.
- Wait 9 seconds. Button is pushed. Door stops at 90% open.
- Wait 8 seconds. Button is pushed. Door starts to close.
- Wait 7 seconds. Button is pushed. Door stops at 20% open. Next direction will be up.