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.
Checking if the string length is odd is an obvious disqualifier that I didn't think to check for. Good call!
Can you explain how did you derive p and where does 210 come from? Thanks!
Can you please explain the solution?
Can you explain the math behind it?
Nice one, I like the clean use of comparators
Definitely not a 5kyu, 7 at most.
I disagree with your "really bad solution" comment and encourage anyone interested in learning more about processing data with functional programming to read Martin Fowler's Refactoring to Collection Pipelines
A similar multi-stage pipeline approach is covered in the above article where Fowler refactors a loop that does multiple things in one pass into separate loops that each process the content with a different purpose. Fowler's article hits a number of different languages including c#, java and in this section, Ruby. In this section, he's quite clear with the section where he does this he introduces with the following:
Although he is using his "split loop" refactoring here, he ultimately transforms those loops into list processing functional programming calls. My point in citing his article is that he not only calls a loop that is doing multiple things at once a smell, it is the biggest smell for him in the code he is refactoring.
A fair comment. The longer the string, the more time is saved by checking for these easy cases upfront.
This is actually really bad solution, you should never iterate over array 3 times if you can do it once. You should know when to use functional programing and when just a simple for loop.
Nice one, although you don't need to iterate if the string doesn't start with "(", ends with ")" or its length is odd, just a small improvement for some cases.
This comment is hidden because it contains spoiler information about the solution