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 = 0seconds = 3 * 60 * 60while 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 Pomodoroif pomodori[-1] != 'pomodoro':    del pomodori[-1]EDIT:I've gone ahead with jonrsharpe's solution. The code is here for those interested.
Calculating how many Pomodori fit into a period of time
python;algorithm;datetime
I would split this into two functions; one that just creates the sequence, and one that develops the programme for a time period:def pomodori():    Generate pomodori and breaks indefinitely.    n = 0    while True:        if n % 8 == 7:            yield ('long break', 15)        elif n % 2 == 0:            yield ('pomodoro', 25)        else:            yield ('short break', 5)        n += 1def programme(len_=120):    Create the pattern for a session of specified length.    t = 0    prog = []    for pn, tn in pomodori():        if t + tn > len_:            break        t += tn        prog.append(pn)    if prog and prog[-1].endswith('break'):        prog.pop()    return progExample:>>> programme(180)'pomodoro', 'short break', 'pomodoro', 'short break', 'pomodoro', 'short break', 'pomodoro', 'long break', 'pomodoro']I have chosen to write in minutes, as all of your lengths are in minutes. You can put handlers around this to convert to or from seconds or hours, but this gives a good start. 