## The Game Consider a points-based game with the following rules: - Players spend money within bucketed intervals of time (e.g. 1 interval = 1 day from 00:00 to 23:59) - Money spent in one interval is split up evenly and spent over N intervals. - A player is active within an interval if they have money spent during it (including money spread) - Every interval, 1 point is split among active players, proportional to how much each spent in that interval. - If no players are active within an interval, no point is distributed. - If a player is inactive for one or more intervals, their points reset to zero. - N is fixed for all players of the game. ## The challenge Given the current interval, we should be able to compute the number of active points for each of the previous (completed) N intervals. This algorithm can not have a storage overhead exceeding O(C*N), where N is the number of intervals a single spend is spread across. C is a constant factor. ## Examples Suppose N=4 ### Just Alice Alice wishes to spend $1. The money is spent as follows: Interval 1 2 3 4 5 6 7 8 Alice $0.25 $0.25 $0.25 $0.25 $0 $0 $0 $0 If Alice is the only player, the point totals at the end of each interval are: Interval 1 2 3 4 5 6 7 8 Alice 1 2 3 4 0 0 0 0 Totals 1 2 3 4 0 0 0 0 ### Alice, then Bob Now, suppose Bob spends $2 in the second interval, as follows: Interval 1 2 3 4 5 6 7 8 Alice $0.25 $0.25 $0.25 $0.25 $0 $0 $0 $0 Bob $0 $0.50 $0.50 $0.50 $0.50 $0 $0 $0 The new point totals are as follows: Interval 1 2 3 4 5 6 7 8 Alice 1 1.33 1.66 2 0 0 0 0 Bob 0 0.66 1.33 2 3 0 0 0 Totals 1 2 3 4 3 0 0 0 ### Alice Renews Now, suppose Alice renews with an additional $1 starting in the fourth interval: Interval 1 2 3 4 5 6 7 8 Alice $0.25 $0.25 $0.25 $0.50 $0.25 $0.25 $0.25 $0 Bob $0 $0.50 $0.50 $0.50 $0.50 $0 $0 $0 The new point totals are as follows: Interval 1 2 3 4 5 6 7 8 Alice 1 1.33 1.66 2.16 2.50 3.50 4.50 0 Bob 0 0.66 1.33 1.83 2.50 0 0 0 Totals 1 2 3 4 5 3.50 4.50 0