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:

Is the question about "how many" interval we can fit or about generating the sequence ? The answers are good so far but could be even more concise if the question was more precise.
–
JosayJun 11 '14 at 16:03

@Josay I could have phrased it better but initially I wanted the quantities of each type of unit (Pomodoro, short break, long break). My first implementation ended up creating a sequence because I'm terrible at maths and couldn't work out a mathematical way of doing it. Now I'm happy with the sequence solution, it's even given me some new ideas for the UI.
–
Matt Deacalion StevensJun 11 '14 at 16:28

I think it would be simpler just to apply some ingenuity and partially unroll the loop. While it's possible to fit in a long cycle (pomodoro, short break, pomodoro, short break, pomodoro, short break, pomodoro, long break) with time left over, then do that. While it's possible to fit in a short cycle (pomodoro, short break) with time left over, do that.

I'd also define some constants for readability.

pomodori is not quite an appropriate name for the result, since it includes pomodori and breaks.

Wow, thank you. That's really nice! This is similar to my first attempt, which I didn't manage to pull off. That's probably the reason I had an iffy feeling about the final code. It's already a method in a project I'm working on, see here. I simplified it a little for this question. Thanks again! :-)
–
Matt Deacalion StevensJun 11 '14 at 12:34

3

Please remember to upvote all answers that you find useful. (I recommend waiting a while before accepting an answer, as acceptance usually kills the desire for anyone else to respond.)
–
200_success♦Jun 11 '14 at 12:36