04-20-2017 08:40 AM
Hello,
Thanks for all your help so far and I apologize for misleading you. I had no intention to do so because I wouldn't benefit from it.
As I look at the code, I get how the loop index each iteration values when the 2nd conditional terminal is false to get the false index values.
I get how when the 1st conditional terminal is false, it takes the old val from shift register + 1 and index those values as all the true before a false.
Same goes for the values of "true after a false" only you subtract all the values of "True after a false'' from all values of "True before a false".
now to modify the code to make it stop counting when it reaches a false, I am clueless. I spend some good time on it. Please help if you can
04-20-2017 09:55 AM - edited 04-20-2017 09:55 AM
Well, one way to do it, the number of trues after a false will also be the number of trues before a false, if you shift the array by -1. But then you need to deal with the edge cases.
04-20-2017 10:10 AM
@aputman,
wouldn't that only shift my result by -1?.... that's without account for edge...
04-20-2017 10:25 AM - edited 04-20-2017 10:25 AM
@ritch_by_nature wrote:
now to modify the code to make it stop counting when it reaches a false, I am clueless. I spend some good time on it. Please help if you can
This is a good exercise, so here is a partial solution that shows how to count only the near TRUEs before the FALSE. You simply need to reset the counter and keep its most recent value as long as the boolean is FALSE. (I assume that you want to keep returning the same value even if there are multiple FALSEs in a row).
It would be trivial to add the "after" count. The most obvious solution would be to reverse the boolean array and then reverse the result, but there are plenty of other ways. Try it!

04-20-2017 10:31 AM
@ritch_by_nature wrote:
wouldn't that only shift my result by -1?.... that's without account for edge...
Only if there are never more than one FALSE in a row. For example, if the array is:
T-T-F-T-T-T-F-F-F-F-F-T
The before's are: 23333
The after's are: 31111
Clearly not just a shift. 😄
04-20-2017 10:33 AM
So this is what I meant by shift the array. I'm taking a subset of the array starting at index 1. The only problem with this is that the last value in your results array will be wrong, if the last value in the boolean array is a true.
04-20-2017 10:40 AM
@aputman wrote:
So this is what I meant by shift the array.
It depends on the expected behavior of there are multiple FALSE in a row. Should e.g. the second FALSE return zero (because there are no adjacent TRUEs before) or should it return the count of the closest stretch of TRUEs below.
04-20-2017 10:54 AM
(I assume that you want to keep returning the same value even if there are multiple FALSEs in a row).
Yes I do.. if there is TTFFFFFFFFT. The first false would be 2, 1...same for the others consecutives falses.
04-20-2017 11:07 AM
@ritch_by_nature wrote:
(I assume that you want to keep returning the same value even if there are multiple FALSEs in a row).
Yes I do.. if there is TTFFFFFFFFT. The first false would be 2, 1...same for the others consecutives falses.
Yes, that's what my code does. Follow my suggestion and you also get the "after" counts. 😄
04-20-2017 12:15 PM
Has this been solved? There's a lot of correspondence. It's kind of difficult to follow.