figure out how it works!
Okay. if you look at the code you'll see it essentially consists of 3 consecutive loops:
This takes an input like ["010000", "010110", 6] and adds two columns to it to make ["010000", "010110", 6, 0, 70].
Ie. It takes each of the day/hour/minute values and converts them to an integer (dhm2int()) and appends them. This gets all the messy string handling out the way up front and simplifiies all comparisons.
Also, within that map there is a while loop. Its job is to check to see if the range being integerised spans a day boundary. If it does, it breaks the range into two (or more) ranges as required.
At the end of the (double) loop @tally looks like this:
6 6 6 6 6 1 1 1 1 1 1 1 1 1 1 1 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 +6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 + 6 5 5 5 5 5 5 5 4 4 + 4 4 4 3 3 3 3 3 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3
And @id looks like this:
0 0 0 0 0 4 4 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 1 1 1 1 1 1 1 5 5 + 5 5 5 2 2 2 2 2 6 6 6 6 6 7 7 7 7 3 3 3 3 3 3 3 3 3
As you can see, we now have a list of the lowest value available for every minute of the period, and the index of the associated range that contributed it. Though the latter information is actually now redundant. Any minute that is not covered by any range has both value and ID as undef and shows up blank above.
All we need to do is walk our way down the tally stick and convert the start and end index minute of each contiguous range of values back to the corresponding day/hour/minute (int2dhm()) and we can construct the required list of output ranges, in sorted order, without any complex comparison logic.
In reply to Re^3: Date Array Convolution
by BrowserUk
in thread Date Array Convolution
by alanonymous
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |