6 kyu
Convert integer to Whitespace format
708 of 1,918MMMAAANNN
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.
BF translation: https://www.codewars.com/kumite/681873bacea1bd09023e9fe2?sel=681873bacea1bd09023e9fe2
Lua translation
Nice kata, well done.
Scala translation
approved by someone
I think there's an error in Tests (JS). I didn't do anything and it just gives me 'ws is not a function' error.
It's a bit late, but I'm sure someone else has faced this issue too.
This kata requires you to return a String.
Looks like the third bullet point is an accidental duplicate of the second?
https://www.codewars.com/kumite/6330545c1ee3678ff7c841fc?sel=6330545c1ee3678ff7c841fc
o_O
The description is ambiguous, as it does not define the order of the binary representation in the output (nor does it define the maximum length of the representation). Neither does it define the leading zeroes. Only by carefully looking at the example of '2' can one deduce the order. Terms like 'first' and 'leading' are therefore ambiguous too. This should be made more clear in the description.
Please suggest the wording that will satisfy your requirements for non-ambiguity.
"characters after that and until [LF] are the binary representation of the integer: [space] for 0, [tab] for 1."
could be
"characters after that are the binary representation of the absolute value of the number, with [space] for 0, [tab] for 1, the rightmost bit is the least significand bit, and no leading zero bits."
and remove "In this kata, the output should not contain any leading zeros."
change
the integer MUST be terminated by [LF]
into
the binary representation is immediately followed by [LF]
Thank you for the suggestions. I incorporated these.
I was able to complete all the example_tests but got this error when I initiated random_tests : Test Crashed Caught unexpected signal: SIGSEGV (11). Invalid memory access. I know what this error is but I don't know why this error occurred when the example_tests came out correct
There is a problem with the bleach() method in Java. It does not read spaces correctly. Just made me mad, i used " " for space as in the description. Could anyone help? edit: I tried this as well : (char)32 . Still the same :(
Show the code that produces issues. I have just tried
System.out.print(PreloadedTools.unbleach("\t \n"));
and it produced[tab][space][LF]
. Also tried just one space, with expected result[space]
.This comment has been hidden.
Well, and what exactly are the errors your code produces? Give us a testcase which your code fails.
I think you fail with the
0
test. Your solution returns a single newline, but it should return a space and a single newline.when I try to use the test cases, it gives me this error: TypeError: ws.replace is not a function at unbleach at /home/codewarrior/index.js:20:19 at /home/codewarrior/index.js:25:5 at Object.handleError
EDIT: Never mind, the issue was resolved. I was returning a number not a string.
Elixir translation awaiting approval.
I'm approving, but will need your help in case anything goes wrong. Please keep an eye on this.
This comment has been hidden.
What will your solution return if n is 1?
<[tab][[tab][]LF]> but was:<[tab][[]LF]>
I asked because your code actually ignores the case of n==1. And this is not the only issue, as far as I can see. You need to work more on your solution.
I have solved this solution and it is literally not compiling any code for this solution in the editor. That's why I was particular to see if there was a reason even this small snippet of the solution was not giving the correct compiled response. My code that works on my machine does have the every case handled but that's not the question I was addressing. So don't overanalyis into degradation of civility as you degredate effervescent ethusiast to have disillusioned notations that articulating about their work is strife issuing. I'd rather you again read what I asked since this is a written forum.
Well, I am not your tutor. You asked why your solution doesn't work, and I identified (one of) potential issues in it. If you want to ignore that, that's your choice. I have no obligation teaching you. Your report does not show any specific things that need to be fixed, so I am not sure how can I help you.
I suggest you find yourself a teacher or go through some additional training/tutorials if you cannot handle simple issues yourself.
@Arandolph543, read the description again and focus on the second bullet point. There's a key term there that you missed.
Julia translation
Approved, but I hope you will keep an eye on it. I will not be able to support this.
This comment has been hidden.
The error message is not clear enough for you? Let me quote:
Please return only spaces, tabs and newlines. Other characters are not allowed.
You are supposed to return only tabs, spaces and newlines. Do not return their placeholders instead.This comment has been hidden.
Your code returns square brackets, letters t, a, b, s, p, c, e, L, F. These are neither spaces, nor tabs, nor newlines. These are placeholders so that you can actually view what is the output and a converter is supposed to convert your output to this viewable format. Do not return "[tab]". Return "\t". Do not return "[LF]". Return "\n". Do not return "[space]". Return " ".
C, C++ and Java translations available. Please review.
Sorry I cannot check them, not enough experience with those languages. I'll leave you responsible for these, and just accept them. Please keep an eye on the discussion and correct if anything goes wrong, okay?
@clcraig, can you please take another look at the Java translation? It looks like newbies may have issues understanding what case is being tested which returns a failure (see a thread by Arandolph543 above - I actually tried to test her solution and it produces an error without specifying the input case, which leads to confusion).
@MMMAAANNN, I've added a print statement to the example test code to show the value of
n
. That should help newbies see which test case is failing. This was already in the full test code.Regarding Arandolph543, even taking into account the missing case of
n = 1
, her code is solving the wrong problem. She's not convertingn
to binary. Given her attitude, I'm not really inclined to help. :-SThank you for the update, @clcraig!
The example tests allow [space], [tab], [LF], but the real tests require " ", "\t", "\n". This was for C# version. The tests should be consistent, especially because the spec specifically mentions we can use [space], etc.
Let me quote the description: "only space, tabulation and linefeed are meaningful characters ... for the purposes of this simple kata, please do not add any other characters in the output".
Please show me where "the spec specifially mentions we can use [space] etc.", I'll correct this.
I am sorry if example cases somehow caused you to believe you can actually use placeholders instead of actual characters. Example test cases are not designed to do full tests on your code, but rather provide you with a starting point so that you can add your tests if needed. If you have any suggestions how to reduce ambiguity that confused you, e.g. edits for description or Example cases, I'll be glad to see those and implement them if feasible. Meanwhile, I am marking this issue as resolved.
You should remove this text from the description:
This is a clear signal that those sequences will be allowed in the tests.
I don't think this is a clear signal. I did some edits to description though, hope it is more strict now.
Is there something wrong with the Tests? This is for the test with 0 as the input
Show your code please (and mark it as spoiler). I suspect that you might be doing some kind of double space there.
This comment has been hidden.
This comment has been hidden.
Yup, you did the double space thing. Your code returned space-space-newline for zero instead of space-newline.
C#-Translation kumited!
https://www.codewars.com/kumite/57b2ec4b1fae8aeefb000290
Please check and approve!
Approved.
There's a slight problem with the Ruby test cases. If the RNG picks
0
, then the test expects" \t\n"
even though the correct answer is" \n"
.Thank you, I've included your edits.
This comment has been hidden.
Not if it has things like
'[space][space][tab]'
in it. In this case it may pass the tests (because in the tests, we compare unbleached result). In fact, there was a solution like that (you can find it in "invalid solutions" in Python).I committed a Ruby translation.
Thank you! I have accepted it.
However, I can see that your translation of test fixture has some differences from my original algorithm. I encourage you to edit it to be consistent with other language versions as much as possible.
Also, looks like your unbleach() function does not work as expected - it only replaces one space, not all characters. And this unbleach() function is not available in Example Test Cases, so I edited them.
I am far from being an expert in Ruby, so please improve your translation.
Thanks for pointing those issues out. I'm really new to Ruby. I'll get started on finishing the translation.
The unbleach issue was easy. I didn't realise that String.sub only substitutes the first occurence. String.gsub is what I needed. Also, for some reason, unbleach didn't work as expected when the characters in gsub were surrounded by single quotes rather than double quotes.
For some reason I was thinking that I could put unbleach in the preloaded section so as to not have to put it in both the test case boxes.
I'm working on re-writing the test case section to match what your algorithm is. My meds were in full force when I initially did it... This time it will come out as close as possible to yours.
I've almost got it. Just chasing out a bug or twelve.
I'm pretty sure I got all the bugs out; anything remaining shall henceforth be called a feature! ...Actually, if there are any bugs I'm happy to fix them.
Looks fine to me, I've moved your updated translation into the kata. Thanks.
Thanks for Kata. Good occasion to learn new language, even esoteric one.
It may be temporary, but given link (http://compsoc.dur.ac.uk/whitespace/) actually doesn't work.
The wayback machine has it:
https://web.archive.org/web/20150611002225/http://compsoc.dur.ac.uk/whitespace/