Ad
  • Default User Avatar

    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

  • Default User Avatar

    This kata definitely consists of two tasks:

    1. Figuring out, what bad means.
    2. Solving performance issues.

    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.

  • Default User Avatar

    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?

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    I don't want to be intrusive, but i would really appreciate any comments about the translation. Thanks in advance.

  • Default User Avatar

    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.

  • Default User Avatar

    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.

  • Default User Avatar

    Swift translation
    This is my first attempt to translate a kata on Codewars. Please review and let me know about the problems. Thanks.

  • Default User Avatar

    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.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    Thanks, now everything is fine, and I solved the kata.
    BTW, it's interestig and fun, but WAY too easy for 4 kyu, IMHO.

  • Default User Avatar

    After resetting the solution I press the Run-Sample-Test button and get:

    Traceback (most recent call last):
      File "main.py", line 1, in <module>
        from solution import *
      File "/home/codewarrior/solution.py", line 2
        @classmethod
        ^
    IndentationError: unexpected indent
    

    What am i doing wrong?

  • Default User Avatar

    I totally agree, it's way too easy for 4 kyu.

  • Default User Avatar

    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.

  • Default User Avatar

    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...