6 kyu
The OR sum
58 of 69Yushi.py
Loading description...
Mathematics
Bits
Performance
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.
Haskell translation
Approved, thanks!
This comment has been hidden.
Because we're not looking for
1 | 2 | 3 | ... | (n-1) | n
.The problem wants you to calculate
(n | 1) + (n | 2) + (n | 3) + ... + (n | (n-1)) + (n | n)
ohhh sh- okay. well, uh, thats kinda dumb
Cause it that was the case, the answer would be
(1 << n.bit_length()) - 1
, which is too easy for6 kyu
, lol.oh look at that, finally completed it!
Only 6 kyu? It seems quite tricky, maybe if I manage to solve it, I'll understand why it's only 6 kyu but right now it definitely feels harder.
It really depends on your mathematical background. If you're familiar with sequences and bitwise operations, it's quite trivial. Otherwise, it can take you quite a while.
Good luck solving it though, I hope you figure it out :)
There's a similar kata already, not exactly a duplicate though:
https://www.codewars.com/kata/56d3e702fc231fdf72001779
upd: nevermind, I think I misunderstood this one!
I wouldn't even call these kata's similar. They are however remotely related in that both require a sum of some bitwise operator.
Exactly. After reading this one more carefully, I see that they are very different.
JS translation
Wow, it's quite rare for me to have a kata without any issues and only a translation in the discussion section.
I find it quite amusing how you defined the Python exclusive functions in JS, like
randint
andrange
. I feel like the things I do in Python may not be the best or easiest to implement in other languages.Anyways, I was looking through the translation, and it looks fine. I just thought it's weird that, in the random tests section, it states that each batch of
10
or20
tests is only1
test.Looking more into it, it seems to work as intended for passing cases, breaking early upon a fail. I just wanted to know if that's intended. It's just a bit weird for me to see
35
passed tests in a passing solution if100
random tests were stated.I just want to clear up this confusion of mine, and then I'll be sure to approve it. Thank you very much for the translation :).
Yep, it is correct that there appears to be less random tests than there really are. Each batch fails early on first test that fails. I could change that if you want. In fact, since there are only 10 - 20 tests in each batch, I could run them all, regardless of early failure. Lemme change that.
I changed the random tests. Could you verify?
It was fine the way it was; I just wanted to make sure it worked as intended. But it's good the way it is now as well.
Just one thing: aren't you missing the Special tests? They aren't all that important, and I could remove them if you think they're unnecessary, but I'd say it's good to have all versions be consistent with the tests.
ah yes, there are special random tests too. I only just noticed. Lemme add them ..
special cases added
Yeah, it all looks good now. Sorry for being annoying, I just wanted to ensure that all versions were consistent. Thanks you very much.