7 kyu
Delta Bits
725 of 3,447ykagan
Loading description...
Bits
Binary
Algorithms
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Lua translation!
Haskell translation
python new test framework
Approved
Rust translation
approved.
The description says that you need to find the number of bits to convert the number
But immediately describes that you can move the bits, then the description conflicts with itself
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
In bit-wise operations, we start off from the end (right) of bits, not from the start (left). Also, it is not moving the bits, but flipping the bits.
No random tests in CS
Node 18 should be enabled (Refer this and this for more info)
Ruby 3.0 should be enabled (Refer this & this for more detail)
JS version has been updated ( thank
@Hobs
, not me )Ruby 3.0 enabled in this fork
what are these numbers 0b1000000000000101011, 0b1110111110100100000001011010011 what does b means in this number
the
0b
in front means "binary", the rest of the numbers are a binary representation of a numberokay Thankyou tell me how to delete my comment using mobile device
you can only delete a comment if it's the first in a thread and has had no replies
ok
This comment has been hidden.
When
a = "011"
andb = "01"
,your solution compared them as0 vs 0 and 1 vs 1
but it should be0 vs 0, 0 vs 1 and 1 vs 1 (011 & 001)
NASM translation and C translation
Approved
( JS, possibly others )
"There are no upper limits for
A
andB
."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.
Never settle, right? ;-)
Obviously there can't be no upper limit as you can't provide 2 infinities as input and expect the user to compare them.
Haskell actually has arbitrary precision integers - limited only by resource limits. Those effectively have no upper bound. ( Your hardware is just inadequate. )
Description updated
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?
Description updated
This comment has been hidden.
This comment has been hidden.
Too easy for kyu 5, should be 6 or even 7
It's harder if you're not good with binary.
Re-ranked to 7 kyu
Seriously ?! 7kyu ?
plz provide upper and lower bound
Not necessary. There's a simple trick that makes it lightning fast.
That being said, the lower bound is effectively 0.
nice kata! but i think it should be somewhere around 6kyu!
Great kata with a nice idea! Thanx!
Nice kata, though by current CW's standards I doubt it would be ranked 5kyu; any chance of getting the pending translations approved?
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.
When no upper bound is given, you should assume the numbers may run up to an indefinite number of digits.
Description updated
This comment has been hidden.
George lives on the ground and wants to send a number in binary to Isaac in the ISS by painting giant dots in his yard. Thankfully, George and Isaac have done this before, so George's yard already has a bunch of dots painted. Each dot will take a single bucket of paint to change. Given George's yard's current number in decimal and the target number in decimal, how many buckets of paint should George buy total?
C# translation submitted, kindly review & approve it.
Kindly go through this tutorial for approving
Was already done
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.
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.
Added random tests to python and ruby. C# and Java already had them.
JS and CoffeScript is still lacking.
Added in JS.
Reraised as issue
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 testingconvertBits
.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:
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.)
Thanks, this is my first published Kata so I'm still getting a hang of this. Updated with your suggestions.
Awesome, looks great! Good job on your first kata! I look forward to more. :-)
OK, new problem with your test cases. You are testing a number that is too large in the last case,
2709989843
. The maximum positive integer that can be represented in JavaScript as an int32 is2147483647
(which is2^31 - 1
). The number you have is actually-1584977453
in binary/int32, since it's converted to two's complement:Fixed again. I suppose I could allow arbitrarily large numbers, but that would essentially limit the solution to string comparisons, which seems less interesting.
Cool. Thanks for fixing it.