7 kyu
Single digit
1,701 of 3,001hamurai
Loading description...
Binary
Fundamentals
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.
This comment has been hidden.
Not a kata issue, print the input to debug your code. Read this: https://docs.codewars.com/training/troubleshooting/
Help I have this error message
Should return a single digit integer expected 1 to equal 8
In advance thank you for your time !! I'm supposed to deliver the 1 but where to get the 8
This test (
test.assert_equals(single_digit(1), 8)
) doesn't exist. For the input 1, the result is 1. Maybe you should reset the test page (pushreset
below the trainer window). Also please don't post twice for the same issue, you can edit your post until you didn't receive an answer, or answer in the same thread, please delete your message above, it's useless.This comment has been hidden.
You're right, this is an error of the Javascript description.
indeed, now I saw different values, thank you!
Java translation ready for review
Approved by someone!
thanks!!!
Typescript translation ready for review
Approved
thanks!
Julia translation
Approved
COBOL translation.
Approved
this: test.assert_equals(single_digit(5), 5) should be this: test.assert_equals(single_digit(5), 2)
This comment has been hidden.
No. Propblem is still valid. I checked a few sek ago.
@temen no it's not. "The goal of this Kata is to reduce the passed integer to a single digit --->>> (if not already) <<<---"
Ok. All of you are rigth. I sugesst more the one test of this case.
All tests were passed, but for n = 5 I get very strange failed test:
requested n= 5 binary form: 1 0 1 summed digits = 2
but I get failed test with the message: "2 should equal 5"
Can anyone explain what is wrong here? How can 2 be equal to 5 according to the kata instructions?
Thank you.
Thank you. My bad, I did not understand the instruction properly.
Thanks again.
C translation (author inactive)
with range
0
<=n
<2^64
Thanks :)
JavaScript Translation kumited. Feel free to check :) FYI, I reduced the upper bound limit to
1e10
because of Number.MAX_SAFE_INTEGERApproved
Thank you
my code works anywhere else, here it only gives the wrong value for one test. it is rather odd since even with that input it yields the correct answer on my interpreter!
Read this please: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
thanks
Ruby translation kumited :) please review and approve ~~
This fixed test breaks the description.
n
should be< 1e20
. I'd edit it, but I can't.removed :)
Haskell translation
Any power user want to approve this? OP has left the building.
Seems already approved.
import paradox; ugh... writing python is so light compared to java, how come that makes me feel heavier?
This comment has been hidden.
My code ends with error: '2 should equal 5'. Why so? 2 is 0010 which equals 1, not the 5. What is wrong? halp pls
Your code returns 2 and it should return 5 instead, I doubt 2 is the original number. Use
print
to check the input value.You mean use
print
inside my code? Cuz I cant see anyprint
in kata output. I would gladly look at input value to recognize my mistakeUPD: I found mistake :)
But I still wanna know what
print
exactly do you mean ThanksIf you write
print(n)
as the first line of your function's code, you'll see the input's value in the Output tab.I think there is an error in the following: test.assert_equals(single_digit(5), 5) Shouldn't this test return 2 :-) ?
No, if it is already a single digit number you have to return that number.
As Chrono79 mentioned:
If the passed integer is already a single digit there is no need to reduce
Ahhh of course, always a good idea to read the description properly. Sorry!! :-/
Thanks.
I don't get it. I passed 108 tests and failed in 1. It says that the result of number 5 should return the value 2. How come?
int(5) = 0b101 = 2. However, the log says: "2 should equal 5". Is there some other way how to get the value 5 when the input is 5 as well? Coding in Python.
How did you solve it in the end? If you ever have... I'd say it must be an error.
"If the passed integer is already a single digit there is no need to reduce." For
single_digit(5)
, 5 is already reduced to a single digit. You don't need to do anything to it; just return 5."2 should equal 5" means "your function gave me 2, but I expected 5".
This comment has been hidden.
Copying my post here, since the full post with the code in it is hidden. See below...
Thing is, that bin(5) is 0b101. That's two 1's. Not five! At least I think so. I wrote another code with different solution and both codes show the same. I also printed simple code, which returns the binar number. Not a reduced one. Just a normal binar number. Here are my two codes, including the print commands. What is wrong there? Why codewars suggests that the result for bin(5) should be 5 while the bin(5) == 0b101?
Thing is that 5 is already a single digit number, so you whould not even do
bin(5)
. It's already the answer. Nothing needs to be done with 5.Codewars does not suggest that
bin(5)
should return 5. It suggests thatsingle_digit(5)
should return 5.Done. Thanks a lot. I sometimes struggle to understand properly the english details. The key part in these datails was this - "(if not already)". It only made a sense to my after reading your reply. Thank to you and thank to jimpjorps, who was probably trying to say the same thing. I just didn't catch what the words "passed integer" really meant. I thought it was something about the binar integer...
This comment has been hidden.
And probably enclose the random tests in a closure
Thanks, done.
Why not 300? :)