4 kyu
Brainfuck Translator
39 of 832Varveyn
Loading description...
Esoteric Languages
Strings
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.
Issue with the PHP tests:
These incorrectly replace multiple consecutive input or output characters (
,
&.
) with just a singleputchar
/getchar
call.This is incorrect, as while reading multiple bytes from input would only store the last, it would still consume multiple bytes.
Same goes for the output: the written character would be the same each time, but it would still be written twice.
(The interpreter in the tests would print
Helo, World!
, with just a single 'l', for example).I could get my solution to pass by implementing the same error, but that is obviously not right.
Edit: Just noticed hotdonkey already reported this 9 months ago...
It's not only in PHP, I guess the author meant some further pattern recognition and code optimization thereby however misleading it might be at some point.
For the C translation, the tests expect us to return a newly-allocated character string, but never frees it. I know it doesn't free it now because the initial solution returns a statically allocated string instead and doesn't break the allocator. A change to the function's interface or the initial solution would allow the tests to free the returned string instead of wasting that memory.
The tip for C: more memory,very more
completely changes the output? i dont even know how it gets the output its getting, i even tried changing compiler to match theres, and it outputs the correct answer
ummmmm Expected: equal to "*p += 4; " Actual: "*p += 4;"
\n
This comment has been hidden.
JS fork, please review:
Chai
;lodash
and replaceTest.randomNumber() % 8
by_.random(0, 7)
;assertStrictEqualPretty
function (thanks to @Hobovsky) for large inputs (but there's still a problem with the ~1MB input).(Thanks!)
In description it is told that repeated "." and "," commands must act like repeated commands
However to pass random tests i had to combine them to one. "...." -> "putchar(*p);\n" So there is either missleading description or tests.
I tried many times to solve this tricky kata in C, but couldn't avoid timeout error.The solution was found in full replacing library functions, such as 'sprintf' and 'strcat'with handmade code and using for output string size not less than 100000000 bytes. For sure, this is not 4 kyu, at least 3 or 2.
JavaScript. Get
for one single random performance test when I want to log the input. Cannot see which pattern I didn't take account of. My code is certainly flawed somewhere, but that's also an issue with the kata, right ?
Edit : I understand that the input is too big to be displayed properly. A workaround could be to display a more informative error message (something about the patterns in the input, or something about the expected output, I don't know). The error message in this case is currently useless :
I have same error and I don't know what is wrong.
.
I can't pass the performance test . why? how can i reslove it?
debug your code this can help: https://docs.codewars.com/training/troubleshooting/#timeout
an
ISSUE
is a bug in the kata. when asking for help, please use theQUESTION
tag ;-)note that the description says:
also see this issue below: because of a flaw in the C++ tests suite, the tests will time out when displaying the output unless your solution is correct
What difference does it make if my algorithm, as a result of calculations, replaced this sequence "+<->" with a similar one "<->+" ? Or this "<<--<-<+>--+" (8 lines in C) to the optimized "<<--<--<+>" (7 lines in C) ? Why is kata hardcoded to one C variant, not realizing that other variant (smaller or equal in number of lines) can lead to the same calculation results? O_o
Can't stop getting timeouts for the c++ version.
I'm 99% sure it's not my fault because even when I immediately return std::string() from the function, I still timeout even though my function is doing absolutely no calculation. All the other tests pass perfectly fine and on my machine at home a 10k brainfuck source code computes in like 30 milliseconds
Simply returning an empty string immediately still times me out.
The issue is caused by testing framework and stringification of large values when assertion messages are displayed. The problem does not occur when assertions pass, only failing assertions are a problem. A correct solution, which returns correct answers, should not time out.
I will think how to solve the issue and how to fix the kata, or the testing framework.
Shall I suggest that this kata expected result is 'suboptimal' ?? My attempt passes the fixed tests, but the for some random test the expected contains "... *p += 2; *p -= 1;..." where my solution gives "..*p+=1;..." for those same both lines ??
C++ version should probably accept
source_code
parameter asconst std::string&
instead ofstd::string
why do I have to return '' in basic#1 but i can't return '' in basic#2
My code is showing error, even though expected result and results are exactly identical. I dont understand the issue here. Can someone please help me. Issue 1: Expected: "if (*p) do { putchar(*p); *p = getchar(); if (*p) do { p -= 1; if (*p) do { p -= 1; putchar(*p); p += 1; putchar(*p); *p += 1; } while (*p); if (*p) do { if (*p) do { *p -= 1; p -= 1; if (*p) do { putchar(*p); *p += 1; p += 1; } while (*p); } while (*p); *p -= 1; *p = getchar(); } while (*p); putchar(*p); *p += 1; } while (*p); *p = getchar(); if (*p) do { putchar(*p); *p += 1; p -= 1; } while (*p); putchar(*p); if (*p) do { p += 1; putchar(*p); *p -= 1; if (*p) do { *p -= 1; p -= 1; *p = getchar(); putchar(*p); *p = getchar(); *p += 1; } while (*p); p -= 1; if (*p) do { p += 1; *p -= 1; putchar(*p); *p -= 1; p -= 1; *p = getchar(); *p = getchar(); if (*p) do { *p -= 1; if (*p) do { p -= 1; *p += 1; if (*p) do { *p -= 1; if (*p) do { p += 1; *p -= 2; } while (*p); putchar(*p); if (*p) do { *p += 1; p += 1; *p -= 1; } while (*p); } while (*p); *p += 2; putchar(*p); putchar(*p); } while (*p); putchar(*p); *p -= 1; } while (*p); p -= 1; ..." but was "if (*p) do { putchar(*p); *p = getchar(); if (*p) do { p -= 1; if (*p) do { p -= 1; putchar(*p); p += 1; putchar(*p); *p += 1; } while (*p); if (*p) do { if (*p) do { *p -= 1; p -= 1; if (*p) do { putchar(*p); *p += 1; p += 1; } while (*p); } while (*p); *p -= 1; *p = getchar(); } while (*p); putchar(*p); *p += 1; } while (*p); *p = getchar(); if (*p) do { putchar(*p); *p += 1; p -= 1; } while (*p); putchar(*p); if (*p) do { p += 1; putchar(*p); *p -= 1; if (*p) do { *p -= 1; p -= 1; *p = getchar(); putchar(*p); *p = getchar(); *p += 1; } while (*p); p -= 1; if (*p) do { p += 1; *p -= 1; putchar(*p); *p -= 1; p -= 1; *p = getchar(); *p = getchar(); if (*p) do { *p -= 1; if (*p) do { p -= 1; *p += 1; if (*p) do { *p -= 1; if (*p) do { p += 1; *p -= 2; } while (*p); putchar(*p); if (*p) do { *p += 1; p += 1; *p -= 1; } while (*p); } while (*p); *p += 2; putchar(*p); putchar(*p); } while (*p); putchar(*p); *p -= 1; } while (*p); p -= 1; ..."
Issue 2: Expected: "if (*p) do { putchar(*p); } while (*p); *p -= 1; putchar(*p); if (*p) do { *p -= 1; putchar(*p); putchar(*p); } while (*p); putchar(*p); *p -= 2; *p = getchar(); p -= 1; *p += 2; putchar(*p); p -= 1; *p += 1; if (*p) do { putchar(*p); *p -= 1; putchar(*p); p += 1; *p += 1; *p = getchar(); } while (*p); *p = getchar(); *p = getchar(); if (*p) do { *p -= 1; p -= 1; if (*p) do { *p -= 1; if (*p) do { putchar(*p); p -= 1; putchar(*p); *p -= 1; } while (*p); if (*p) do { p += 2; } while (*p); if (*p) do { *p = getchar(); } while (*p); } while (*p); *p = getchar(); *p = getchar(); *p = getchar(); putchar(*p); } while (*p); putchar(*p); p -= 1; putchar(*p); if (*p) do { *p = getchar(); p += 1; } while (*p); *p += 2; putchar(*p); *p = getchar(); p -= 1; if (*p) do { if (*p) do { p -= 1; *p += 1; } while (*p); *p += 1; } while (*p); if (*p) do { *p = getchar(); *p = getchar(); p += 1; if (*p) do { *p -= 1; putchar(*p); p += 1; putchar(*p); } while (*p); if (*p) do { putchar(*p); if (*p) do { if (*p) do { *p = getchar(); } while (*p); *p -= 1; p += 1; putchar(*p); *p = getchar(); *p = getchar(); *p = getchar(); putchar(*p); p += 1; if (*p) do { *p += 1; *p = getchar(); if (*p) do { p -= 2; *p = getchar(); *p ..." but was "if (*p) do { putchar(*p); } while (*p); *p -= 1; putchar(*p); if (*p) do { *p -= 1; putchar(*p); putchar(*p); } while (*p); putchar(*p); *p -= 2; *p = getchar(); p -= 1; *p += 2; putchar(*p); p -= 1; *p += 1; if (*p) do { putchar(*p); *p -= 1; putchar(*p); p += 1; *p += 1; *p = getchar(); } while (*p); *p = getchar(); *p = getchar(); if (*p) do { *p -= 1; p -= 1; if (*p) do { *p -= 1; if (*p) do { putchar(*p); p -= 1; putchar(*p); *p -= 1; } while (*p); if (*p) do { p += 2; } while (*p); if (*p) do { *p = getchar(); } while (*p); } while (*p); *p = getchar(); *p = getchar(); *p = getchar(); putchar(*p); } while (*p); putchar(*p); p -= 1; putchar(*p); if (*p) do { *p = getchar(); p += 1; } while (*p); *p += 2; putchar(*p); *p = getchar(); p -= 1; if (*p) do { if (*p) do { p -= 1; *p += 1; } while (*p); *p += 1; } while (*p); if (*p) do { *p = getchar(); *p = getchar(); p += 1; if (*p) do { *p -= 1; putchar(*p); p += 1; putchar(*p); } while (*p); if (*p) do { putchar(*p); if (*p) do { if (*p) do { *p = getchar(); } while (*p); *p -= 1; p += 1; putchar(*p); *p = getchar(); *p = getchar(); *p = getchar(); putchar(*p); p += 1; if (*p) do { *p += 1; *p = getchar(); if (*p) do { p -= 2; *p = getchar(); *p ..."
Hi,
Thanks for replying. I am using Java. While attempting I am able to pass randomTests_MediumInput and randomTests_SmallInput. But I am facing this issue for randomTests_LargeInput: Note: ./src/test/java/SolutionTest.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. And later it is ending up in time limit exceeds.
That's only warnings. They won't cause troubles to your code. I guess your code is just too slow. There is another batch of random tests, with "superInput", that uses inputs 5 times bigger than the largeInput one. If you dont see it, you have a performances problem.
note: don't print anything to the console in this kata if you wanna pass the tests, otherwise you'll systematically saturate the buffer (so far, you're not doing it, but just a warning when you'll get to the superInupt tests)
As far as I can tell, that's not an issue (of the kata) but a problem in your code.
closing as user error
I'm having an issue in the last performance test. It says "The translation was failed. - Expected: true, instead got: false" and the input it's "[[>?-+<]]..." repeated many times. What would be the expected output in this case? My solution is outputting the following:
Not sure what I'm missing here.
Rule number 1 it must erase all characters except +-<>,.[].
It's unclear from the instructions what a useless sequence is. You say '+-' is useless, but don't specify that '-+' is useless, for example. Am I supposed to learn C and interpret the code to determine what's useless?
No but you're expected to know that incrementing an integer and then immediately decrementing that same integer (and vice versa) means you did nothing with it and is therefor inefficient. The output of '+-' and '-+' would be:
That would be a useless thing to do.
Gotta agree here, as someone who isn't completely sure what +- or -+ mean in the first place, it is unclear that -+ is invalid as well. Same goes for the rules on the < and > carets—need to look the rule up or make deductions since it's not completely clear in the statement.
I am having an issue :( When I upload my solution I was doing a print of the code at the beginning of the function just to check what the code was and use it to debug my program in case that solucions didnt match, and it appeared that it did work for all the assertions but receiving an sterror due to the print; but when I remove the print statement the execution time requirement pops up. What can be happening?
hi,
You cannot print anything during the tests, otherwise you'll never pass: there is a f...ing lot of stuff, in the programs, so you'll systematically saturate the buffer. Now, if you time out when you remove the printing stuff, that just means that your code is too slow. So you'll need to track bad time complexity, then optimize your code (you need some kind of microoptimization, for this kata)
Great! Then I will try to enhance my code :) Thanks a lot!
In order to print the input code for some inputs do this:
Can i see tests from large_input?
i keep getting a timeout error. is performance relevant in this kata? and if so isn't it too hard for a kyu 4?
yes, perfs are the most important problem with this kata, actually
ok. thanks for the quick reply. i will keep trying for a bit
Random tests in JavaScript are problematic because the user does not get to see the expected answer, meaning even if we log the input and process it line by line, we cannot see what the checker expects. In some cases it is clear the checker is rejecting a demonstrably correct solution.
That being said, nice kata. To the people saying it requires too much performance for a level 4 kata, I wouldn't agree, you should just try various methods of parsing until you find the most efficient one possible.
Tried two different approaches — both of them pass 53 tests and then timeout (super_input 6 of 6).
For anyone considering solving this kata: this is NOT A 4kyu KATA! It seems like the only way to solve it and not get a timeout is to somehow transpile the whole thing on the fly in one pass — something that should have been mentioned in the description. :|
I'm gonna post both of my solutions in comments to this post just in case...
This comment has been hidden.
This comment has been hidden.
By the way, how many tests are there? Maybe there is a way to optimize one of my solutions to pass it? I tried to modify the stack to use a doubly linked list so I don't have to reverse it but that caused it to crash on
(*root)->prev = stack_node;
somehow. Weird...upd: OMFG I did it! I fucking did it!!
So, after creating those posts I decided to take a break and went to read "The C Programming Language" by Kernighan & Ritchie and suddenly I got reminded that strlen() function reads through the whole string in order to find out it's length. That got me thinking: "Hmm... My program is actually using this function every time it has to translate a bit of BF code into C code... Hmm... AM I SURE, this is the right thing to do, concidering input size can reach up to a million characters? ABSOLUTELY FUCKING NOT!!" So I went back to my stack solution and refactored it to calculate C code idx using log10 for the character length of counts.
After that, my timeouts were gone! But now it would fail on super_input 8, so I did some investigation by compiling and running a local version of this code — it gave me a Segmentation Fault, so I figured out the only way this could happen is if I didn't allocate enough space for resulting C code string. So I raised the size of the buffer and voilà! All green! Wo-hooooooow! I feel like such a hacker now... :)))
(I'm only using static size array to avoid millions of realloc-s, but will see if I can make it dinamic since it only takes 3 seconds to run my code now.)
Should
translate into
or is the problem something else?
There is a useless particle <> in the translated string that needs to be deleted
This comment has been hidden.
Don't know if this is relevant, but I have an O(n) solution in terms of the length of the source and it times out. Can't figure out how to process text any faster than this. Any optimization tips would be super appreciated.
Kotlin translation, would someone mind reviewing this please.
This comment has been hidden.
This comment has been hidden.
this way , you're still going through the whole string for each element of
legal
andillegal
. CCL: build one single regex that will do all the replacements one shot. ;)(deleted: double post again... x/ )
This comment has been hidden.
mmmmmh.... Lemme think about it again...
Well, there are actually 2 approaches. One is to do some/most of the work with regexp, carfully/wisely choosing what stuff you remove. The other is to scan one time through the whole string nd gather all the data you need "one shot", making the simplifications and transpiling on the fly.
From there, it's hard to tell what will or will not do with the regex approach. I personaly used the other method, actually...
Mine passed the static test but then gave Max Buffer Size Reached (1.5 MiB) Any suggestion?
Time: 10556ms Passed: 2 Failed: 0 Exit Code: 137 Test Results: static_tests STDERR Max Buffer Size Reached (1.5 MiB)
Just in case anyone else would run into it, the problem is you writing too much to the stdout. Remove all printing functions.
The python version trims the expected output so much that it's impossible to debug.
I tried to republish it, increasing the limit, but the server DOES NOT want to eat the republishing... :/
My C++ solution is failing with the following status (it passes basic sample tests and is indicating "General Tests" in green as well:
Time: 2038 ms Passed: 1 Failed: 0 Exit Code: 139
and an error which reads:
test: ../../libcxx/include/string:1164: void std::__1::__basic_string_common::__throw_length_error() const: Assertion `!"basic_string length_error"' failed.
It would appear that either I'm trying to use negative length strings (already checked there's no chance) or that the maximum C++ string size has been exceeded.
Can someone enlighten me on the possible causes of the error?
I'd also appreciate if someone could point me to where I can find a reference to what Exit Code: 139 means.
Need more info in description :)
For example : what's result of "[[...][,,]]"? As I understand - it should be "[...,,]", but seems that I didn't get it right and only "[]" sequence shoulde be removed (not "][").
Because "][" is an error. You should start with open square bracket.
This comment has been hidden.
I've passed 14 tests(9 general-tests, 4 general-test2, and 1 large-input) with no failed test cases, however I'm still getting an error "Execution Timed Out (12000 ms)".
In my function, I print out code before I do any processing to see when I'm getting a new problem, but after the large-input test it doesn't seem like theres any more tests (I might be wrong).
If it helps, I wrote the translator in C.
Any pointers about this would help! Thanks
did you try removing all the printing? Because in this kata, if you print anything (almost) like the input code, it will mak fail your solution (inputs contain millions of chars)
Yup, I just removed it, but it's still timing out. I am using sprintf to format my strings. Not sure if that throws a wrench into the performance of my code.
Update: I found an error in my code, and I proceeded to fix it. Now I am passing a lot more tests (9/9 general tests, 4/4 general test2, 10/10 large input, 10/10 medium input, 4/4 performance tests, 10/10 small input, and 6/6 super input), yet I'm still getting the Execution TImed Out error. I removed all my print statements and it's still failing this. Anybody else experience the same thing?
Update: I figured it out! I was using the built in strcat function, which according to how strcat works (https://stackoverflow.com/questions/21880730/c-what-is-the-best-and-fastest-way-to-concatenate-strings) it always loops from the beginning of the string to the end, and then appending the new string to it. Therefore for longer bf programs, the longer the translated program is, so the longer strcat would take to complete.
I replaced it with my own strcat function such that it keeps track of the last index of the string instead of finding it. Gained a huge performance boost as a result!
I saw this pattern under expected
} while (*p); if (*p) do {
e.g ][ but OP told us to remove it yeah?
So why is that expected?
[]
is redundant (technically it depends on the current cell value, but for the purpose of this kata it is) but][
is not ;-)... My mistake. If *p is false the next if wouldn't run at all
This comment has been hidden.
nah, don't change '+++,' to ','.
Thanks!
wouldn't ",," also be a useless command?
Strange, but not removable in optimizations - one reads a character from input, throws it away, and then reads another. If you think of input as a byte stream, it makes more sense - you're deliberately skipping a byte to get to the one after it.
yeah I know better now :D thanks
Is this normal?
Do I need to optimize my code or something like that? The instruction does not contain any requirements about it. I think one of the tests (all passes) tries to translate very big string.
Thanks in advance.
That's what I thought. But there are actual optimization steps you'd have to take.
currently, the kata mentions:
This comment has been hidden.
that's a shortcut. Your code should be able to handle any kind of "simple" simplifications.
shouldn't BF code like [[[[...]]]] be optimized to [...] as well?
yes. It's already what you have to do.
then why this test expects unoptimized code?
Failed asserting that two strings are equal. Expected: 'if (*p) do { if (*p) do { putchar(*p); } while (*p); } while (*p); ' Actual : 'if (*p) do { putchar(*p); } while (*p); '
Mmmmh... :/ Seems you try it in php? I'm not competent in that language, unfortunately. All I can say is that my code handles this in python and passes the tests. Might be you found an inconsistency between languages...
The simplification is wrong. You should simplify
[]
only if there's no command between the brackets. The input code here is[[.]]
instead.Wow I completely missed part 6 of the description and spent a good hour debugging it. Passing all fixed tests and no random tests was kind of annoying.
This kata would definitely benefit from some more complex, deeper nested examples.
Nevertheless, a great exersize !
in cases like this, you can always add your own to the sample tests file - knowing they don't have to be meaningful brainfuck programs, it's not too hard to throw some together and work out what they ought to optimize/translate to.
basic tests 1 and 2 succeed but all random cases fail. As "ooflorent" already mentioned, my solution for
[+..,,]
also outputs:The translator did a bogus version for C++ and C, and never corrected them. Unfortunately, nobody with the competences in these languages came by to fix them.
EDIT: no need to raise them same issue several times.
When i press to "attempt" button i get an error exec_failure. What could be a resaon for this and how can i fix it? Sample tests work fine.
might be, too much information printed to the console (do not print anything in this kata when using attempt).
Note: it's 2 kyu kata, and a difficult one to debug because you often have no clue of what's going wrong (just as you're facing now). Are you sure you wanna fight against this one now?
Yes, i had one test-print. Now it works, but i pass only 3 tests ( random-small/medium/large ) and then have "Process was terminated. It took longer than 20000ms to complete ". So, i need to do it faster? It's interesting, that's why i am doing it :)
Yes, that's it. You have to do the same thing faster, now.
This comment has been hidden.
Solved it!
for (char c: input.toCharArray()) ...
) are "slow" by essence (but it's possible to achieve the task if you use it only one time).EDIT: too late... x-)
This comment has been hidden.
After a bit of hair-pulling, the answer turned out to be quite easy. Now, to do it in Java!
As already mentioned by @ooflorent, the optimization which deletes
[]
is not correct. I suggest to add a new optimization which transforms[...][..]
to[...]
. This optimization is correct and it can significantly reduce the translated code size in some cases. It also makes this kata a little bit more interesting.Coffeescript translation
Another issue, your solution wrongly translates
[+..,,]
. It outputs:Whereas the expected result is:
I went ahead and edited ZahNarztiK's Javascript translation. It contained typo in solution (was checking
c
instead ofc[0]
). Also, added couple cases to test repetition of..
and,,
.I think there an issue with the expected solution.
+[]
should translate to:The infinite loop is intended!
Shouldn't '[]' be removed in optimization?
Good point. Resolved.
Javascript translation has issue with random tests. All general tests pass fine (in ~100ms), but none of random tests pass. And since they print no expected result, it would be a nightmare to try and guess what they really expect. Please fix it so it prints expected string in case of mismatch, and stops testing (for performance reasons).
I went ahead and edited ZahNarztiK's Javascript translation. It contained typo in solution (was checking
c
instead ofc[0]
). Also, added couple cases to test repetition of..
and,,
.Errr, well that's not actually an issue, but why on Earth did you chose to translate
[***]
byif (*p) do {***}while(*p);
and notwhile(*p){***}
?Simply by mistake. :D
P.S. I'm sorry.
Ah ah NP it just startled me so hard I had to say it somewhere xP
JavaScript Translation and PHP Translation of this kata have been published! Please review and approve! :D
Which one is right? (I guess the former is right, just want to be sure.)
The latter.
Can you increase timeout for Java please? 20 seconds for ~90k of lines isn't enough
Nope. It's 2kyu, you'll have to deal with the performances.
Thx, figured out strings optimization
every time i try to submit by solution it gives me an network error.
(code in comments)
This comment has been hidden.
it seems to be an issue with "import re"
Not an issue.
Actually what you're facing is that you print way too much things to the console and that is what makes fail your code (for now, at least). This kata is demanding about performances and present some difficulties in that it's sometime difficult to see what is causing failure because the debugging print statments can make fail yor code by themselves.
Some inputs contain several millions of characters.
"Network Error
This error was caused due to an issue processing the web request, not because of an issue executing your code."
the fact it said it was not an issue executing my code was quite misleading.
yeah, I know. Unfortunately, there's nothing that can be done about that... :/
I attempt but the network errors keep showing up for no reason. It's not timeout, it said network cannot process the request, and this problem only happen in this challenge. Please Help!
"This error was caused due to an issue processing the web request, not because of an issue executing your code. You can retry the request." I attempt before and I have error, so I fix my code, I pass all the sample test, but when I attempt, this network error show up everytime. Please help!
@Varveyn , Can you check if there's something wrong with the compiler / tester? I have made a solution which passes the supplied tests. But when I “Attempt” it the only thing I get is this: https://i.imgur.com/iikigTl.png It's an Internal Server Error (500).
language?
Be sure you do not print ANYTHING to the console, because it may produce this type of problems, considering the size of the inputs. Avoid recurcive solutions too, for the same reason.
The language is C.
I am printing nothing to the console.
The solution is not recursive, I do use a loop however. The maximum function depth in my code is 2.
I allocate the output buffer with malloc and I have tried different values. All sensible values work with the supplied tests.
Most of the times it works it keeps failing at the large input batch. It passed the first two, but the third not. I tried upping the amount in malloc and it still doesn't help. Most of the times, though, I would say 90%, I get the upper error and this one https://i.imgur.com/xuqnUnQ.png
To me, a person who doesn't know much about the infrastructure of codewars, it seems that the “Attempt” servers aren't really stable with big input or output. I may be wrong, but what should I do to make it work?
So it still fails three months later. Is there a solution to the problem of the servers giving 500s?
I'm looking at the C translation, pretty the test suited areto blame. Made a C solution myself, it was consistently crashing on one particular "random" test, after quite a bit of head-scratching and poking with a stick, I found what seems to be a fix - it's calling an assert method with an output format string and 3 strings to plug into it - the complete, 100000-byte bf program, plus both the actual and expected c programs. After dropping those inserted values, all tests pass.
Not sure if this is the cause of any or all the problems or not. Hopefully a fix will be coming soonish, though!
In the Python solution, I keep getting a timeout, saying my code takes over 12 seconds to complete.
Now, my code may not be optimal, but on my run-of-the-mill desktop machine, even the code sample at https://pastebin.com/SaU5Jfcv (mentioned in the comment from Naiten) completes in under a second.
the sample tests represent at most 0,000001% of the performance requierment. They are just present for you to check the correctness of the basic requierments, not the performances.
EDIT: I missread your comment, but the result will be the same: the tape you found on this link is a rather small one and there are 10 tests for each size of tape (size up to several millions of characters for the performance tests (only one test) or ten thausend for the random tests)
all well and good, but only 3 things are mentioned in the requirements:
If there is a hidden requirement, such as "and it should be able to process 90k input in under 12 seconds", that should at least be mentioned. Furthermore, the time you get seems to be different per programming language (20 seconds for C++). This makes it a rather unbalanced problem IMHO.
I guess you can expect the participant to create efficient code, it is 2kyu after all. But this requirement seems too well hidden, and too random for me.
In performace test, there is a test input string which length is 18 000 000. and the output string's length is 164 000 000. In java, trying to build a string with a length of 164 000 000 will cause out of memory since the return type of test method is string. Thanks for any advice to pass the test? Thank you!
There are dedicated tools/objects in Java for this type of stuff, just use them. ;)
Thanks a lot for your reply and help. I googled a lot and cannot find a way to build such a huge string in memory to return. I tried ByteArrayInputStream and FileInputStream and FileOutputStream. Could you please give me a hint on what class or api I could use to solve the issue? Thank you very much.
Asking for help and downvoting my comment at the same time...? Weirdest thing of the day, I bet...
It's 2 kyu, I won't give you the answer straight away (especially considering that it's a really basic knowledge that you seem to be missing)
Thank you very much for the hint. The downvoting is my misoperation in fact, sorry about it. Finnally fixed the issue haha.
Well, I finally managed to solve the problem, but my code still hits 20000ms limit. Any chance that limit can be set a bit higher? Or can this happen because of high server load? I'm often getting a timeout even on sample test in this exact kata right now.
might be (servor overload): my working soluiton just time out one time over two attempt. Maybe try again later.
This comment has been hidden.
the random tests use BIG inputs (up to 100000 characters). Paste your code here (with the spoiler flag), I'll take a look.
This comment has been hidden.
This comment has been hidden.
I thought it could be the recurrent purifier, but it only iterated 27 times during small test, 56 times in medium and 3 times in large when I attempted last time... Not that much to make a deal, but definetely needed.
ok:
EDIT: yep, correcting these stuff, your solution passes the tests. Think about "fundamentals" ;)
This comment has been hidden.
Oh my gosh, it finally passed... .O.
This comment has been hidden.
Ah, thanks for explaining.
Here's an example of medium and small tests https://pastebin.com/SaU5Jfcv https://pastebin.com/HaRSwc7n The error message was trimmed and I can't see what's wrong with it. Neither can I see any mistakes or errors in the code. And yet I pass the sample tests and super test... https://i.imgur.com/nuS7etl.jpg
language?
Ah, forgot that. Java.
So that's not normal at all, that you're passing the last test because its implementation is exactly the same than for the other ones. Only the length of the tape is changing. Really weird. Actually, I rather believe that the last test does not pass either but you get the green formatting because of the time out (which means your code is not performant enough all the same).
I have raised up the trim limit of the output to 1500 characters, you should be able to get the full message for the small set of random inputs. If not, be aware that you'll often have several
]
at the end of the random tapes. Might be your code doesn't manage properly this particular case?Well, it was my fault. Idk why, but sometimes series of > and < commands were interpreted as singles. Reworked the solution, and now it passes small and medium tests, but fails with timeout... Should think of something more efficient.
ok, resolved.
Argh, I passed all the sample tests, but none of the final tests. And I can't even get what is wrong, because both the output and error meccage is trimmed.
A really enjoyable Kata, thank you. I completed it in python and think that 2 kyu is very generous, I would have thought 3 or 4.
I agree, it's too easy for 2 kyu. But thanks for the points! ;-)
What's actually "funny" is that the usual way to implement this kind of things (parsing a language string) doesn't work here because it's too much time consumming. And so, one have to use something more... "brutal". Let's rather say "direct", it's more appropriate here. Something that is especially like the way daddepledge and you are used to code, actually. ;)
EDIT: performances of both your codes are impressive, btw :)
I didn't realize that performance was an issue here :-)
I only struggled with the time-outs caused by too much output...
help
Java translation (
super input
tests included), please review and approve!This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Hint: try counting braces.
[C] This only happened once out of 20+ submissions but it suggests that the reference solution is flawed:
In the "expected" part of the failure message, the first line of C code is
*p = getchar();
which corresponds to the,
command; however, the input BF program starts with the characters.4,.
which means the first line of C code should have beenputchar(*p);
instead.Please approve C translation
Approved!
Thank you
Somebody to translate this to other languages (python, java... By any chance...? ;p)?
(keeping the target output language to C, of course)
When I press the "Attempt" button to run the Submit tests, the test output states that I have successfully passed all six test groups (namely
general_tests
,general_tests_2
,performance_tests
,small_input
,medium_input
andlarge_input
) but for some reason the test suite still timeouts. Does that mean that my solution has a logical error which fails the 7th test group (following thelarge_input
in the random tests, if any) or does it mean that my solution is not efficient enough? If the latter is the case then shouldn't theperformance_tests
test group display a failure message instead? Looking forward to an explanation, cheers :)There is one more test group:
super_input
. The input is randomly generated and is 10 times larger thanlarge_input
.Timeout may be caused by string operations.
For the record,
performance_tests
are strings that, once reduced, become very short.super_input
will still leave you with around ~90k different segments even after reduction.Some approaches (I won't say what it is, but it should be obvious ;-)) will die horribly at
super_input
for exactly that reason.I can pass the sample tests just fine, but for the past half hour I'm getting continuous timeouts when running the full tests. Error message: -- Request Error: Network Error
This error was caused due to an issue processing the web request, not because of an issue executing your code. You can retry the request.
When I run a sample test after that, it will just pass fine again.
What the heck?
This behaviour continues for a day already
Filed a bug report for this
This seems to occur if there is too much output written to standard-out. Since some of the test cases can be very large, it's easy to end up writing too much output for this test. Try removing any debugging output.
Based on some of the older comments, it appears that people used to receive this error instead:
Perhaps that functionality has changed or is broken.
It does indeed seem to be related to too much output. Removing ALL stdout gave a 'regular' timeout.
This comment has been hidden.
You can wait for the author to approve it :-)
Approved!
Approved :-)
But I have to say that if the answers to my questions are both "omitted", things would be more interesting and realistic. (Wouldn't be much harder though)
This comment has been hidden.
Kept in both cases.
This comment has been hidden.
Looks like my guess is correct. If the algorithm works and no error message is output, then no timeouts.
Please fix your test cases.
I got the error message "Failed to process output. It is possible that too much data was written to STDOUT.". And my solution this time is: (so it's clear that the error is from YOUR code) std::string brainfuck_to_c(std::string source_code) { return ""; } By the way, I solved the problem too, the basic tests are good, and I hope we will be able to fix (somehow) the other tests.
It must be caused by the solution validation assertion. Some of the tests are quite large and can't possibly be written to STDOUT. I'm currently looking for some assertion documentation to rewrite that part (remove standard assertion output).
N.B. I don't like C++ assertion library used on Codewars...
Anyway, I've fixed that part.
Great job. As you can see, this way I could submit succesfully my solution. Thanks.
[]
is not a meaningless statement, it depends on the contents of the tape. Either it will leave the loop, or it won't. In general it is undecidable (i.e. halting problem).Yes, I agree. But there is no point in using that expression in programm.
I'm having some problems with the build server. I've optimized in several iterations and have reached a point where I beleive my code is efficient enough, but I keep getting these stupid problems with the builds (only the "Attempt" builds, the "Run Examples" works fine).
Sometimes it complains about JSON errors, sometimes I get HTTP 500, and currently I'm stuck with "Failed to process output. It is possible that too much data was written to STDOUT." even though I don't write anything at all to stdout.
I think that the tests might be a bit on the heavy side for the servers, what do you think?
I have the same problem.
The example tests are ok, but the complete tests can never be done. It seems the problem with the performance of the tests (too big, too much for the codewars resources).
It takes at most 2 seconds to test my solution (I've tested it right now - it took 1364ms).
If you cannot pass the performance tests section, probably your code isn't optimal enough. What is time complexity of your solution? Also, big output may be caused by the error in the solution. 'DoTest' function tries to output actual and expected results, which can be quite large.
This comment has been hidden.
Do you mean, O(n) iterations through the source_code string? That gives you O(n2).UPD. My bad, I've got your idea just now. It seems to be optimal enough, but there may be small hateful bug, which makes you suffer.
P.S. Finally there is one solution (except mine), so I believe that kata is solvable.
Ok. I think that it is a problem that the test suite outputs horrendeous amounts of crap if one of the big tests fail and I'm not sure how to solve this so that it is possible to figure out what tests are failing.