5 kyu

My smallest code interpreter (aka Brainf**k)

1,840 of 8,315ssineriz
Description
Loading description...
Interpreters
Algorithms
  • Please sign in or sign up to leave a comment.
  • xmy Avatar

    Check that you used correct indices. I used indice from out loop in inner loop and spent close to 50 minutes printing everything to see why timeout happens.

  • YurichBRO Avatar

    BF translation: how many nested loops should the solution support?

  • Egor318 Avatar

    Очень хорошее Ката. Автор молодец, огромное тебе спасибо. Все удачного кодирования!

  • KSTNR Avatar

    The description talks about ASCII-Values for input and output. ASCII has values from 0 to 127. Yet, the last input character of the first test example has a value of 255. My code looped forever until I figured this out, because that character does not have an ASCII value. [ In Swift: Character(UnicodeScalar(255)).asciiValue == nil ]

    Please change the description.

  • rezaie01 Avatar

    Hey everyone, I am solving this kata using kotlin, and my solution passes all the testcases, but the fibinochi one. In the fibinochi testcase, my program outputs: I7, 1, 2, ..... As you can see that the problem is in the beginning. Does this have happend to anyone?

  • www.BCFCODE.ir Avatar

    It might be a good idea to include this crucial tip in the instructions for this awesome kata: "Brackets must be matched based on their nesting level. This means you can’t simply jump to the next ]; instead, you need to track the depth of nesting to locate the correct matching bracket.

  • Uoao1807 Avatar

    Can someone summarize the content in 100 words?

  • FRANKKKO Avatar

    Could anyone please point me (pun not intended) in the right direction? What sort of material and topics do I need to learn before being able to solve this? (C++)

  • windhu Avatar

    Need to be careful with nested brack.

  • The43rdDev Avatar

    I came back to this kata after 4 years

    Amazing

  • Alexcarv318 Avatar

    this shit was at the same time the worst and the better problem I ever solved

  • Ximasumr Avatar

    I regret doing this kata

  • juanpavon Avatar

    Awesome kata!

  • alex_duty Avatar

    hi! first 3 test is working, 4th is working on visual studio, but i constatly get 'IndexOutOfRangeException' for the 5th test. Nonetheless, it is still unclear what to to for ',' if input is empty?

  • emria8406 Avatar

    C fibonacci tests are certainly wrong 👎

  • Volador Avatar

    (C++) I can pass the 3 basic standard tests, but get a timeout when I use the attempt button. I'm trying to debug, so I was trying to print out the code and input to see the test. However, when I print out the input, I get a bunch of unknown characters that I can't read. What can I do to find out what the tests are expecting as input/output? I can't see them. There's also no "Expected this and got that" sort of message.

    For example, for cout << code << " " << input << std::endl;

    I get:

    ,+[-.,+] Z`�3Q�C��ſ"|y�%�]:�

    ,[.[-],] Z`�3Q�C��ſ"|y�%�]:

    If I try to feed these to some online interpreter to see the expected output, it of course doesn't work. How can I find the input and expected output of the tests that I'm failing?

  • p-romeo Avatar

    How is this a 5 kyu??

  • saudiGuy Avatar

    This comment has been hidden.

  • Sir Umbra Avatar

    This thing broke while loops.

    I decrement var i in while(){}. When it reenters while, (because of the condition) i is the value before.

    The increment is somewhere far below the while loop.

  • dbtx Avatar

    My old (working) C solution with a modified prototype passes should_work_for_a_few_simple_examples and should_work_for_more_complex_examples_with_randomness, then segfaults at should_work_for_a_few_runs_of_a_fibonacci_program. I fprintfed that program and ran it through my solution for Valid Braces to find that they aren't valid. I don't know what else changed, but the last item in the description says we shouldn't ever need to check for that. The same item also seems to promise that the data tape will expand automatically, even though we have to allocate it in the first place and simply "make it big enough", so I don't quite know what to think.

    edit: by 'data tape will expand' I really meant this: "Error-handling, e.g. unmatched square brackets and/or memory pointer going past the leftmost cell is not required in this Kata." It didn't say anything about dynamically resizing, and that's just one way to make the claim that I will never have to worry about it. But it's potentially confusing. The memory tape is supposed to be infinite, so there is no "leftmost cell". Maybe it only means that the BF programs supplied are supposed to never take the data pointer lower than the initial location, and that you don't even have to initialize the data pointer somewhere farther along the tape in order to be safe, which I did anyway.

    But it seems that my segfault comes from walking off the edge of the code string while looking for a matching brace that doesn't exist. gdb says the instruction pointer is at 147424 relative to the start of the program string which seems to be 504 bytes long.

  • Nikoloz Baratashvili Avatar

    so in C# string iterpreter thing "Codewars"+char.ConvertFromUtf32(255) specifically convert from utf32 returns this character ÿ and in total string is Codewarsÿ so what the heck should i do with this XD, thanks =)

  • Horneringer Avatar

    So ladies and gentlemen...

    In one of the tests I get the following

    Expected: equal to "1, 1, 2, 3, 5, 8, 13, 21, 34, 55" actual: ""

    How am I supposed to guess where the problem is? How should I understand which Brainf**k language command was used? How should I understand whether the string was supplemented with some characters or not (unless, of course, I need to know this at all)

    Your options, dear)

  • AllBecomesGood Avatar

    No idea why, but sometimes Test4 passes and sometimes it doesn't. C#. Currently still trying to pass Test5, soon gonna rip my hair out btw

  • mouthbreather Avatar

    My C code seems to retain data from the previous test, each test passes on their own but together I get Hodewars. I am initializing my data array inside the function and have even added memset to try to fix it, not sure whats going on.

  • Mr.Andy Avatar

    For c++ the first testcase is ,+[-.,+] this calls , on an exhausted input

  • dolce_zorro Avatar

    Hello !

    The TypeScript tests are invalid, when I test my solution it replies:

    TSError: ⨯ Unable to compile TypeScript:
    test.ts:1:27 - error TS2306: File '/workspace/default/solution.ts' is not a module.
    
    1 import { brainLuck } from './solution';
    
  • ahmet_popaj Avatar

    Super nice kata to solve, I had a lot of fun with it.

  • Tony308 Avatar

    I don't understand the task. The inputs are string of code that does xyz, I understand. Byte array from the String also given as input which you use only when , code is reached?? Everything else, I don't. Am I supposed to initalise a byte list/array and use this with the data pointer? Or is that from the String input??

  • Saftur Avatar

    [Clojure] Description says to assume that , will never be invoked when input stream is exhausted, but there is a test for "insufficient input" that is just "," with an empty string as input.

  • experiencethebalanceoftheyinandyang Avatar

    I just really want to punch myself in the face right now, I can do crap, everytime I come on here it's hard I just can't I FREAKING QUIT!!!

  • vdgtbsgs Avatar

    This comment has been hidden.

  • rmnzndlr Avatar

    Luck yeah! What a great challenge it was))

  • rmnzndlr Avatar

    Another question is about brainluck code itself. Let's take first sample text. ,+[-.,+] What would that supposed to mean? It is an infinite loop, isn't it?

  • rmnzndlr Avatar

    I don't get what means the second argument in process-method in tests: "Codewars" + ((char) 255) What does it for?

  • gomox79 Avatar

    Hi, I'm doing this kata in C. My code runs fine until the "more complex examples with randomness", where the output is just "Expected: Hello World!, but got: (BLANK)". I printed the inputs so that I can run it on my IDE (Codeblocks) and it runs fine, outputting "Hello World!" as expected. The codes are the exact same, so I'm not sure what is wrong. Anybody has any ideas?

  • WeiCODER Avatar

    This comment has been hidden.

  • thamill Avatar

    C++17 grading seems to be broken for this one. My solution works for a half dozen random inputs in testing using g++, but "identical" looking non-printing in both my result and the expected make debugging extremely difficult when submitting.

  • Pklerik Avatar

    This comment has been hidden.

  • geron-d Avatar

    On the java When use an array passed test, but not passed attempt Failed on the testTwoNumbersMultiplier, which passed on the level test On the local all tests passed without fails Same code reworked on the array list passed test and attempt without fails

  • Kacarott Avatar

    (Brainfuck translation): No (proper) random tests.

    Additionally, the rank of BF translation of this kata is too low, it should be at least 4kyu. This probably has not been noticed before, because except for one other solution besides mine, ALL solutions (including the reference solution) are direct copies from someone elses work on an external website. A BF version of this task should be standalone, and should not be designed to perfectly match an existing online solution, just so that the reference solution can be lazily copied.

    This translation should be nuked.

  • hlebas  Avatar

    Great Kata, helps to understand this fancy programming language

  • SemenovVD Avatar

    It was very (though oddly) enjoyable and satisfying hour, thank you, author.

  • Sven Viking Avatar

    The description says:

    "Your memory tape should be large enough - the original implementation had 30,000 cells but a few thousand should suffice for this Kata" and: "The memory pointer should initially point to a cell in the tape with a sufficient number (e.g. a few thousand or more) of cells to its right."

    However in C# at least, no test case requires more than 15 memory cells. Even if using the same memory tape for all tests without ever clearing it or winding it back, only 24 cells are needed. If this is intentional, the description's references to requiring thousands of cells should probably be changed

  • Prateekrajdasari Avatar

    This comment has been hidden.

  • roansong Avatar

    I thoroughly enjoyed this kata. I had heard of brainf##k before, but never taken the time to understand how it works in practice.

  • Hyrtsi Avatar

    It was a bit difficult to get started at first.

    There were a few traps:

    • outputting the byte means appending it to the return value that is returned in the end
    • it wasn't discussed how the program ends but it ends after we've processed all the instructions
    • instruction ',' reads the first unread value in the input data so it doesn't read anything twice which is different from data pointer behaves: you can output the sama data many times and edit it many times
    • [ and ] matching must be known for the programmer

    nonetheless I was able to solve it and I had a good time

  • Schr0 Avatar

    Why MY WHOLE FUNCTION START ITSELF AGAIN FOR NO REASON. It works in clion but not here. Disappoint

  • user9526662 Avatar

    Problem: Solution is predictable and users can pass without actually programmed the interpreter Solution: Randomize the "code" input

  • naashw Avatar

    I did it' let's goooooooooo, so much time spend just for the last test fibonacci... 😅😄😄

  • Bigoh20 Avatar

    I did it!!!! :DDDDDD

  • Bigoh20 Avatar

    Day 3: I can't even figure it out how to do the loop system :(

  • Bigoh20 Avatar

    I just can't come up with anything :'(

  • Bigoh20 Avatar

    I don't get it. The , is a char that needs to be convert into a int ascii code?

  • akar-0 Avatar

    COBOL translation, please review carefully (author inactive).

  • nedigan Avatar

    how does the input even work?

  • hqqe Avatar

    finally i've made it. it didn't work until i understand, that pointer input and data poiner it not the same and i should create new poiner:)

  • Soikk Avatar

    Confusing instructions. It says
    "-[: if the byte at the data pointer is zero, then instead of moving the instruction pointer forward to the next command, jump it forward to the command after the matching ] command."
    and
    "-]: if the byte at the data pointer is nonzero, then instead of moving the instruction pointer forward to the next command, jump it back to the command after the matching [ command."
    but really, you have to move the instruction pointer to the matching "["/"]" command. Had to use a debugger to realize this.

  • deniskaroms Avatar

    This comment has been hidden.

  • ejini战神 Avatar

    Missing return type in initial soluton of TS

  • d.cost Avatar

    Wow, this took some time. If you are having trouble understanding how it works, doing it manually on a piece of paper might help. A little tip from me - if you are doing this on JavaScript make sure when you are checking/incrementing/decrementing the cells they aren't undefined. That stupid mistake took me a lot of time to notice.

  • AdityaGupta030697 Avatar

    The solution wasn't too hard, but the instructions were a little bit difficult to understand.

  • mrjoe3012 Avatar

    Excellent Kata!

  • benjvdb9 Avatar

    This comment has been hidden.

  • apine35 Avatar

    My C# solution works in Visual Studio. However I'm unable to get it working here because it does not allow compiling as unsafe. Unsafe is needed to use pointers in C#. I could make a work around that doesn't use pointers, but it feels like that would defeat the purpose of this Kata.

  • klaus234 Avatar

    Nice Kata, give me a lot of trouble the Fibonacci Attemp because of the nested brackets :P

    I suggest to put this example with an unused loop in the Sample Tests: ,>+-[+++[+-++]]<+.

     Input: "a"
     Output: "b"
     
    
  • yuanyanhui Avatar

    I have two questions about the problem statement.

    1. , accept one byte of input, storing its value in the byte at the data pointer.

    Does the data pointer move forward to the next cell after the operation?

    1. [if the byte at the data pointer is zero, then instead of moving the instruction pointer forward to the next command, jump it forward to the command after the matching ] command.

    In the second test case: brain_luck(',[.[-],]', 'Codewars' + chr(0)), for the outer [, the mathing ] is the last instruction. This means there is nothing after it. What should I do here? End the pogram or loop back to the start of the instructions?

  • jsara Avatar

    Can anyone share the Fibonacci test? In Dart's version, it is not shown.

  • szelga Avatar

    This comment has been hidden.

  • maazza Avatar

    really nice kata, worth mentioning that brackets can be nested, was not that clear from the description

  • SunMaster Avatar

    I found my c-language solution obsoleted. When trying to make it work again I struggle with the fibonacci part.

    First - the error message looks like :

      Expected the first term of the Fibonacci series with input byte(1) (actual: :)
      
    

    So it does not show what is to be expected.

    Second, the data used as input varies from attempt to attempt. Is this by design ?

    The last 6 attempts has used

    10 5
    7 5
    3 8
    9 6
    2 8
    3 3
    

    as input data. The fact that it changes if the larger or smaller number comes first is what has me wondering. Also the pair of 3s.

    The simple tests seem to run fine, also the more complex with randomness.

  • shihab3119 Avatar

    Hi! Can't seem to understand this kata. Can someone please explain? :)

  • ajmcateer Avatar

    This comment has been hidden.

  • Marva Avatar

    Doesn't work because of 255 character is interpreterd by C# as 63, that's why test 1 just loops and I can't go futher. Input gives ÿ character. Idk what to do. Any ideas?

  • zLuki Avatar

    Very nice kata!

  • glorper Avatar

    This comment has been hidden.

  • user6657767 Avatar

    Hi! As at now my code works. However, when I attempt, timeout error is always displayed. Is it possible to write this code without looping through the instructions once? (As this is what I did)

  • Alyasevich Avatar

    Hi! When I test my solution, I have the error:

    Test Crashed
    Caught unexpected signal: SIGSEGV (11). Invalid memory access.
    

    But when I test my solution with the same tests on my machine(Compiler -- TDM GCC), everything works correctly. So, I think that the problem in tests.

    I will be glad to any feedback. Thank you in advance

    Programming Language -- C

  • sli4 Avatar

    I'm having a lot of trouble with this one on python. The wiki on brainf*** helped me understand the process/movement of the commands but now I'm stumped with the actual input/output side of things. When the input is a string or a string + chr(#) it's characters are passed as a string automatically. My code, which is using integers (+/- 1) depending on the command, is running into type errors with strings/int/bytes. Am I looking to convert the input string to bytes and all of my +/-1 integers to bytes (like +chr(1)) and on the "." command convert it to string again? I tried string.encode() on the input - but then I'm dealing with another conversion. Same issue with bytes([#]) for converting the ints. In the first test the input is "Codewars"+chr(255) which shows as "Codewarsÿ". I believe the input code's commands should ultimately +1 so that the ÿ (chr(255)) becomes 0 so it completes as "Codewars" The closest I was able to get so far just adds a single space/character to the end of "Codewarsÿ" instead of altering it - but that eventually errors out anyway because of str-str/other type issues.

  • mjpieters Avatar

    The Rust translation lacks random tests.

    Rust kata can use the rnd crate these days, see the Rust language page in the wiki.

  • mjpieters Avatar

    ASCII is a codec with 128 characters, from 0x00 through to 0x7F, inclusive. It's a 7-bit standard.

    Yet, the Python test at the very least assumes that chr(255) is valid input; that makes the input require an 8-bit codec. It's not ASCII, so I had to assume Latin-1 (ISO 8859-1), which is a superset of ASCII.

    Please correct the description.

  • korziee Avatar

    Very satisfying to finish this, a tip for anyone stuck on the fibonacci sequence: read the instructions for this kata VERY carefully.

  • gscharf94 Avatar

    I recently joined this website and a lot of the problems I thought were too easy.. and then this one came along and I thouroughly enjoyed it.

  • Drblessing Avatar

    This was so hard, but I feel accomplished in doing it . Yay!

  • user7445252 Avatar

    Can anyone tell me what this error means for C:

    Test Crashed Caught unexpected signal: SIGSEGV (11). Invalid memory access.

    Also can anyone give me the test inputs for random test 5

  • IdenR Avatar

    This comment has been hidden.

  • tluge Avatar

    When I "attempt", the fifth test fails due to "Max Buffer Size Reached (1.5 MiB)". I am wondering where I can look up the test case to understand what is happening. Any pointers?

  • aburd Avatar

    I'm having trouble in the Rust kata understanding what it means to "accept one byte" (with the , instruction). What exactly does this mean? A byte from where?

  • B3nCr Avatar

    I'm struggling now, the tests pass and they pass quite quickly but when I attempt it times out.

    The only loops in my solution are the main program loop and something that does bracket matching so I'm assuming that it's a large program that has lots of [ ]

  • Coderwonderland Avatar

    Hello guys, I have following Problem: at the end of the while loop all conditions are satisfied to exit the while. Nevertheless, the code will still execute. I checked the same code on c++ 2017 gdb and different online compiler.... Thats strange and annoying.

  • Voile Avatar

    Random tests are missing in some languages, e.g Haskell.

  • qes Avatar

    I think there should be a validation for wrong code input. like below

    brain_luck('[,+[-.,+]', 'Codewars' + chr(255))

  • gekoke Avatar

    Wow, that was fun!

  • nomennescio Avatar

    Please review and approve my Factor translation

  • tranquility-base Avatar

    This comment has been hidden.

  • Darejkal Avatar

    For c#: Should the solution be cleaner if there is a way to enable and use unsafe code.

  • donaldsebleung Avatar

    [C#] Actual and expected values are swapped in assertions in both Sample Tests and Submit Tests, leading to confusing error messages.

  • mangaka Avatar

    For C version. Be careful with your memory allocations. Although everything looks perfect, some tests won't pass if you don't allocate/initialize the memory properly.

  • SumitKPandit Avatar

    Training in Python 3.

    I don't know what I am doing wrong but my code times out on Attempt. I tried to see code and input using print to console, couldn't see input for many test cases.

    Only thing I was able to figure out was if I remove + chr(255) from the first test case in Sample Tests, I get a timeout because the value at pointer ends up as 1 everytime it gets to [.

    If that is an issue, how can that be handled?

  • MikChan Avatar

    I think you should add correct function signature to the template

    From

    std::string brainLuck(std::string code, std::string& input);
    

    To

    std::string brainLuck(std::string code, const /* <- add this*/ std::string& input);
    
  • RomZdark Avatar

    Is it possible to solve this kata in c#? Just yes or no. I'm stuck with 255 char that appears in code as 63.

  • Zheoni Avatar

    Reading older issues, the C version still doesn't have a 255 ending character. :(

  • m4ch4do Avatar

    I thought I had the solution right but I’m getting this error:

    '11, 11, 2(, 3\x1f, 5\r, 8\xf2, =\xc5, E}, R\x08, gK, '

    should equal

    '1, 1, 2, 3, 5, 8, 13, 21, 34, 55'

    This test has ‘\n’ as input.

    Other tests work fine as long as they don’t include characters with ‘\’.

    I’m I using a wrong codification? I used chr() and ord() to change ascii<->string.

  • arssonist Avatar

    Been working on this for awhile and can't figure it out. Two questions:

    1. The > and < that change the data pointer. Does this refer to the brainfuck code, or the string? Which piece of data is the cursor moving on? I've been using it on the string, i.e. Codewars
    2. How to handle the data pointer when it goes outside the bounds of the data it is pointing to? This is the more imoprtant of the two questions. If the string is a length of 2 and the cursor goes to 3 then what? Not doing anything causes infinite loop for me.
  • leke Avatar

    This comment has been hidden.

  • ShoulderOfOrion Avatar

    (C++) The expected behaviour with regards to running into the end of the input string should be described more carefully. I had to use the input data to reverse engineer the expected behaviour...

  • Deanna1 Avatar

    Just solved this one, its definitely the hardest one I've done so far! The trickiest part to implement is '[' and ']' commands. If you are using Array.FindIndex('[') or something similar you are doing it wrong. You need to pair the brackets, like how brackets are paired when writing code. For example in ,[.[-],] the first [ pairs with the last ]. Also, remember to be really careful about whether you are changing the data pointer or the instruction pointer, it's easy to make a mistake! I found the output from the second test to be confusing, however the issue I had with passing the 2nd test was also picked up by the 3rd test. I am not sure how much memory is needed for the test cases, but when I submitted mine I used a byte array of 10000. However, for the the 3 sample problems, I can pass them using a byte array of size 100.

  • donaldsebleung Avatar

    https://esolangs.org/wiki/Brainfuck#EOF_2

    [Haskell] The behavior for "insufficient input" is inconsistent with accepted standards - instead of failing immediately and returning Nothing, it should do one of the following at least once:

    • Set the value of the cell under the pointer to 0 (like the NUL-terminator in C-strings)
    • Set the value of the cell under the pointer to -1
    • Leave the value of the cell under the pointer unchanged

    This (incorrect) fail-fast behavior expected of the Haskell implementation of the Brainfuck interpreter also means that even simple programs such as a typical CAT program would not be correctly interpreted as it relies on the input string being exhausted by a while loop.

  • trransom Avatar

    I copied and pasted my code into Visual Studio, and everytime I call the method the same way it gets called in the Codewars tests, I get the exact answers that the tests say they're looking for. However, when I plug in the same code into Codewars, the error says that it keeps getting "Codewars" back. I'm sure this is an instance of user error, but does anyone know what could possibly be wrong? Thanks.

  • Dominik1999 Avatar

    This comment has been hidden.

  • _Noob_User Avatar

    While writing a code I was wondering if there are no issues in the code tests (I had some problems with them... (: ). But now I passed and want to say that everything is fine with the Python 3 version. Good luck!

  • LRadomski Avatar

    in 1st sample test (C) ",+[-.,+]" at the end of input string after it reads (,) ending character (\0) it then increments it (+) and this causes to loop again (]) reading next input (outside of range), outputing etc. What do I miss to understand the algorithm. How the loop is supposed to end?

  • qq1326678957 Avatar

    英文不好,被卡了好久,说一下题目,首先第一个参数是指令,第二个参数,是输入,也就是","指令要写入的东西,一次写一个字母,第二点就是"["和"]"指令会跳转,怎么跳,每次要跳转的时候,都要跳到对应的符号那里去,因为中间会有嵌套,都要跳到对应的符号那里去,因为中间会有嵌套,都要跳到对应的符号那里去,因为中间会有嵌套,重要的事情说三遍,这一点题目好像没有体现出来。

  • qq1326678957 Avatar

    谁可以告诉我“,”是什么意思,读入的一个字节数据从哪里读来的啊?

  • user3193374 Avatar

    It should be said that it should stop if it reads input from an empty input.

    It wasn't in the question so originally I just ignored it and it took me a while to realise that it shouldn't do this.

  • mcmlevi Avatar

    awesome kata propably one of my favourites so far. though I feel it's a bit hard for a 5kyu, alhough that could be due to the fact I haven't done many interpreter katas.

    it also gave me an massive headace trying to solve it :D but the end result is so worth it thanks for the kata!

  • cyril-lemaire Avatar

    C version still bugged (the first example doesn't have a 255 ending character, both in test cases and validation). Please either fix or explain what special behaviour is expected when running out of the string.

  • NIaa Avatar

    This kata reminds me of the time when I tried to write a json interpreter in C.

  • ProstoNekitos Avatar

    This comment has been hidden.

  • thaarad Avatar

    Ok I have a question about working command [ and ] if we have list of commands ",[.[-],]" on the second place we have this bracket "[" then on the last place we have "]". So if the last bracket we reach and we have value in memoryCell different than zero, we should go back to this mentioned first bracked on the second place in string (index 1) or to the bracket which appears first when we go backward - on the four place (index in string 3) ??

  • hakatom Avatar

    this kata might be too easy to be a 4kyu kata, but its still super fun, and the solutions here are amazing! thanks:)

  • theDarkBright Avatar

    This should be like 4 kyu. This has been the fastest I've ever solved a 2 kyu kata.

  • CalculusBear Avatar

    Hello, i try to complete kata, but test has error on code ",>+>>>>++++++++++++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+>+<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[-<-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<<-]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<+>>[-]]<<<<<<<]>>>>>[++++++++++++++++++++++++++++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++++++++++++++++++++++++++++++++++++++++++++++.[-]<<<<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<<[-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-]"

    I must find the closest parentheses or take into account the nesting ? thanks

  • jonny_123H Avatar

    This comment has been hidden.

  • dvbuntu Avatar

    Any suggestions for how to debug a memory corruption error? I get *** Error in `/home/codewarrior/solution': double free or corruption (!prev): 0x0000000001a23620 *** after passing the first test. On my local machine, everything tests fine. I'm not using free() at all (just to be paranoid), so I'm not sure what the issue is.

  • emgordon154 Avatar

    Did this kata formerly have Python 3 support? I see down below that about a year ago people were talking about Python 3 solutions? As a Python 3 programmer (and not a good one), refactoring my code to work in Python 2 after working without noticing what version I was coding for was a bit of a pain (: EDIT: omg i just noticed that my JavaScript solution got horribly mangled by its mix of tabs and spaces. how embarassing! i thought i got rid of all the tabs. i'm never going to use Emacs without turning off auto-tabs again

  • rchan510 Avatar

    It seems there is a bug in the last test case in C#. Here is the error message I got.

    Should return "1, 1, 2, 3, 5, 8, 13, 21, 34, 55" Expected string length 40 but was 32. Strings differ at index 1. Expected: "11, 11, 2(, 3, 5\r, 8ò, =Å, E}, R\b, gK, " But was: "1, 1, 2, 3, 5, 8, 13, 21, 34, 55" ------------^

    So obviously my result is same to "should return" but because of the corrupted expected I can't pass this Kata...

  • Sejiko Avatar

    This comment has been hidden.

  • ice1000 Avatar

    Dart translation kumited and approved!

  • TGeo Avatar

    This comment has been hidden.

  • Korrigan Avatar
  • dcbrwn Avatar

    The kata is overrated. It should be 4kyu.

  • codeman869 Avatar

    This comment has been hidden.

  • CarstenKoenig Avatar

    there are some issues with people complaining about timeouts in there code and indeed I ran into the same issue.

    So I really looked around in my code and could not figure out why it should take so long (yeah it's a mess - but after that I don't want to refactor the correct monad stack anymore).

    In the end it was rather simple: there seem to be input with spaces (char ' ') and in my case for some reason the resulting exception/failure ended up in CW complaining about timeouts.

    So I would suggest adding some remark about this or removing invalid characters from the test input

  • anter69 Avatar

    After doing some other "interpreter" katas, it was relatively simple, but a good exercise. However, I'm a bit disappointed to see that the top voted python solutions are over-complicated -- compared to mine ;-)

  • mgiuffrida Avatar

    This comment has been hidden.

  • lichevsky Avatar

    I think this is way too easy for lv2, I've seen harder tasks on lower levels

  • assyrianic Avatar

    C version is broken somehow. I tested out my code on my end with both GCC and Clang 3.5 and it came out correct but the Kata itself says it's wrong somehow.

  • CvxFous Avatar

    ,+[-.,+]

    Endless loop

    In this one (which is in the basics tests), when we get 0 from ',' to announce the end of string, the '+' increase the 0 to 1, so it loop back and overflow.

  • dinglemouse Avatar

    This comment has been hidden.

  • user5036852 Avatar

    CoffeeScript-Translation kumited!

    https://www.codewars.com/kumite/589ddc86ba1f855127000104

    Please check and approve it! :-)

  • Varveyn Avatar

    C Translation kumited.

  • haugk Avatar

    This comment has been hidden.

  • SupremeEP Avatar

    Why does every C++er write so big code? More certainly, why do they use switch-case constructions, while if-staircases are more compact and flexible?

  • Keozon Avatar

    Reposting this at top-level for visibility: Rust translation Please review, and approve. Let me know if there are questions or issues.

  • driconmax Avatar

    Code: ,>+>>>>++++++++++++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+>+<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[-<-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<<-]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<+>>[-]]<<<<<<<]>>>>>[++++++++++++++++++++++++++++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++++++++++++++++++++++++++++++++++++++++++++++.[-]<<<<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<<[-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-] INPUT: 10; STDERR: Process was terminated. It took longer than 12000ms to complete

    It's the only one broken. My code runs all the other codes correctly

  • dacostam Avatar

    "the machine memory or 'data' should behave like a potentially infinite array of bytes"

    Is this the case for both directions (left and right)?

    In other words, is there an initial position in the array that cannot be passed, lest it cause an error? Or is it legal for the program to move the data pointer left and right ad infinitum (similar to the tape in a turing machine)?

  • Keozon Avatar

    Looks like the author is no longer active. Any change of getting a moderator to approve these translations? Looks like the Crystal one was the last to be approved. I would like to write a Rust translation (and help out the very limited Rust library of Kata here) but I don't want to spend the time if no one is going to approve it (well, maybe I will anyway).

  • ArcaneIntegers Avatar
    C++ translation just submitted! Great Kata, I really enjoyed it.
  • brunolm Avatar
  • donaldsebleung Avatar

    PHP Translation Kumited - please accept :D

  • ALYIP Avatar

    nice kata

  • ripesunflower Avatar
  • MazTheMazy Avatar

    Nice kata! The instructions were straightforward and the kata itself wasn't too hard either. Moderate thinking required. :)

  • Matyt Avatar

    Python3: Tests passed, running Submit…

    Time: 130ms Passed: 1 Failed: 0
    Test Results:
    ✔  Test Passed
    STDERR:
    Traceback:
       in 
       in random_token
    NameError: name 'xrange' is not defined
    
  • StaymanHou Avatar

    The behaviour should be specified when the data pointer is pointing to an uninitialized data point. Looks like the current behaviour is setting the uninitialized data point as zero.

  • kevinrothi Avatar

    I enjoyed this kata! Pretty straightforward, but also took some thinking.

  • itsafinn Avatar

    Nice kata, I implemented a solution I'd imagine is somewhat more optimized than a naive one.. at least for the longer, complicated, perhaps even commented programs :D

  • provector Avatar

    Beautiful kata! Was a bit confused with the Input description at the beginning but after reading more on Brainf%%% i actually got it :) Would be lovely if we could complete it in assembler ;)

  • NonStop Avatar

    Nice kata, pretty simple and pretty hard. But 'input' is reserved word in Python, it'd be nice to change it.

  • fanantoxa Avatar

    Implemented not so worst design as saw in solution) For other who'll try: You could print code in input to console, and see exaples that you can use for debugging.

  • j-t Avatar

    My initial solution was too slow (I kept having timeouts) so I rewrote it to compile to Ruby and now it works. I think the nested loops in the final test case murdered my performance (my code to deal with loops was pretty naïve).

    Fun kata!

  • rewk Avatar

    This comment has been hidden.

  • hnaderi Avatar

    easy to implement but very hard to debug it could be a good idea to implement a simple compiler to bf I give it a try

  • zhuli19901106 Avatar

    This is the first time I tried anything about BrainF--k. Never wrote or read it before. I printed almost every parameter I defined, just to locate a bug in my code... It's hard to imagine the daily work of an assembly programmer. Still, this is quite a challenge and a lot of fun. My thanks to the author of this kata! :)

  • siolag Avatar

    There should probably be a test case for the overflow of +, and the underflow of -. The description says that 255 + 1 should be 0 and 0 - 1 = 255, but I forgot to implement this and only noticed after my submission had been accepted.

  • Marx314 Avatar

    This comment has been hidden.

  • pablo.varela Avatar

    Really nice kata! Thanks a lot for creating it. I have translated it to java in case you are interested.

  • Uraza Avatar

    Very nice kata, I had a good time solving it. :)

  • Yuval Avatar

    I can't get the tests (or solution) to run fast enough. I wrote an optimizing system that runs simple (+-<>) loops in one step and runs the test suite in 0.1080 seconds on my machine - and it still times out on CodeWars. Would it be possible to have a compilation option? I think the Haskell Control.Lens package doesn't do that well in interpreted mode.

  • Jim Hartnett Avatar

    Mine wasn't passing the fifth test then suddenly is passed.

  • SnooperSnayk Avatar

    If you liked this one check out my interpreter challenge! http://www.codewars.com/kata/rubyfunge-interpreter

  • SnooperSnayk Avatar

    Great kata! Gives me some ideas for some new ones!

  • SnooperSnayk Avatar

    Quick question, what is the expected behaviour if we use the '<' instruction and the pointer currently points to the first memory location (0)? For example, what would be the expected pointer location if the code vaariable was just '<'?

  • Mihail-K Avatar

    This one was excellent! Short and simple, but still excellent.

  • sanctusraphael Avatar

    This was fun! Took all morning.

  • cheater Avatar

    This comment has been hidden.

  • edalorzo Avatar

    Wow, the last test really gave me a hard time. It took me a while to find my own bug. No wonder they call it a "turing tarpit".

  • Jeroko Avatar

    I get this error: Test Failed: Expected: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, instead got: 02, 2, 3, 5, 8, 13, 21, 34, 55, 89 Any idea what could be going wrong? I have tested my interpreter with almost every program I could get my hands on and it has never failed.

  • Jeroko Avatar

    This comment has been hidden.

  • JagWire Avatar

    I've no idea how to solve this without the test or attempt timing out :-/

  • timmontague Avatar

    This comment has been hidden.

  • wthit56 Avatar

    This comment has been hidden.

  • xDranik Avatar

    Awesome Kata! Had a lot of fun, even though I lost a good amount of sleep xD Wouldn't an interpreter be considered 2 Kyu? (Just wondering)

  • JulianNicholls Avatar

    I enjoyed this one a lot.

  • xcthulhu Avatar

    This comment has been hidden.

  • constablebrew Avatar

    OMG I have had to retype the code three full times because I didn't save my code to the clipboard or elsewhere...

  • constablebrew Avatar

    There are a few ambiguities that need to be cleared up in the instructions:

    • When the input queue is empty and the "," instruction is encountered, what happens? For example: brainLuck(',.','') == ???
    • Is the data array expected to be initialized to 0?
    • Is the data array limited in bounds? E.g. what happens when the data pointer == 0 and the instruction is "<". What happens when the data pointer moves past the length of the data array?
  • nklein Avatar

    This comment has been hidden.

  • eugene-bulkin Avatar

    Okay, I don't get this error: "Test Failed: Expected: w34q3680k9, instead got: w34q3680k9". What am I supposed to do here? When I test it in the console it works perfectly. I don't get what's wrong.

  • jcorbin@wunjo.org Avatar

    Very nice, I would've liked to have had the initial test feature populated, but attempting to submit sufficed.

  • yo.oviedo Avatar

    My solution seems to work when tested on chrome's console, but when tried in here, system says "Code timedout". How fast is it supposed to work?