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.
Yeah, you're right. At some point this kumite changed into testing whether or not the number is even.
As for the power_of_two, I think that the first solution was the best one:
return n & ( n - 1 ) == 0
This kata definitely consists of two tasks:
First part is a nice puzzle. As for the second one, it's pretty easy to come around with a fixed array of bad integers. This array can either be hardcoded or calculated outside of the function. Both these ways feel like cheating to me.
So it's kinda weird: you have some performance problems to deal with, but they can be solved with the same computational complexity (linear) as the dumb algorithm, just changing the order a little bit.
IHMO, you should either remove the performance part from this kata (so that the stupid solutions like
sum(1 if is_bad(i) else 0 for i in range(a, b+1))
work), or require a solution of logarithmic complexity.Or maybe you can split this kata in two: the first one will be very simple allowing the most obvious solution, but the second one should pose the performance problem to its full.
Some user came up with pretty clever solution using
eval
. While it is really cool, I feel like it goes agains the spirit of this kata. Maybe you should prohibit using ofeval
too?This comment is hidden because it contains spoiler information about the solution
I don't want to be intrusive, but i would really appreciate any comments about the translation. Thanks in advance.
In Swift version the test does forced unwrapping of the result of the function without testing it to nil, which can lead to a runtime error. It's hard to understand what is going on in this case. You should compare the result to nil before unwrapping it.
Swift version. I added return [] to the body and tried to run. The result was:
Assertion failed: file setup.swift, line 4
Looks like the test is broken.
Swift translation
This is my first attempt to translate a kata on Codewars. Please review and let me know about the problems. Thanks.
This solution was tested on 10_000 random values
The result was expected to be the same, as my C++ solution.
This is my first translation, so if i've done any mistakes, please let me know.
This comment is hidden because it contains spoiler information about the solution
Thanks, now everything is fine, and I solved the kata.
BTW, it's interestig and fun, but WAY too easy for 4 kyu, IMHO.
After resetting the solution I press the Run-Sample-Test button and get:
What am i doing wrong?
I totally agree, it's way too easy for 4 kyu.
The two pass solution, which is mentioned in the description of the kata, is probably the most efficient, and it's not that hard to come up with, IMHO.
Very clever and interesting kata, enjoyed it a lot, thanks to the authors.
But it's a little easy for a 3 kyu, isn't it?
Loading more items...