Ahh, I see. I was mis-interpreting your use of `onsets` and `offsets`. In that case I think you'd only have to add extra checks for `[0, 0, 0, 1, 1]` and/or `[1, 1, 1, 0, 0]`-type cases. And your solution is better than mine :)