Ad
  • Custom User Avatar

    Exactly, that was my point. This kumite needs new test inputs

  • Custom User Avatar

    Correct, this will return False if it is odd and True if it is even. I've seen some more complex mathematical methods to detect if it's a power of two with just simple arithmetic but what would probably be easiest is to import Math and do return False if math.log(n, 2)%1 else True

  • Custom User Avatar

    I think this checks if a number is odd, not if it's a power of two. For example, 12 % 2 is equal to 0, yielding True but 12 is not a power of two.

  • Default User Avatar

    thank you ,this is good way

  • 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

  • Custom User Avatar

    Am i mistaken or does this only check if the number is even and not odd, but does not check if it's a power of two? For example

    power_of_two(6)
    True

    I guess the test cases only test odd numbers for the False test case and thus the test cases work fine.

  • Custom User Avatar

    Absurd solution, congratulations

  • Custom User Avatar