7 kyu

Delta Bits

826 of 3,447ykagan
Description
Loading description...
Bits
Binary
Algorithms
  • Please sign in or sign up to leave a comment.
  • JohanWiltink Avatar

    Haskell translation

  • saudiGuy Avatar
  • akar-0 Avatar
  • 3au4onok Avatar

    The description says that you need to find the number of bits to convert the number

    Complete the function to determine the number of bits required to convert integer A to integer B
    

    But immediately describes that you can move the bits, then the description conflicts with itself

    In the example
    31  0 0 0 1 1 1 1 1
    14  0 0 0 0 1 1 1 0
    --- ---------------
    bit 7 6 5 4 3 2 1 0
    

    We must remove the bits after indices 0, 4 and insert new ones in their place, then the required number of bits is really two, but if we move the bits between each other, their number will remain the same

    Further in tests with numbers 7 and 17 we get '111' and '10001' where answer 3 is not entirely correct. Only the first bit matches, the rest must be replaced, and then the answer should be 4

  • ejini战神 Avatar

    No random tests in CS

  • ejini战神 Avatar
    • Node 18 should be enabled (Refer this and this for more info)

    • Ruby 3.0 should be enabled (Refer this & this for more detail)

  • Problemsolver2909 Avatar

    what are these numbers 0b1000000000000101011, 0b1110111110100100000001011010011 what does b means in this number

  • krishp Avatar

    This comment has been hidden.

  • stellartux Avatar
  • JohanWiltink Avatar

    ( JS, possibly others )

    "There are no upper limits for A and B."

    Good. But I then expect actual testing with numbers over 2**32, which means I'll have to arithmetic some other way than bitwise integer stuff.

    Fixed testing is done with 32-bit numbers. Random testing is done with 16-bit numbers. These are upper limits.

  • Unnamed Avatar

    to convert positive integer A to positive integer B

    But there are test with zeros in all languages. And there's no real reason for them not to be, so the description should probably be updated?

  • geeves Avatar

    This comment has been hidden.

  • SergeyOvchinnik Avatar

    Too easy for kyu 5, should be 6 or even 7

  • ReaL73 Avatar

    plz provide upper and lower bound

  • iamchingel Avatar

    nice kata! but i think it should be somewhere around 6kyu!

  • user5036852 Avatar

    Great kata with a nice idea! Thanx!

  • GiacomoSorbi Avatar

    Nice kata, though by current CW's standards I doubt it would be ranked 5kyu; any chance of getting the pending translations approved?

  • NeveezyBrah Avatar

    It would have been a little more helpful if the kata description specified that the numbers can use more than 7 bits, but great kata.

  • globalkeith Avatar

    This comment has been hidden.

  • hbakhtiyor Avatar

    C# translation submitted, kindly review & approve it.

  • pablo.varela Avatar

    This was an interesting kata. I have translated it to ```java``; feel free to merge it if you like the implementation.

    I have also added in this translation some random tests and some extra information to the tests output, I hope that is fine with you.

  • jacobb Avatar

    It would be pretty easy to add random test cases to this. You can get random numbers, though not large, from Test.randomNumber(). It should be enough to prevent any brute force solutions though.

  • OverZealous Avatar

    I think this is an interesting kata. There will be a few different ways to solve it.

    Some suggestions to improve it:

    • You have a mistake in your function setup: it's got the function name as convert, but your tests are testing convertBits.

    • Typo in description: interger A should be integer A.

    • Your description is rather bare. Having a visual example of the changes needed would be nice, something like:

      For example, given the numbers 31 and 14, which in binary are:

       31  0 0 0 1 1 1 1 1
       14  0 0 0 0 1 1 1 0
      ---  ---------------
      bit  7 6 5 4 3 2 1 0
      

      You can see you'll need to change bits 0 and 4, which means your function should return 2.

      When in doubt, spell it out. A longer, clearer description is better for those solving the challenge. :-)

    • This could definitely stand to have a few more tests, maybe even include the example in the test setup code. You can use 32-bit signed ints in JavaScript, so you can test up to 2^31-1 (31 bits).

    • You don't have any edge cases tested, such as testing the same number (so the result is 0). If you don't want to have edge cases, you should state that in the description.

    • On a related note, you should clarify if this is only going to test positive integers, since the two's complement of a negative integer is incompatible with my solution. (I think it would be more practical to only focus on positive integers here.)