BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

Fun Coding Challenges / Questions


@bsvare wrote:

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


That could well be. I am running on a 16 core, dual Xeon system, so there is definitely more overhead if the compiler splits it across two CPUs. I assume that the synchronization across the MB is a slight bottleneck compared to doing everything on the same die. Not sure.

 

However, you need to be careful when comparing. Parallelized loops don't generate debugging code, so you need to compare the speed when debugging is disabled in both cases.

 

In my experience, lighweight loops such as this don't really benefit from parallelization.

 


@bsvare wrote:

 

Unless something has improved greatly, I thought the auto indexing output tunnels were extremely poor on memory efficiency .


 

No, for FOR loops the number of iterations is known when the loop starts and the output tunnel is initialized with the correct final size. Most likely the two versions (autoindexing vs. init-shift-replace) create nearly identical compiled code and are equally efficient. So stick with the simpler diagram. 😄

 

(Issues arise if you are autoindexing on the output tunnel of a while loop. That's a very different thing because the final size cannot be known so a new allocation needs to occur whenever the current alloocation guess is exceeded.)

 

 

 

 

0 Kudos
Message 41 of 53
(6,871 Views)

Another variation, about the same speed and even less code 😉

 

 

 

0 Kudos
Message 42 of 53
(6,866 Views)

@altenbach wrote:

Another variation, about the same speed and even less code 😉

 

 

 


Well, I'm glad I was very close to the best speed and the improvements found are just because if various compiler tweeks, not because of a major change in the method of solving. I didn't spend any real time to optimize the new algorithm, just to showcase it as a different (or better) way to solve the bonus question.

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 43 of 53
(6,854 Views)

I've been busy lately with a large project, and haven't had a chance to keep this up.  Luckily it is winding down a bit, so... here is the next challenge!  Since (my guess is) we all come from STEM type backgrounds I thought this one might be fun.

 

Again, it was shamelessly stolen from https://www.reddit.com/r/dailyprogrammer/comments/4fc896/20160418_challenge_263_easy_calculating_sha...

 

Description

Shannon entropy was introduced by Claude E. Shannon in his 1948 paper "A Mathematical Theory of Communication". Somewhat related to the physical and chemical concept entropy, the Shannon entropy measures the uncertainty associated with a random variable, i.e. the expected value of the information in the message (in classical informatics it is measured in bits). This is a key concept in information theory and has consequences for things like compression, cryptography and privacy, and more.

The Shannon entropy H of input sequence X is calculated as -1 times the sum of the frequency of the symbol i times the log base 2 of the frequency:

            n
            _   count(i)          count(i)
H(X) = -1 * >   --------- * log  (--------)
            -       N          2      N
            i=1

(That funny thing is the summation for i=1 to n. I didn't see a good way to do this in Reddit's markup so I did some crude ASCII art.)

For more, see Wikipedia for Entropy in information theory).

Input Description

You'll be given a string, one per line, for which you should calculate the Shannon entropy. Examples:

1223334444
Hello, world!

Output Description

Your program should emit the calculated entropy values for the strings to at least five decimal places. Examples:

1.84644
3.18083

Challenge Input

122333444455555666666777777788888888
563881467447538846567288767728553786
https://www.reddit.com/r/dailyprogrammer
int main(int argc, char *argv[])

Challenge Output

2.794208683
2.794208683
4.056198332
3.866729296

 

0 Kudos
Message 44 of 53
(6,437 Views)

Cute attempt in 10 minutes... maybe I didn't understand the question or why the values are challenge, but the results are so fast on my computer, it doesn't register in time. The results also match.

 

Spoiler
Round4.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 45 of 53
(6,433 Views)

Not that hard.  I'm sure somebody can make some improvements though.

Spoiler

GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 46 of 53
(6,429 Views)

@bsvare wrote:

Cute attempt in 10 minutes... maybe I didn't understand the question or why the values are challenge, but the results are so fast on my computer, it doesn't register in time. The results also match.

 


Interesting use of variant attributes. I'm not sure I would have even considered that...

0 Kudos
Message 47 of 53
(6,419 Views)

BowenM wrote: 

 

Interesting use of variant attributes. I'm not sure I would have even considered that...


Variant Attributes have been used as a poor man's Associative Array (a.k.a. Dictionary/Map) for a long time now, since LabVIEW doesn't provide a native one:

Certified LabVIEW Developer
Message 48 of 53
(6,334 Views)

I figured since I contribute here enough, that I can also contribute a question:

 

The smallest number evenly divisible by 1 thru 5 is 60. The smallest number evenly divisible by 1 thru 10 is 2520. What is the smallest number evenly divisible by 1 thru X where X is any number between 1 and 40?

 

 

 

Bonus points for innovative solutions and for speed.

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 49 of 53
(6,206 Views)

What about bonus points for speed of implementation? 😉

 

Spoiler
lcm.png

 

0 Kudos
Message 50 of 53
(6,197 Views)