Selecting items from events, as evenly spaced as possible

Posted by Matt Warren on Stack Overflow See other posts from Stack Overflow or by Matt Warren
Published on 2010-06-14T11:36:52Z Indexed on 2010/06/14 11:52 UTC
Read the original article Hit count: 260

Filed under:
|
|

If I have an event that happens 15 times a second (numbered 1 - 15), but I only want to process it 3 times I can choose [1], [6] and [11],. It's important that the events I process are as evenly spaced as possible and take into account wrap-around, i.e. the events are continuous 13, 14, 15, 1, 2, 3 etc.

If I want 4 items the best I can do is [1], [5], [9] & [13].

Is there a general algorithm that will calculate which events I need to process given the total number of events (total) and the number to process (processAmount).

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about events