Zend certified PHP/Magento developer

matching specific departure times in a bus timetable

I’m constructing a bus timetable and I implemented parameters like different intervals, travel-times, min. waiting time at end-stops etc. How can I automatically number reoccurring buses (yellow cell in table). I managed so far only the numbering of all buses on their first laps but not once they are back again at the starting point (‘Stop A’ in table). The solution should also work if I change parameters. Thank you.