Is the electric garage door open? 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 up/down, U/D, +/-, 1/0 or whatever you choose.


You may assume the door takes infinitesimally less than 10 seconds to complete an open or close action.

Example inputs:

&lt;empty list&gt;  # 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.
Lua, 258 248 242 bytes
u,s,p=1&gt;0,0&gt;1,0;io.read():gsub(&quot;%d+&quot;,function(a)if(not s)then p=u and p+a or p-a;if(p&gt;=10 or p&lt;=0)then s,p=1&gt;0,p&gt;0 and 10 or 0;end;u,s=not u,not s else s=0&gt;1;end end)if(not s)then p=u and 10 or 0;u=not u;end;print(10*p..&quot;% &quot;..(u and&quot;U&quot;or&quot;D&quot;))

Ungolfed
u,s,p=true,false,0;                          -- Up direction, Stopped, Position
io.read():gsub(&quot;%d+&quot;,function(t)             -- For each number in input
    if(not s)then                            -- If door wasn't stopped
        p=u and p+t or p-t;                  -- Position = Moving up ? +t : -t
        if(p&gt;=10 or p&lt;=0)then                -- If door fully opened or closed
            s,p=true,p&gt;0 and 10 or 0;        -- Then door stopped at 0 or 10
        end 
        u,s=not u,not s;                     -- Toggle direction and toggle stopped
    else 
        s=false;                             -- If stopped, nothing happened, un-stop.
    end 
end)
-------------------- Done pressing the button --------------------
if(not s)then                                -- If left off moving
    p=u and 10 or 0;                         -- Finish movement
    u=not u;                                 -- Toggle direction
end 
print(10*p..&quot;% &quot;..(u and&quot;U&quot;or&quot;D&quot;))           -- Output answer

I don't see how your test cases can be right...
20 20 -- Initial push, after 20, garage is at 100, push to start it down, after 20, garage is at 0, push to start it up, garage finishes up.
10 10 -- Same as above
1 2 3 -- 0 U Moving, wait 1, 1 D Stopped, wait 2, 0 U stopped, wait 3, 100 D stopped

 OP Fixed