08-14-2015 12:33 PM
I ran a benchmark on my code vs Crossrulz' code. It resulted in my code being about 30% faster. Crossrulz will also go slower if your array input gets bigger because there is more logic within each iteration.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
08-14-2015 12:44 PM
@James.M wrote:
1. Instead of the rotate, I think I would just use a Delete From Array to eliminate the first element.
2. Your code only really works if the first element and last element are different. The Delete From Array part should fix that, somewhat. Still need to think about the final element somehow.
3. Instead of subtracting, just use Equals. That will also eliminate the need for the Not Equal To 0 node.
08-14-2015 12:56 PM - edited 08-14-2015 12:56 PM
OOps misread the post
08-14-2015 01:23 PM
@crossrulz wrote:
1. Instead of the rotate, I think I would just use a Delete From Array to eliminate the first element.
2. Your code only really works if the first element and last element are different. The Delete From Array part should fix that, somewhat. Still need to think about the final element somehow.
3. Instead of subtracting, just use Equals. That will also eliminate the need for the Not Equal To 0 node.
Ooo good catch. Using a comparison instead of the Subtract sped it up by a little bit.
I'm trying to get the logic to work when the first and lest index don't match without adding too much processing.
While doing this, I noticed yours has a problem too. If you add a single "1" to the end of the array, yours adds another element to your Zero output instead of your One output. If you add two 1s, it works just fine.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
08-14-2015 01:27 PM
James.Morris wrote:While doing this, I noticed yours has a problem too. If you add a single "1" to the end of the array, yours adds another element to your Zero output instead of your One output. If you add two 1s, it works just fine.
Yep, I wire the output tunnel to the wrong side of the Feedback Node. Oh well.
08-14-2015 01:38 PM
Yup, that fixed it.
Anyways, I've spent way too much time here. walidbalid, you can figure it out from here. Crossrulz code gives you the end results accurately. If it is really going take a long time, you can give my code a shot, but just make sure your input array has opposing first and last values.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
08-14-2015 01:58 PM
How fast does this conditional accumulation work? It is not regular autoindexing (for loop does not know end size), so will you end up with build array in a loop with indefinite size? Or is it equal to initialize full array, then delete remaining portion?
08-14-2015 02:04 PM
@Alexander_Sobolev wrote:
How fast does this conditional accumulation work? It is not regular autoindexing (for loop does not know end size), so will you end up with build array in a loop with indefinite size? Or is it equal to initialize full array, then delete remaining portion?
The autoindexing FOR loop allocates the maximum sized array based on how many times the loop could run. When using conditional, it just throws away what was not needed once the FOR loop is complete. It is VERY effecient.
08-14-2015 02:09 PM
I haven't timed anyone else's code (could someone post the times?), but decided that I should "enter the race". Since the length of the strings is given as "very long", I generated 10 million arrays of length between 1 and 10 (uniformly distributed), alternating between True and False (I used Booleans instead of Ones and Zeros). This took about 4 seconds, I then created a single array that counted the sizes of the "runs" (not surprising, but the size of this array was 10 million, and its sum was the size of the Big Boolean Array). Doing this took about 0.48 seconds. Splitting this array into Trues and Falses added about 0.14 seconds to the time.
I also tried it for 100 million "runs", but LabVIEW gave me an Out of Memory error. I could go up to 30 million, and it took three times longer (at least it scales linearly!).
Before I post it, I'm going to try to time it against some of the methods posted, and won't bother if I finish dead last ...
Bob Schor
08-14-2015 02:23 PM
Bob_Schor wrote:
Before I post it, I'm going to try to time it against some of the methods posted, and won't bother if I finish dead last ...
Don't take that attitude. This is not a competition. Go ahead and post what you got. It might give somebody an idea and then everything will blow wide open. Either that or we learn something as we poke big giant holes in it.