Sub topic 12
Pipes opened or closed at different times
This chapter assumes you can already do the following:
- Treat each pipe as a rate, where an inlet is positive and an outlet or leak is negative.
- Pick a total capacity with the LCM method.
- Find the net filling time when several pipes run together.
- Handle a worker who joins or leaves partway through a job.
A pipe that opens or closes midway is the same idea as a worker who joins or leaves. The only new skill is cutting the timeline into phases and keeping track of the tank level.
The phase method
Between two events (a pipe opens or a pipe closes), the set of open pipes does not change. So the net rate is constant, and the amount added in that phase is simple:
amount in phase = net rate × duration of phase
The whole problem is then a sum over phases:
total in tank = sum of (net rate × duration) over all phases
Set that total equal to the capacity and solve for whichever quantity is unknown. The unknown is usually the length of the last phase, but it can also be the opening time of a pipe or how long a pipe stays open.
Worked example 1: a pipe opened later
Pipe A fills a tank in 20 hours. Pipe B fills it in 30 hours. A is opened at the start, and B is opened 5 hours later. When is the tank full?
Take the capacity as LCM(20, 30) = 60 units. Then A = 3 units/h and B = 2 units/h.
| Phase | Open pipes | Net rate | Duration | Added |
|---|---|---|---|---|
| 1 | A | 3 | 5 h | 15 |
| 2 | A and B | 5 | t | 5t |
Set 15 + 5t = 60, so t = 9. The tank is full 5 + 9 = 14 hours after A was opened.
The question asks for the time from the start, not just the length of the last phase. Add the earlier phases back before you answer.
Worked example 2: an outlet closed later
Inlet A fills a tank in 8 hours. Outlet C empties a full tank in 12 hours. Both are open at the start, and C is closed after 12 hours. How long does the whole job take?
Take the capacity as LCM(8, 12) = 24 units. Then A = +3 and C = −2.
| Phase | Open pipes | Net rate | Duration | Added |
|---|---|---|---|---|
| 1 | A and C | +1 | 12 h | 12 |
| 2 | A | +3 | t | 3t |
Set 12 + 3t = 24, so t = 4. The total time is 12 + 4 = 16 hours.
Worked example 3: finding when to close a pipe
A fills a tank in 15 hours and B fills it in 10 hours. Both are opened together. After how long should B be closed so the tank is full in exactly 10 hours?
Take the capacity as LCM(15, 10) = 30 units. Then A = 2 and B = 3.
A runs for the full 10 hours and adds 20 units. B must supply the remaining 10 units, which takes 10 ÷ 3 = 10/3 hours. So B is closed after 3 hours 20 minutes.
Here the unknown is a duration in the middle of the timeline, not the last phase. Write the equation 2 × 10 + 3 × x = 30 and solve for x.
Clock-time problems
Some questions give clock times for the events. For example, A is opened at 9:00 and B is opened at 11:00. Convert each event into hours since the first event, then use the phase method.
A fills a tank in 6 hours and B empties a full tank in 8 hours. The tank starts empty. A is opened at 9:00 and B at 11:00. When is the tank full?
Take the capacity as LCM(6, 8) = 24 units. Then A = +4 and B = −3.
- From 9:00 to 11:00, only A is open. It adds 4 × 2 = 8 units.
- After 11:00 the net rate is +1 unit/h. The remaining 16 units take 16 hours.
- The tank is full 18 hours after 9:00, which is 3:00 the next morning.
A phase calculator in Python
The function below applies the phase method directly. Each event is a pair (time, rate_change). A pipe opening adds its rate. A pipe closing subtracts its rate, which for an outlet means adding a positive amount. Exact fractions avoid rounding errors.
from fractions import Fraction
def time_to_fill(capacity, events, level=0):
"""Return the time at which the tank reaches capacity.
events is a list of (time, rate_change) pairs.
Returns None if the tank never fills.
Raises ValueError if the level would drop below zero.
"""
capacity = Fraction(capacity)
level = Fraction(level)
events = sorted((Fraction(t), Fraction(d)) for t, d in events)
t = Fraction(0)
rate = Fraction(0)
i = 0
while True:
next_t = events[i][0] if i < len(events) else None
if rate > 0:
finish = t + (capacity - level) / rate
if next_t is None or finish <= next_t:
return finish
if next_t is None:
return None
level += rate * (next_t - t)
if level < 0:
raise ValueError("the tank runs empty before the next event")
t = next_t
rate += events[i][1]
i += 1
# Example 1: A fills in 20 h from time 0, B fills in 30 h from time 5.
print(time_to_fill(1, [(0, Fraction(1, 20)), (5, Fraction(1, 30))])) # 14
# Example 2: A fills in 8 h, C empties in 12 h; C is closed at time 12.
print(
time_to_fill(
1,
[(0, Fraction(1, 8)), (0, Fraction(-1, 12)), (12, Fraction(1, 12))],
)
) # 16
# Example 3: A (15 h) and B (10 h) open together; B closed at 10/3 h.
print(
time_to_fill(
1,
[
(0, Fraction(1, 15)),
(0, Fraction(1, 10)),
(Fraction(10, 3), Fraction(-1, 10)),
],
)
) # 10The calculator is not for exam use. It is useful for checking your hand method on practice problems.
Edge cases and traps
The tank may fill before the next event
In each phase, check that the tank does not exceed capacity. Suppose A fills a tank in 4 hours and B is scheduled to open after 6 hours. The tank is already full at hour 4, and B never matters. If your phase total passes the capacity, the answer lies inside that phase, not in a later one.
The tank may empty before the next event
An outlet cannot drain more than the tank holds. If a phase has a negative net rate, work out when the level reaches zero. After that point the level stays at zero, and the negative rate has no effect until an inlet makes the net rate positive again. The calculator above raises an error in this case instead of silently continuing.
A net negative rate means the tank may never fill
If an outlet is faster than all the inlets combined, an empty tank stays empty. A formula such as 1 ÷ (net rate) then gives a negative time. Treat a negative time as a signal that the setup is wrong, not as an answer.
Start and finish levels
The phase method also works for a tank that starts partly full. Work in units and begin the running total at the starting level. If the tank is one-third full and the capacity is 24 units, start the total at 8. If the question asks only for time to empty, use the level as the amount to remove.
Signs on closing
Closing an inlet removes a positive rate, so the net rate drops. Closing an outlet removes a negative rate, so the net rate rises. Mixing these up is the most common sign error. Rewrite each phase's net rate from scratch for the pipes that are open in that phase, not by adjusting the previous phase.
Cyclic opening
Some problems open pipes in a repeating pattern, for example A for one hour, then B for one hour, and so on. This chapter's method still applies, and the cycle follows the alternating-schedule approach from the earlier chapter. Compute the amount per full cycle, find how many whole cycles fit before the last partial one, then handle the leftover.
A sanity check for every answer
Before you move on, run these checks:
- Is the final time at least as long as the time the fastest single arrangement would take?
- Is it shorter than the time with only the slowest pipe, if the extra pipes were all inlets?
- Does the level stay between 0 and capacity in every phase?
- Did you answer the question that was asked: total time, or time after a given event?
Summary of the method
- Choose a capacity from the LCM of the pipe times.
- Give each pipe a signed rate: positive for an inlet, negative for an outlet or leak.
- Split the timeline into phases wherever a pipe opens or closes.
- Add net rate × duration across the phases and equal it to the capacity.
- Solve for the unknown and verify that the level never leaves the range 0 to capacity.
Exercise
Pipe A fills a tank in 10 hours, pipe B fills it in 15 hours, and pipe C empties a full tank in 30 hours. A is opened at the start, B is opened after 2 hours, and C is opened after 4 hours. How long after the start is the tank full?
Show answer
Take the capacity as 30 units, so A = +3, B = +2 and C = −1. From 0 to 2 h only A is open and adds 6 units. From 2 to 4 h A and B are open at a rate of 5 and add 10 units, so the total is 16. After 4 h the net rate is 3 + 2 − 1 = 4. The remaining 14 units take 14 ÷ 4 = 3.5 h. The tank is full after 4 + 3.5 = 7.5 hours.
Exercise
Pipes A and B fill a tank in 12 hours and 18 hours respectively. Both are opened together on an empty tank. After how many hours should A be closed so that the tank is full in 15 hours in total?
Show answer
Take the capacity as 36 units, so A = 3 and B = 2. B runs for all 15 hours and adds 30 units. A must add the remaining 6 units, which takes 6 ÷ 3 = 2 hours. A should be closed after 2 hours.
Exercise
Inlet A fills a tank in 6 hours. Outlet C empties a full tank in 4 hours. Both are opened at the same time on an empty tank. Does the tank ever fill? What does the formula 1 ÷ (net rate) give, and why is it not the answer?
Show answer
With capacity 12 units, A = +2 and C = −3, so the net rate is −1 unit/h. The formula gives −12 hours, which is meaningless. An empty tank cannot go below empty, so the outlet drains whatever the inlet adds and the tank never fills.