7 kyu
Shared Bit Counter
259 of 2,353Anarki
Loading description...
Fundamentals
Binary
Bits
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.
COBOL translation.
approved
Ruby 3.0 should be enabled, read this to learn how to do it
Please organize the structure of test fixture as following (although it has been mentioned in the attached link, I'm repeated here again)
Enabled in this fork
I've forked the Rust translation in order to update it to Rust 1.49 and updated
rand::Rng::gen_range
to its new signature that takes astd::ops::Range
.Good kata!
I see this in the python test cases: (16, 8 -> False) Why is this False? 16 => 10000 8 => 01000
This comment has been hidden.
My bad, sorry!
This comment has been hidden.
The reason I included the "positive" clause was to avoid confusion around sign-tracking bits. So changing descriptions to "non-negative" would be the easiest solution.
I'm more interested in the correct solution. It sounds like you always intended "non-negative".
It makes things a lot easier if you get this correct before you have ten or so languages!
I'll update Haskell after the description is updated. Description is leading IMO.
Fixed
Python random tests expect
0
sometimes. While this does evaluate toFalse
, the expected output should nonetheless be consistent.Got it, nice little Kata!
I wasn't able to replicate this issue. Regardless, I've wrapped the sample solution in a
bool()
cast, so things should be consistent now. Let me know if it still misbehaves.@Anarki it's coming from this in the return statement of the reference solution:
It shouldn't have happened, but the Python translation does not conform to "numbers are positive" either.
ETA: wait, the original doesn't either :/
Ruby translation kumited with updated description -- please check and approve.
"Description cannot be approved, recent changes from related record must be merged first."
We had this on another translation... the only fix was to re-create the translation from scratch :/
No, you simply have to fork it.
forked Ruby translation
Thanks, and sorry about the confusion. I've never had people translate my Katas before, and now I'm juggling conflicts and updates and translations all at once.
Welcome to authoring kata ..
This is a recurring problem: this always happens when the description is changed, either in the editor or by other translations ( which is unavoidable when the description contains language-specific sections ), while translations are pending ( actually even when the translation was started before the change was made ).
I don't know if it is documented anywhere. If not, maybe it should. ( Then again, who would read it? ).
In a docs-to-be it's hinted in authoring guidelines and in explanation of translations but I am thinking how to improve this section and describe it in more details.
If this function is meant to simply return a boolean value, why are some test cases implying that the correct output should result in 0? I'm assuming zero should only be returned if no two numbers share a bit? Attempting in python3..
@rowcased pointed this out too. I've put in a fix that should prevent this from happening.
Haskell translation
This translation includes the description fix for "at index 3" that got reverted by the Prolog translation.
( If you change the description before approving this translation, the translation will break. )
Approved
Prolog translation
Approved
C++ translation rekumited.
Has 50 false & 50 true random tests.
Why 7 and 10 is false if 7 => 111 10 => 1010
index 0 and 2 share the "1" so the premise of "returns true if 2 integers share at least two '1' bits" is true???? thx
In the background all numbers having zero padding. You don't get to see it, but a byte is 8 bits long, so even though 7 might look like
111
, the code "sees"0000 0111
."Indexes" actually have nothing to do with binary comparisons, they were just a convenient way of pointing to specific elements of a binary number.
thanks for this explanation. as someoen whose tyring to learn "programming" with no real cs background this one kept screwing me up.
eventually i deduced when i looked at the solutions bc people were adding 0s when lens werent the same that something about how i was implementing bin() was wrong.
yeah, keep on studying other people's code, this is one of the best features of codewars!
OP solved it closing ~~
hi,
that part of the description is unreadable. Plz use either:
I thought I'd fixed that... somehow the Python translation didn't propogate. Should be fixed now.
( JS, possibly others )
Submit testing relies on random tests only. There should be fixed tests for edge cases.
This has been fixed. Could you check and approve? fork
Lots better. Still missing fixed cases with all (!) combinations of
0b00, 0b11, 0b0101, 0b1010, 0b1100
, which will include the more obvious edge cases.As mentioned below, I can't approve, sorry.
( JS, possibly others )
Please do not show
1000
it
-headers. Webbrowsers do not like that. Collapse that into a single header. No, for succeeding tests we do not need to know what just happened.This has been fixed. Could you check and approve? fork
Lots better, thanks.
I can't approve unfortunately, author will have to do that.
Approved
seven and ten share only a single '1' (at index 3)
[0,1,1,1] - 7 [1,0,1,0] - 10
=> seven and ten share only a single '1' (at index !!2!!) ????????
Good catch. Fixed.
(7, 10) ['1', '1', '1'] ['1', '0', '1', '0'] why is this one supposed to return False?
[0,1,1,1] - 7 [1,0,1,0] - 10
ohh ok thanks. it worked
why 7 binary is 0111 and not 111???
Because you need to add padding of zeros to shorter number's LEFT. With regular numbers, 50 + 2 == 50 + 02, not 50 + 20, right?
Exactly. You don't get to see it, but a byte is 8 bits long, so even though 7 might look like
111
, the code "sees"0000 0111
fuuuck how do you know that stuff?! jesus christ i suck... thx, i have a beginner code but well, i cant do more funcy code.
You don't suck, I just have an unfair advantage (7 years of formal Computer Science education, and 15 years of programming practice).
Everyone starts knowing nothing. You're doing the best thing to learn-fast: practice, plus feedback from people who've been there before you ^_^
thanks for your words i'm having a rough time...specially that i am 5 kyu and still is super hard doing 6kyu or even 5...
The students I teach will often have trouble even on 7th & 8th kyu problems for the first few months. The problem is usually several things happening at once:
Most of these come with practice. When I was starting I personally found that drawing on a piece of paper helps (use arrows, pictures, words, anything - the goal is to solve the problem in a way you can understand, and then translate it into JS/Python/C later). Also, have a quick Google for "Javascript cheatsheet" (or whatever your prefered language is): they are usually really nice lanuage summaries, which can help with points 2 and 3.
C Translation kumited.
Approved
JavaScript translation. Please, review and approve.
MY POOR WEBBROWSER !!
Do not show
1 000
it
-headers.Unrelated, do not rely on random tests only ( these issues may not be unique to this translation ).
Python translation. Please, review and approve (the author may be inactive).