I've written some code to calculate how many Pomodori can fit into a period of time, including long and short breaks. I'm looking for alternative solutions because what I have at the moment doesn't feel right. I think I'm missing something.
A Pomodoro is an interval of time 25 minutes long and after each one there should be a short 5 minute break. But every 4x Pomodori should be followed by a long 15 minutes break. So we have the following:
╔═══════╦════════╦═════════════╗
║ Time ║ Length ║ Activity ║
╠═══════╬════════╬═════════════╣
║ 12:00 ║ 25:00 ║ Pomodoro ║
║ 12:25 ║ 05:00 ║ Short Break ║
║ 12:30 ║ 25:00 ║ Pomodoro ║
║ 12:55 ║ 05:00 ║ Short Break ║
║ 13:00 ║ 25:00 ║ Pomodoro ║
║ 13:25 ║ 05:00 ║ Short Break ║
║ 13:30 ║ 25:00 ║ Pomodoro ║
║ 13:55 ║ 15:00 ║ Long Break ║
║ 14:10 ║ 25:00 ║ Pomodoro ║
╚═══════╩════════╩═════════════╝
At the moment I use a loop to populate a list and then delete the last element if it's not a Pomodoro, as there's no point in ending the list of Pomodori with a break.
pomodori = []
iterations = 0
seconds = 3 * 60 * 60
while seconds > 0:
# zero and even numbers are always Pomodori
if iterations % 2 == 0 or iterations == 0:
pomodori.append('pomodoro')
seconds -= 25 * 60
else:
quotient, remainder = divmod(iterations+1, 4)
# if the quotient is even and the remainder is zero, then we
# are just after a 4x Pomodori and should add a long break
if quotient % 2 == 0 and remainder == 0:
pomodori.append('long-break')
seconds -= 15 * 60
# otherwise, we're at a short break
else:
pomodori.append('short-break')
seconds -= 5 * 60
iterations += 1
# remove breaks that are not followed by a Pomodoro
if pomodori[-1] != 'pomodoro':
del pomodori[-1]
EDIT:
I've gone ahead with jonrsharpe's solution. The code is here for those interested.