BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

Fun Coding Challenges / Questions


@bsvare wrote:
Didn't spend any longer this time, though, it's not the most optimized. Certinally doesn't work well with the bonus points.

My initial implementation was very similar to yours, but isn't nearly fast enough for the bonus.  The bonus though is far more difficult than I thought it would be.

 

I've been playing around for about an hour trying to come up with something that will solve the bonus in a couple of seconds.  No luck yet!  I'm curious to see if anyone will get the bonus.

0 Kudos
Message 31 of 53
(7,047 Views)

Here's my brute force attempt. Yes it is slow but avoids allocating intermediary arrays and simplifies a few other things.

 

 

Spoiler
 

 

0 Kudos
Message 32 of 53
(7,032 Views)

It's actually an order of magnitude faster doing the boolean sub-arrays, so yes, my initial assumption was wrong.

 

 

 

 

 

 

0 Kudos
Message 33 of 53
(7,022 Views)

@altenbach wrote:

It's actually an order of magnitude faster doing the boolean sub-arrays, so yes, my initial assumption was wrong.

  


 

Yea, your first solution was almost identical to mine (I didn't use DVR), but it was slow.  I've been playing around with using an array if integers instead of an array of boolean.  (Boolean = 1 bite, using integers I can theoretically toggle bits instead of the first bit in each byte).  I haven't gotten it working yet though.  I'll play with it tomorrow - I'm out of "goof off time" for the day 🙂

 

If anyone has any other ideas for optomization, I'm open.  If a Python solution can execute in 1.5 seconds, surely we can do it in LabVIEW...!

0 Kudos
Message 34 of 53
(7,018 Views)

@BowenM wrote:

@altenbach wrote:

It's actually an order of magnitude faster doing the boolean sub-arrays, so yes, my initial assumption was wrong.

  


 

Yea, your first solution was almost identical to mine (I didn't use DVR), but it was slow.  I've been playing around with using an array if integers instead of an array of boolean.  (Boolean = 1 bite, using integers I can theoretically toggle bits instead of the first bit in each byte).  I haven't gotten it working yet though.  I'll play with it tomorrow - I'm out of "goof off time" for the day 🙂

 

If anyone has any other ideas for optomization, I'm open.  If a Python solution can execute in 1.5 seconds, surely we can do it in LabVIEW...!


But even if we could operate on 64bits concurrently (except for some edge cases which would need a bit more code), it would not speed things up sufficiently to account for the difference. I think we need to fundamentally change the approach....

0 Kudos
Message 35 of 53
(7,013 Views)

@altenbach wrote:

But even if we could operate on 64bits concurrently (except for some edge cases which would need a bit more code), it would not speed things up sufficiently to account for the difference. I think we need to fundamentally change the approach....


I guess that makes sense.  It would speed things up, but I'm not sure it would drop us down to the 2 second range.  I just attempted a solution that stored an array of just the lights that were "On".  Searching the array for a specific light was (unsurprisingly) too slow once the array got larger than a few thousand entries.  I'll keep thinking about it...

0 Kudos
Message 36 of 53
(6,944 Views)

Bonus Points Round: 185 ms for the bonus file on my computer.

 

Spoiler
Challenge3Bonus.png

 

Certified-LabVIEW-Architect_rgb.jpgCertified_TestStand_Architect_rgb.jpg


"I won't be wronged. I won't be insulted. I won't be laid a-hand on. I don't do these things to other people, and I require the same from them." John Bernard Books

Message 37 of 53
(6,927 Views)

Cool!

I actually made a very similar one yesterday, including the sorting and +1 on the off times, but there was a bug and I had no time to troubleshoot later.

 

I think there is still some slack left, though. 😄

 

0 Kudos
Message 38 of 53
(6,919 Views)

@altenbach wrote:

I think there is still some slack left, though. 😄


Here's a 5 minute rewrite that gives the same result but is about 20% faster (and significantly simpler code ;))

It seems parallelization makes little difference.

 

It is your code verbatim and I have not verified that it is actually correct. 😄

Message 39 of 53
(6,910 Views)

There was about a 10ms improvement using parallelism in my code (from 195 to 185). Minor, but still notable.

 

Unless something has improved greatly, I thought the auto indexing output tunnels were extremely poor on memory efficiency . I thought it had to recreate the output array each time something was added. Thus why I attempted to do the value updating into an pre created array. Assuming the best optimization of the arrays, it should be able to determine the final array size and index it properly, or do exactly what I explicitely did.

 

As for the min/max vs array sort, My first attempt was to get the two values and do a compare what is greater, and then use the Swap value primitive. However, I found that sorting the array and then just getting the two values to be faster. I didn't test min/max. That may be the sole cause of the 20% speed increase.

 

 

 

As for the code being right,  I did verify it produced the same number of lit bulbs as all three problems would using the old methods.So I'm assuming it's right.

Certified-LabVIEW-Architect_rgb.jpgCertified_TestStand_Architect_rgb.jpg


"I won't be wronged. I won't be insulted. I won't be laid a-hand on. I don't do these things to other people, and I require the same from them." John Bernard Books

0 Kudos
Message 40 of 53
(6,900 Views)