Consider two lists of identical length:
t
is a list of irregular-intervals of times in seconds, arranged chronologicallypt
is a list of sequences of numbers 1,2,3 wsuch that a 1 is followed by a consecutive string of 2's, then followed by a 3.- 1 = start of event, 2 = continuation of event, 3 = end of event
- This means that for a single event, the sequence begins with a single 1, is followed by a consecutive string of 2s (how many times it repeats will vary), and finally ends in a single 3.
- There is more than 1 event contained in this vector
For example, the input could look like:
# |--Event #1-| |---Event #2----| |Event #3 |
pt = [1, 2, 2, 3, 1, 2, 2, 2, 3, 1, 2, 3 ]
t = [1, 10, 13, 14, 17, 20, 21, 25, 37, 32, 33, 38]
Is there a 1-liner that doesn't involve multiple nested loops that we could use that would calculate the difference in time values in t
for each event sequence in pt
?
For example, the desired output for the above inputs would be a list of length 3 (because there are 3 events) where the output is
Output: [13, 20, 6]
### Explanation:
# 13 = 14-1 = t[position where pt shows first 3] - t[position where pt shows first 1]
# 20 = 37-17 = t[position where pt shows second 3] - t[position where pt shows second 1]
# 6 = 38-32 = t[position where pt shows third 3] - t[position where pt shows third 1]