I'm counting jumps. My jumps are timestamped, and I have the jump count on both UTC time zone and GMT -3 time zone (my time zone). The jump counts are:
| Day | UTC | GMT -3 |
|---|---|---|
| Sunday | 658 | 672 |
| Monday | 704 | 701 |
| Tuesday | 696 | 756 |
| Wednesday | 727 | 680 |
| Thursday | 738 | 740 |
| Friday | 688 | 669 |
| Saturday | 699 | 692 |
How many jumps should I jump each day on my time zone, before and after 9 PM (21h00), so I have the same number of jumps every day in both time zones (UTC and GMT -3)? How can I model this problem?
The number of jumps must be the same across all days of the week (ie. Sunday, Monday, Tuesday, etc, must all be "756" or "787", as long as they are all the same number). Also, I noticed that as the total sum of jumps must be the same on UTC and GMT -3, the numbers must also be the same on every cell of the table.
As an additional information implicit by the time zones, if I jump once on Sunday at 1 PM my time (4 PM UTC), my Sunday jump count will be 659 for UTC and 673 for GMT -3. If, on the other hand, I jump once on Sunday at 10 PM my time (1 AM Monday UTC), my jump count on Sunday will be 658 for UTC, 673 for GMT -3 and also my jump count on Monday will be 705 for UTC.
Example
Imagining a 3-day week, this:
| Day | UTC | GMT -3 |
|---|---|---|
| Sunday | 3 | 2 |
| Monday | 1 | 2 |
| Tuesday | 1 | 1 |
gets partially solved by this:
| Day | bef. 9 PM | aft. 9 PM |
|---|---|---|
| Sunday | 0 | 1 |
| Monday | 0 | 0 |
| Tuesday | 0 | 0 |
making the table look like this:
| Day | UTC | GMT -3 |
|---|---|---|
| Sunday | 3 | 3 |
| Monday | 2 | 2 |
| Tuesday | 1 | 1 |
and from this point forward, the solution to equalize every number is trivial by adding jumps before 9 PM, which add the jump count for each day on both time zones:
| Day | bef. 9 PM | aft. 9 PM |
|---|---|---|
| Sunday | 0 | 0 |
| Monday | 1 | 0 |
| Tuesday | 2 | 0 |
finally making the table:
| Day | bef. 9 PM | aft. 9 PM |
|---|---|---|
| Sunday | 3 | 3 |
| Monday | 3 | 3 |
| Tuesday | 3 | 3 |
The final solution is the sum of each partial table:
| Day | bef. 9 PM | aft. 9 PM |
|---|---|---|
| Sunday | 0 | 1 |
| Monday | 1 | 0 |
| Tuesday | 2 | 0 |
This can be solved by dividing the problem into two partial problems: calculate jumps done after 9 PM, to even the jump count on every day in both time zones (lines of the table); then jumps done before 9 PM, to even the jump count across all days.
As jumping before 9 PM equally changes the counter on both time zones, it is useless trying to find jumps considering jumps done at this time. Considering an initial state with 0 jumps in all days, jumps done after 9 PM are the only ones which can disturb the balance between time zones.
For the first part of the problem, the following algorithm solves the problem:
It works by comparing the jump count on the current week day on the GMT -3 and UTC time zones. If there are more jumps on GMT -3, the difference is compensated by adding the jumps needed post 9 PM in the previous week day. It will count as jumps on the previous week day on GMT -3, but it will even the number of jumps in the current week day.
After both time zones have the same number of jumps in each week day (each line of the first table), we simply find the day with most jumps and add the difference to each week day by jumping that count before 9 PM.
Example:
The original problem is:
After running the jump counts through the algorithm we get:
and
After that, we simply add jumps before 9 PM so all week days equal to the largest day count (Thursday in this example):
making a total of 545 additional jumps and: