8 kyu
Fake Binary
63,947 of 154,208PG1
Loading description...
Fundamentals
Strings
Arrays
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.
The instructions are missing the statement that it has to be greater than or equal to 5 instead of just greater than 5.
Are you sure? I read the description three times and every time i see "below 5" and "5 and above"...
Not a kata issue. "5 and above" and "greater than or equal to 5" are the same.
Why are half the exercise's instructions in the comments of the editor? Seems more ideal for this information to be in the instructions section
No fixed tests in Swift, also random tests should be increased and follow DRY principle
This is more of a 7 Kyu. Teaches the difference between ammending strings vs lists, useful.
its really a 8 kyu problem because it requires a basic knowledge about characters
There seem to be an issue of some kind with the test, i printed the string (45385593107843568) and the error is: expected:<0[10111100011001]11>
following all the output:
when you realize your mistake and pass the kata, please come back to close your issue/question. (and ask questions when you are not sure, if there was such a big mistake in Java 10,000 would not have completed it)
What's wrong with this kata in Perl? I pass initial [Test] and all 100 random tests from [Attempt] are all green. Still I cannot [Submit] solution. Output doesn't give a clue... as it only tells the passed tests. BETTER SAY WHAT'S WRONG INSTEAD (if at all).
If you remove your
print
statements, your code will work. It seems like printing anything at all in Perl messes with Codewars' processing of the output and makes tests appear to pass even though they fail.Lua translation!
Approved
This doesn't feel like a 8 kyu...
Agreed.
This comment has been hidden.
Nevermind ignore me, I forgot a }
Closing the question then.
Shortness is fine, why don't we see times?
This comment has been hidden.
This comment has been hidden.
at least this:
getNumericValue
notNumericValue
and there is more, but start with these
Big thanks, man
you're very welcome
seems like you passed the kata?
in which case, if your
question
was fully answered, close it out by clickingMark question as resolved
This comment has been hidden.
Did you check the solutions tab?
Just saw an example. I had to scroll down for a bit.
This comment has been hidden.
A problem with your code is not a kata issue, please use Question label next time, and read this first: https://docs.codewars.com/training/troubleshooting
This comment has been hidden.
This comment has been hidden.
Strings are immutable in JavaScript.
Thanks sorted
Note: input will never be an empty string.
In Java you get random test: for input "".
Fixed.
This comment has been hidden.
This is not 8kyu for SQL!
For some reason it thows an error:
rows did not match expected @@,x ,res → ,45385593107843568 ,1→01011110001100111 → ,509321967506747 ,1→101000111101101 → ,366058562030849490134388085,1→011011110000101010000011011 → ,15889923 ,1→01111100 → ,800857237867 ,1→100111001111
Whereas the code is correct for each testcases seprately
This comment has been hidden.
Sorry, I must be going slightly mad, but aren't these the same?
Time: 540ms Passed: 0Failed: 5Exit Code: 1 Test Results: Fixed Tests Basic Test Cases Log 01011110001100111 None should equal '01011110001100111' Log 101000111101101 None should equal '101000111101101' Log 011011110000101010000011011 None should equal '011011110000101010000011011' Log 01111100 None should equal '01111100'
Read this: https://docs.codewars.com/training/troubleshooting#expected-the-same
Thanks for the help!
This comment has been hidden.
Scala translation
LGTM, Approved!
Interesting task
I think this needs to be re-evaluated at a higher skill level.
Not a kata suggestion
Once again Ruby bahaves unlike other languages in a very annoying way. Why? Why I can't just convert booleans to 0 and 1 with .to_i method for instance? There is no reason I cannot do that by default
This comment has been hidden.
This comment has been hidden.
OP solved it, closing
The test asserts that this string "4112340110111" should be equal to "0110000110111", but in the description It says that any digit below 5 should be replaced with '0', and that includes the '1's... In my opnion, this test case was coded wrong.
There is no such test. And the tests are fine.
Yeah, I put random numbers here just to explain the concept. but you are right, the test is passing now. Thank you for the quick reply.
This comment has been hidden.
That's not a kata issue.
strange, i can't use List<> for my solution (( But why ?
This comment has been hidden.
This comment has been hidden.
print(x)
on a new line just before the return statement, run the tests, then look at what "becomes"x
during the executions, for the tests your code failsstr.replace
isn't working the way you think it doesHow this function will behave if input string is an empty string?
OP solved it, closing
You said you wouldn't test for an empty String but you do!! Easy fix for both of us ;)
This comment has been hidden.
This comment has been hidden.
Issue with your code is not a kata issue, also please type in English so most users can understand and will ty to help you!
'00000000001000010' should equal '01011110001100111' ???? '000000000000000000000000000' should equal '011011110000101010000011011' something wrong with a tests ? or I don't understand the instructions?
Print the input: https://docs.codewars.com/training/troubleshooting#print-input
This comment has been hidden.
There seems to be an issue with a test case here? I have tried with validating pointers, accepting any char and char only between 0 - 9, but always failing ATTEMPT.
What language?
This comment has been hidden.
This is an issue with your code, you need to make sure your string terminates properly to stop memory allocation! (Not a kata issue)
This comment has been hidden.
You forgot
5
.Cheers... Next time I'll do regex
Not a kata issue. Use
Question
label next time.Appologies, not too used to the platform yet
No problem, cheers.
This comment has been hidden.
OP solved it, closing
D translation
Approved, thanks
Overthought this one way too much.
This comment has been hidden.
Which language?
Assuming this is Java, since you completed the kata in it, but the random tests can't generate an empty string.
No answer, no proof, no issue.
This comment has been hidden.
Your output is not null terminated.
That is not the Issue.
You can add
mov byte[out1+rcx],0
after end:
Typically every reserved byte defaults to value 0, so unless, that variable has been in use before, it ends with alot of zeros, which is what null-termination means.
Similarly the c-function "puts" would not print my value, if it wasn't null-terminated. Please provide a working code with said solution, if you think, that this is the issue. And if that code does not work for me, i will provide a video link.
Indeed, the problem is actually you are not doing what you are supposed to do. As stated in the solution set up you are provided a buffer (rsi), you must write into it and return rax as a pointer to it.
That is indeed working, thanks.
This comment has been hidden.
Your anonymous function isn't returning anything.
This comment has been hidden.
Go translation
Approved
Traceback (most recent call last): File "/workspace/default/tests.py", line 2, in from solution import fake_bin File "/workspace/default/solution.py", line 8, in x = input() EOFError: EOF when reading a line что это значит?
Remove the last two lines of your code. This doesn't work. Just click on
Test
orAttempt
to launch the tests.This comment has been hidden.
Because
replaceAll
doesn't work in all Node's versions.Java. There's LITERALLY a note that says: "an entry string won't be an empty string bro", and then as soon as you're trying to submit the solution it goes BAAM, EAT THIS EMPTY STRING LOSER. What's wrong with you authors and test creators?
This comment has been hidden.
This comment has been hidden.
I see. Thanks man!
As a 5 kyu why am I getting 7 & 8 kyu kayas to solve. I thought at each level you get that level kayas
I assume you mean when selection 'Rank up', right? It depends a bit on how many katas are actually available in the chosen language.
I did not chose "rank up" but "foundations" I thought rank up was more if you were experienced andd quickly wanted to get to a level more appropiate for your experience. I thought foundations was the usual route for just progressing normally as you obtain more experience. I guess I need to reread how this site works :)
SQL translation
^^
This comment has been hidden.
In the description it's stated "Note: input will never be an empty string"
but there is a random test with an empty string input. The note is wrong then
Language: Java
fixed
My answer should be correct, I have no idea why but it should work but it doesn't. Please check your test cases. Language: Python
its highly unlikely (but still not impossible) that tests are wrong, since >11k people have completed it in Python
saying that your answer should be correct doesn't prove anything without code snippets/the exact test case which you think is wrong
marking this issue as closed, but do try to send your code/failing test marked with the spoiler flag
I had a similar issue with NASM and i provided the spoiler-flagged code as requested. There is also a link to a screenshot and a video.
This comment has been hidden.
There is no lower kyu than 8 LOL
proly should be 10kyu xD
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
OP solved it, closing
This comment has been hidden.
kept getting this error in random test for Java expected:<[]> but was:<[]> I'm not sure what's the difference between these?
This comment has been hidden.
COBOL translation
Approved :)
This comment has been hidden.
Approved
This comment has been hidden.
Approved thanks
Wowww that was speed :)
:D
stack a bit in Python :))
No random tests in Java
Solved by me agn ~~ :)
You, The Unsung Hero :p (mmmhm no "final" variables :p)
Clojure Translation ready for review.
Approved
This comment has been hidden.
This is a question.
What is error|failure message you get while attempting?
This comment has been hidden.
This comment has been hidden.
Use local IDE, debug, step through your code.
This comment has been hidden.
oh, there is issue with random tests, any solution passes all of them.
fixed, the tester was comparing the string with itself.
Your solution is wrong, you're confused between zeroes.
This comment has been hidden.
It does work for me? How exactly it does not work for you?
Wow. I dont know. I tried this on my work laptop a few hours ago, and it did not work. Strange. Now it works.
The issue regarding that might have been fixed.
This comment has been hidden.
What case exactly you mean by "the second scenario"? What input is it? I just checked C version and it seems to be OK.
I am going to resolve this issue as invalid, and if you have some details on how the tests are incorrect, please raise the issue again, with test input, your (correct) output, and expected (incorrect) result.
Potentially helpful link: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#how-can-i-see-which-input-causes-my-solution-to-fail
Hello thanks for that. In the time I was editing my post I figured it out. I saw a bunch of others posting issues and then I remembered about the null terminator so I tried it, and it worked. Wow you were fast and right on it lol. It was like 2 mins!
I normally use printf to figure out what I screwed up, which is why I knew it was returning too many digits.
This comment has been hidden.
Not a kata issue, your solution has a bug.
This comment has been hidden.
Kotlin translation added :)
This comment has been hidden.
Error with your code, the input is a string of multiple characters not just one.
This comment has been hidden.
great usecase for map and lamda,loved it :)
Can you please show a bigger portion of the code because I'm not sure what I'm working and I can't really solve it.
It simply means replacing digits 0-4 with '0' and 5 to 9 with '1' in the string~~
TestCase for java is failing for Input: 45385593107843568 expected:<0[10111100011001]11> but was:<0[00100100011000]11>
It should be <0[00100100011000]11>
The expected value is ok.
The second test give 15 numbers as an input, only 14 are expected. Language - C. Check the test, please.
the second test (both in the sample tests and the fixed tests) is as follows:
and it does expect an answer that matches it at
15
strlen() chars.Thank you!
But I checked right now: 10100011101101. Only 14 chars. Damn, you know what? When I click the "Test" button, the second test give me an error, but when I click the "Attempt" button, all the tests are passed. So, the seond test is wrong. I spent a lot of time rewriting my solution, but the case was this test...
You're welcome! Glad you passed the kata, but hey, the second test is not wrong. I don't know from whence you're getting
10100011101101
(?) as the 2nd sample test / 2nd fixed tests are literally copy/paste identical code, their answer is101000111101101
, and your code passes both of them.Weird thing, haha.
i have the same probleme and i can't pass it
Shenawy99:
Remember strings end in a null terminator. That is the 1 + (strlen(digits)) in the test. How can you tell the program to stop reading after your last char that you update using the +1 at the end?
Passes all random tests, works as it should. Yet I get this error: The expression strcmp(buffer, "01011110001100111") == 0 is false.
check your output in tests
printf("%s\n", buffer);
most likely a problem at the end of the line
'\0'
Swift translation :)
'alr approved some time ago'
This comment has been hidden.
I thought the same too, then I re-read: "...any digit 5 AND above with..."
Racket translation
Approved, thanks
What's wrong with the second test? The program passed all the main tests, but the sample tests did not pass I use C
almost 600 coders have solved this in C, so it's not a problem with the test. if you post your code (use a spoiler flag) perhaps someone can help you
Same :D
Julia translation
Approved, thanks
This comment has been hidden.
I'm a newbie, but from my understanding you need a "+=" to make sure it captures each string character. Also, "return" shouldn't be embedded in the if statements, because it will stop the for loop from continuing after the just one run, instead of looping for each character. "return" statement should come outside of the for loop, but within the function.
Passes all tests except the second theirs:
101000111101101
Mine:101000111101101
I forgot "return"...just use "cout"...and then I failed. I should come here everyday.
I love the oneline shots in python but it gives me hard time, everytime I try to make the solution that way I get the failure and finish with if a == b: Bleeh
I use C,my solution show me time limit.Who can help me?
Awesome! The best example to start "my great regex adventure" - very simple but encourages to go deeper into those mysterious expressions. :)
This comment has been hidden.
This comment has been hidden.
Please, NASM Translation
Approved
Great! But now i am unable to change the NASM Translation link
How, Can i remove it?
When my code was testeted I've recieved the answer: expected:<[45385593107843568]> but was:<[01011110001100111]> It passes all the the tests but it fails in the comparison I use C programming language
This was a nice easy one to show my students and to get them started on codewars.
Glad you liked it - I have plenty more :D
When my code was testeted I've recieved the answer: expected:<[45385593107843568]> but was:<[01011110001100111]> Could sb explain me what is that ?
language?
It seems that expected and actual are swapped. So the first would be your output while the second one is rather the expected value.
Fixed the swapping for Java. It still lacks sample tests and random tests tho.
I am a novice to programming and lm super enjoying this!!!
This comment has been hidden.
You return some arbitrary integer on first iteration of the loop, whereas the task is to return a string of
0
's and1
's.This comment has been hidden.
Read how to use split
You're returning a number too.
Damn, you are everywhere. I understand the objective, I just don't understand why my code isn't working
Because
x.split();
doesn't do what you think it does. And the thing about returning the wrong data type too (that's what I changed to bold in the instructions there).This comment has been hidden.
Strings are immutable in javascript so you do need the
split
, but used properly (see the docs I posted in my first answer) and you have to recover a string before returning it usingjoin
. You can't overwrite a single char of a string. Beware of comparing different data types. Why don't you create a new string instead? It seems easier.C++ translation kumited :)
Nice
Good one! Only a suggestion: Consider moving the comments of the code to the description of the Kata. It cleans the code and gives enough info to solve the task.
This comment has been hidden.
You probably forgot to append the null character at the end.
You're right. It works now.
This comment has been hidden.
Is it just me or this test for C doesn't work properly?
Me too :(
Me too.
An anonymous user wrote:"You probably forgot to append the null character at the end."
This comment has been hidden.
push() is not a method in C. You're probably doing this in JavaScript or a C variant. There is no way to push/pop/append/etc... in C as array sizes have to be declared at initialization, unless the array is defined at initialization (strings are arrays of characters in C.)
.
This comment has been hidden.
This comment has been hidden.
Why would you pass a String of numbers in the first place?
Do you mean DIGITS not numbers, please update the description because the results are very different.
I did. Done, thanks.
Crystal translation submitted; and, incidentally, I indeed put a test for empty string even before reading biskinis.
Cheers.
Trying to approve this (1 year on...oops)... getting a merge conflict with the description, Can you update an Ill approve?
Sure, go for this :+1:
Done
This comment has been hidden.
added to description
Ruby translation added, ready to be reviewed and approved!
Approved, thanks
PHP Translation Kumited - please accept :D
Approved
Python translation kumited :) Please review and approve.
Thanks,
suic
Approved
This comment has been hidden.
C translation kumited. :)
Approved
C#-Translation kumited!
https://www.codewars.com/kumite/57ebe6652d45a01892000017
And F#-Translation kumited!
https://www.codewars.com/kumite/57ebeacc2d45a0ecd7002d5a
Please check and approve both!! :-)
Hey Pete, Mr. Turbo-Kata-Creator! :-)
Check and approve this wonderful translations for the sharp-world. ;-)
hey steffen, C# approved. other link keeps bringing up a 500 server error... will leave for a bit - remind me again some time :D
ignore that, F# apprved too
Great!
The first of your katas, that is available in F#. ;-) Perhaps, I will translate some more to F#.