Time 45 Minutes Using Two Non-Uniform Burning Cords
Math & Bit ManipulationAuto-graded · 17 test casesLast updated
Tests logical reasoning about burn-time budgets and how lighting both ends of a cord precisely halves its remaining duration regardless of density.
Problem
You have two cords and a box of matches. Each cord takes exactly 60 minutes to burn from one end to the other. The material is unevenly packed, so burning speed varies along the length — half the physical length of a cord does not represent half the burn time.
You may ignite either end of either cord at any moment. Your task is to produce a procedure that times exactly 45 minutes, starting from your first match strike.
Key Facts
- Igniting one end of a cord lets it burn for 60 minutes total.
- Igniting both ends of a cord simultaneously causes the two flames to consume the cord's total remaining "fuel" at double speed. The cord is gone in exactly half of whatever one-end time it had left, regardless of where the flames happen to meet — because only total fuel matters, not position.
- You cannot cut the cords, fold them, or use any other measuring device.
What to Return
Return the exact six-step sequence below (as a List[str]), in order, with no modifications:
"At time 0, light both ends of rope A."
"At time 0, light one end of rope B."
"Rope A finishes at time 30 minutes, because it is burning from both ends."
"At time 30, light the other end of rope B."
"Rope B has 30 minutes of one-end burning remaining, which takes 15 minutes when lit from both ends."
"Rope B finishes at time 45 minutes."
The judge compares your return value against this list exactly.
Constraints
- The function takes no parameters and returns a
List[str]of exactly 6 elements. - Each string must match the expected output character-for-character.
- No other measuring tools, no cutting, no folding.
- The procedure must work regardless of how burn density is distributed along either cord.
Examples
Example 1
Input: measure_45_minutes()
Output: ['At time 0, light both ends of rope A.', 'At time 0, light one end of rope B.', 'Rope A finishes at time 30 minutes, because it is burning from both ends.', 'At time 30, light the other end of rope B.', 'Rope B has 30 minutes of one-end burning remaining, which takes 15 minutes when lit from both ends.', 'Rope B finishes at time 45 minutes.']
Example 2
Input: measure_45_minutes()
Output: ['At time 0, light both ends of rope A.', 'At time 0, light one end of rope B.', 'Rope A finishes at time 30 minutes, because it is burning from both ends.', 'At time 30, light the other end of rope B.', 'Rope B has 30 minutes of one-end burning remaining, which takes 15 minutes when lit from both ends.', 'Rope B finishes at time 45 minutes.']
Hints
Hint 1
Think of each cord as holding a fixed 'budget' of burn-time fuel rather than a physical length — what operation halves that budget instantly?
Hint 2
Cord A burning from both ends disappears in 30 minutes and acts as a precise timer; what does that tell you about how much fuel cord B has left at that moment?
Hint 3
The moment cord A burns out is your signal to change something about cord B — what one action at t = 30 converts a 30-minute remainder into a 15-minute one?
Worked solution
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Approach
Core insight: fuel, not length
Because density is uneven, physical position along a cord carries no timing information. The only reliable quantity is burn-time fuel — the total number of minutes a cord (or the remainder of a cord) will take to finish when burning from one end.
Two rules follow directly:
- A cord with
Tminutes of one-end fuel left, ignited from both ends, is consumed in exactlyT / 2minutes. The two flames eat the fuel at double the rate; where they meet is unpredictable and irrelevant. - A cord burning from one end for
tminutes has exactly60 - tminutes of one-end fuel left.
Why the procedure is correct
- t = 0: Cord A is lit from both ends (60 min fuel, double rate → finishes in 30 min). Cord B is lit from one end (starts consuming its 60 min of fuel at single rate).
- t = 30: Cord A burns out — this is the trigger. Cord B has been burning for 30 min from one end, so it has exactly
60 - 30 = 30minutes of one-end fuel remaining. - t = 30: Light cord B's other end. Its remaining 30 min of fuel now burns at double rate → finishes in
30 / 2 = 15more minutes. - t = 45: Cord B burns out. Elapsed time since t = 0 is 45 minutes.
No step depends on the physical position of any flame, only on the total fuel remaining — which is always exactly known.
Common pitfalls
- Measuring by length ("when half of cord B is gone") is wrong; uneven density makes length meaningless.
- Lighting cord B only after cord A finishes gives cord B a full 60 min of fuel; lighting both ends then yields 30 min, for a total of 60, not 45.
- Any delay between cord A burning out and lighting cord B's second end adds directly to the final time.
Complexity
The procedure is a fixed, finite sequence of six events with no dependence on any input size.
- Time: O(1)
- Space: O(1)
Reference solution
from typing import List
def measure_45_minutes() -> List[str]:
return [
"At time 0, light both ends of rope A.",
"At time 0, light one end of rope B.",
"Rope A finishes at time 30 minutes, because it is burning from both ends.",
"At time 30, light the other end of rope B.",
"Rope B has 30 minutes of one-end burning remaining, which takes 15 minutes when lit from both ends.",
"Rope B finishes at time 45 minutes."
]