02-23-2016 03:56 PM - edited 02-23-2016 03:57 PM
@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.)
02-23-2016 04:02 PM
02-23-2016 04:40 PM
@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.
"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
04-26-2016 03:15 PM
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
04-26-2016 03:33 PM
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.
"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
04-26-2016 03:43 PM - edited 04-26-2016 03:43 PM
Not that hard. I'm sure somebody can make some improvements though.
04-26-2016 04:35 PM
@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...
04-27-2016 08:56 PM - edited 04-27-2016 08:58 PM
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:
05-04-2016 09:33 AM
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.
"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
05-04-2016 10:22 AM