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.
Unfortunately, this is not tail-recursive. All of the intermediate calls need to be kept on the stack because they still have work to do, specifically: adding 2 to the result of the recursive call they are waiting on.
Tail recursion gets optimized at compile time anyway.
The example matrix transformations in the instructions don't match the unit tests.
Thanks, this was fun! Regards, suic
Yes.
Right.. <_< but didn't.. you... write the Python translation?
;)
It's nice if the kata mentions efficiency in the desription (e.g. "0 < input size <= 10^5"), but this is a pretty reasonable test suite I think. Enjoyed the kata!
This comment is hidden because it contains spoiler information about the solution
As for why so many people marked it as "Best Practice"... maybe they liked the variable names and spacing between lines?! Just kidding. I'm guessing they just didn't realize there was a better way. Or they exhibited mob behaviour - once it has a few upvotes others upvote to go with the crowd.
@sheriv, it's not one iteration. For each index he's checking he sums up all the numbers on the left and all the numbers on the right. He's forcing the CPU to do the same calculations over and over, and to solve this it's unnecessary. For example if you are at an index and already know the left and right sums at that point, you only need to remove one element and add one element to check the neighbouring index - but the solution above has the program recalculate the entire sum on both sides. It's functional but it's not elegant or efficient.
I think I did it the complex way, lol. But.. mine could easily be modified to work for any rotation of rectangle and any length of sides and it should still work. So there's that.
This comment is hidden because it contains spoiler information about the solution
I was going to reply with these same critiques but I see someone else beat me to it. Anything using streams tends to look clever but there's no excuse for calling the same function twice for the same values. It's even called here a third time for every number that's a factor.
And here I thought my solution was elegant. Noice!
Finally the same solution I found is the top one! All of the other problems I solved had solutions by other people that were way better, lol. I did go with the StringBuilder as others have mentioned but the difference is kind of trivial. That would just be an efficiency upgraded needed when dealing with larger datasets.
Loading more items...