Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Thanks for the reply -- good thoughts, I agree there is a balance between optimization, readability, development time, etc!
Ah, good point. If optimization was requred for that kata, I likely would have used set or some other implementation. I saw a few other solutions using the "Counter" data structure to do it all at once. I'm not entirely certain as to the time efficiency difference between the methods, but I'm sure it'd be an improvement.
As I've spend more time here on codewars and programming in general, I've also came to the realization that time efficiency isn't as important as the CS classes make it out to be in most situations. Optimization is rarely a bad thing, but it's frequently not worth the time investment when it's not needed. Especially if it sacrificies the readability or simplicity.
I've found that I get the most out of my time by starting with code that is the most readable and simple, and optimizing it as needed. Your suggestion was a good idea though, since set is a commonly used data structure. I tend to avoid using methods that would over complicate the code when it's not needed. I used to do the opposite and endlessly refactor my code until I felt it was near perfect.
Thanks for the feedback! It's fairly uncommon for people to leave a comment on code solutions (especially the ones that weren't the most upvoted), but I always welcome constructive criticism (:
When you set up your dicts, you iterate through (and re-compute count() for) every character in every string. The strings could be very long. Iterating through each possible letter in the lowercase alphabet would have a fixed number of iterations regardless of the length of the input strings.
(I saw other solutions using set() to potentially limit the iteration to the subset of the alphabet actually appearing in the input strings.)
When you set up your dicts, you iterate through (and re-compute count() for) every character in every string. The strings could be very long. Iterating through each possible letter in the lowercase alphabet would have a fixed number of iterations regardless of the length of the input strings.
(I saw other solutions using set() to potentially limit the iteration to the subset of the alphabet actually appearing in the input strings.)
In the description of the distance metric
Distance = (sqrt((0-4)^2 + (0-3)^2) + sqrt((0-4)^2 + (1-2)^2)) / 2
should the
(1-2)
near the end actually be(1-3)
to match the example pointCluster 2: (4, 3)
?OK, but what if the original song contained the consecutive characters "WUB" somewhere? I don't believe that could be decrypted successfully once encrypted based on the description here.