Sub topic 6
Alternating and cyclic schedules
What this chapter assumes
You should already be comfortable with the work = rate × time relation and with picking the total work as an LCM so that every rate is a whole number. You should also know how to add rates for people working together. This chapter covers jobs where people do not work together. They take turns in a fixed pattern that repeats, such as A on odd days and B on even days.
The working model: one cycle is one block of work
In an alternating schedule, the pattern of who works on which day repeats. Call one full pattern a cycle. Everything in this chapter follows from three facts:
- A cycle completes a fixed amount of work, which is the sum of the rates in the pattern.
- Complete cycles are cheap to count. You divide the total work by the work per cycle.
- The job usually ends partway through a cycle. You handle that final stretch day by day.
A cycle is not the same as "working together". If A does 3 units on day 1 and B does 2 units on day 2, the pair completes 5 units in 2 days. That is 2.5 units per day, not the 5 units per day they would manage working side by side.
Worked example: A and B alternate
A alone finishes a job in 10 days and B alone in 15 days. They work on alternate days, A first. How long does the job take?
- The LCM of 10 and 15 is 30, so the total work is 30 units. A does 3 units per day and B does 2.
- One cycle (A's day, then B's day) takes 2 days and does 5 units.
- Six cycles would do exactly 30 units. That means the job ends on the last day of the sixth cycle, which is day 12. Counting the full cycles that still leave work gives 5 cycles (10 days, 25 units), with 5 units left. A does 3 on day 11 and B does the last 2 on day 12.
The answer is 12 days. When the total is an exact multiple of the cycle work, the job ends exactly at the end of a cycle. Do not add an extra cycle.
Order matters when the job ends mid-cycle
Now take A at 12 days and B at 18 days. The LCM is 36 units, with A at 3 units per day and B at 2. One cycle does 5 units in 2 days.
Seven cycles take 14 days and do 35 units. Only 1 unit remains, and who works on day 15 decides the answer.
| Start | Who works on day 15 | Time for last unit | Total |
|---|---|---|---|
| A first | A (3 units/day) | 1/3 day | 14 1/3 days |
| B first | B (2 units/day) | 1/2 day | 14 1/2 days |
The leftover work is the same, but the slower worker is on duty in one case. Starting with the faster worker finishes sooner when the job ends mid-cycle. When the job ends at the end of a cycle, the order does not matter.
Checking with code
The function below takes the total work and the list of work done on each day of the cycle. It uses exact fractions and returns the elapsed time, including a fractional last day.
from fractions import Fraction
def cyclic_time(total, day_rates):
total = Fraction(total)
rates = [Fraction(r) for r in day_rates]
cycle_work = sum(rates)
full_cycles = int(total // cycle_work)
days = Fraction(full_cycles * len(rates))
remaining = total - full_cycles * cycle_work
for r in rates:
if remaining <= 0:
break
if r >= remaining:
days += remaining / r
remaining = Fraction(0)
else:
days += 1
remaining -= r
return days
print(cyclic_time(30, [3, 2])) # 12
print(float(cyclic_time(36, [3, 2]))) # 14.333333333333334
print(float(cyclic_time(36, [2, 3]))) # 14.5The loop covers the case where the remainder is exactly zero, so no extra day is added. A day with rate 0 (a rest day) is handled correctly, because it counts as a full day with no work done.
Reverse problems: find one worker's time
Exams often give the finishing time of the alternating schedule and ask for the second worker's solo time.
A alone takes 10 days. A and B alternate, A first, and finish in exactly 9 days. How long would B take alone?
Take the total as 10 units, so A does 1 unit per day. In 9 days starting with A, A works on days 1, 3, 5, 7 and 9, which is 5 days. B works on days 2, 4, 6 and 8, which is 4 days.
- A's contribution is 5 × 1 = 5 units.
- B must supply the other 5 units in 4 days, so B does 5/4 = 1.25 units per day.
- B alone takes 10 / 1.25 = 8 days.
Check in fractions: 5 × 1/10 + 4 × 1/8 = 1/2 + 1/2 = 1. The key step is counting each person's working days correctly. In an odd number of days, the person who starts works one day more than the other.
Longer patterns and mixed days
The method does not change for three workers in rotation, or for patterns such as "A and B together on day 1, A alone on day 2". The cycle work is just the sum of that day's rates.
| Pattern | Work per cycle | Cycle length |
|---|---|---|
| A, B, A, B, ... | a + b | 2 days |
| A, B, C rotating | a + b + c | 3 days |
| A+B together, then A alone | (a + b) + a | 2 days |
| A works 2 days, B works 1 | 2a + b | 3 days |
For example, take workers A, B and C who take 12, 24 and 6 days alone. The LCM is 24 units, so their daily rates are 2, 1 and 4. If they rotate A, B, C, the cycle does 7 units in 3 days.
Pipes in a cycle: the peak matters, not the net
Alternating pipes look like alternating workers, but they have a trap. A leak or outlet removes water, and the tank may hit its capacity in the middle of a cycle, before the outlet has had its turn.
An empty tank holds 20 litres. An inlet adds 5 L/h for one hour, then an outlet removes 3 L/h for the next hour, repeating. The net gain per 2-hour cycle is 2 L.
A naive answer divides 20 by 2 and gets 10 cycles, which is 20 hours. That is wrong. After 8 cycles (16 hours) the tank holds 16 L. The inlet's next hour would add 5 L and reach 21 L, which is more than 20 L. The tank fills during that hour, after 4/5 of an hour. The answer is 16.8 hours.
from fractions import Fraction
def fill_time(capacity, rates, limit=100_000):
capacity = Fraction(capacity)
level = Fraction(0)
elapsed = Fraction(0)
steps = 0
while steps < limit:
for r in map(Fraction, rates):
if r > 0 and level + r >= capacity:
return elapsed + (capacity - level) / r
level = max(Fraction(0), level + r) # an empty tank cannot go negative
elapsed += 1
steps += 1
return None # never fills
print(float(fill_time(20, [5, -3]))) # 16.8
print(float(fill_time(20, [-3, 5]))) # 17.8The second call shows the other trap. If the outlet runs first on an empty tank, it removes nothing, so the first hour is wasted. The result is exactly 1 hour more than the inlet-first case.
Common errors
| Error | Why it is wrong | Fix |
|---|---|---|
| Treating alternate work as "together" | Each person works only on their own days | Use work per cycle, not the sum of rates per day |
| Adding an extra cycle when total work is an exact multiple of cycle work | The job ends at the end of the last cycle | Count only cycles that leave work remaining, or finish the last cycle on schedule |
| Rounding the last day up to a whole day | The job can end part-way through a day | Use remainder ÷ rate for the final fraction |
| Ignoring who starts | Matters when the job ends mid-cycle | Walk through the leftover days in pattern order |
| Counting equal days for both workers in an odd number of days | The first worker works one more day | Count working days for each person separately |
| Using net-per-cycle for pipes | The tank can fill before the outlet turn | Check the peak level within the cycle |
Exercises
Exercise
A can do a job in 15 days and B in 20 days. They work on alternate days, with B starting. How many days does the job take?
Show answer
Take the total as 60 units, so A does 4 units per day and B does 3. One cycle (B then A) takes 2 days and does 7 units. Eight cycles take 16 days and do 56 units, leaving 4 units. On day 17 B does 3 units, leaving 1 unit. On day 18 A does the last unit in 1/4 day. The total is 17 1/4 days.
Exercise
A, B and C can finish a job alone in 12, 24 and 6 days. They work in rotation A, B, C, one day each, repeating. How long does the job take?
Show answer
Take the total as 24 units, so the daily rates are 2, 1 and 4. One 3-day cycle does 7 units. Three cycles take 9 days and do 21 units, leaving 3 units. On day 10 A does 2 units, leaving 1. On day 11 B does 1 unit in one full day. The total is 11 days.
Exercise
An empty tank holds 30 litres. An inlet adds 7 L/h for one hour, then an outlet removes 4 L/h for the next hour, repeating, with the inlet first. When does the tank become full?
Show answer
The net gain per 2-hour cycle is 3 L. After 16 hours (8 cycles) the level is 24 L. Seven cycles would leave 21 L, and the next inlet hour reaches only 28 L, which is short of 30 L. After 16 hours, 6 L are still needed, and the inlet adds 7 L/h, so this takes 6/7 of an hour. The tank is full after 16 6/7 hours.