5 kyu

Esolang Interpreters #2 - Custom Smallfuck Interpreter

1,216 of 4,044donaldsebleung
Description
Loading description...
Esoteric Languages
Interpreters
Algorithms
Tutorials
  • Please sign in or sign up to leave a comment.
  • Urkaz Avatar

    This comment has been hidden.

  • kottticsharp Avatar
    This comment has been reported as harmful. Show
  • RYP_w Avatar

    nice kata, I found the solution in 2 days

  • RileyHunter Avatar

    Random tests in Python do not contain any loops or no-ops, therefore only testing a subset of the specified behaviour.

    Python fork which implements better random testing: https://www.codewars.com/kumite/66c8182e4d7ff9aec7c3b877

    If approved I'll port the changes to JS as well.

  • SS-Stefanov1 Avatar

    Most of the kata I solved in 30 minutes, but I can't get how the [ ] are suppose to be working..

  • Egor318 Avatar

    Отличный ката, как и вся серия. Конечно хотелось бы при решении иметь более подробное описание задачи. Автору ката большое спасибо.

  • saudiGuy Avatar

    This comment has been hidden.

  • saudiGuy Avatar

    python new test framework is required. updated in this fork

  • MikeMKH Avatar

    Why does the C# tests not have an example of '[' and ']'? I do not understand how these work, could someone give a simple example of '[' and ']' in the code string along with the a tape string and the expected result?

  • user3038216 Avatar

    Broken test *[>*] expects all bits to be flipped, but it is only first bit that has to be flipped.

  • CyroClast Avatar

    sisyphean task

  • AXER-doc Avatar

    No examples with '[' and ']' in C++. It's not quite clear for me how they work.

  • cbserra Avatar

    Can someone please provide the expected result for the following TypeScript test? Only one failing for me and would like to debug in my local IDE. Thanks!

    should work for randomly-generated programs

    My code's logging of arguent values/lengths

    🚀 ~ interpreter ~ code = >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><**>*<<<<><<>>*><*>>*>><*>*<*<<*><><****>*>><>>*>>>>**<<*>>**<<>>>*>>*<><>***<*>><*<>>>*<*>>*<><>*>****>>*>*>>>*><*><>><><><><><<<**><<<*><><>**>**><>><<**>>*>><**<*>><<*<<<>>*>*><<<>><*><><*>**<>>>**>><><>>>**>*<***><<>>*>><<>>*<<*<>>>>>*<*<**><<><*>*<**>*<<>*>><><>><<>*><<<<**<>*>***><**<*>*>><><<>>><<<>><>><<<*>>**><<*<<<<><>**>><*>>><*<>>>***>>**<*<><<>>>>*><<>*>*><<>>>>><***>**><<<><><<<>>>*>***<*<<><<**>><>><><><><>>>*><<<<*>*<<*<>>>*<<<<<<><*><**><*>>*<<>*<**<><***>>*><>>><>>**<<>**>*<*<*>*<***>***<<*<*>>>>>
    🚀 ~ interpreter ~ code =  ~ code.length = 1020
    🚀 ~ interpreter ~ tape =  0000011101110000100100111110110001100001101101100110101100011001010111100111100111010011000011010010100001010110011010100000101110001011100001100000100001001011111101000110100011101111101000010010100111101010001010111011100001001001111000000010011101100011111111001011000010000100110101111100101010011111111000100001110001111010111010011010110001101001100010110101100101001000100101000100100111000110100101000100100111101110110111001111110110000001111101010001101011110100111010100111110110101001000101110111001010011110001111100000010010111011110110111101101101111001110101000000101001011011010010110100010000000011000011001100001010011011111100110001010111001010111011001011101101111000110110101110010111101011110111110011101010111111011111010111111111101100100011110001101111011001010011000111001011011010010101010111110010110000101110111110011001110000110111000011101011010011000100110000100100001110010101101111010101010011010000100110001011101110000001111001111111011011111001010000101111010001
    🚀 ~ interpreter ~ tape =  ~ tape.length = 1000
    🚀 ~ interpreter ~ cleanedCode: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><**>*<<<<><<>>*><*>>*>><*>*<*<<*><><****>*>><>>*>>>>**<<*>>**<<>>>*>>*<><>***<*>><*<>>>*<*>>*<><>*>****>>*>*>>>*><*><>><><><><><<<**><<<*><><>**>**><>><<**>>*>><**<*>><<*<<<>>*>*><<<>><*><><*>**<>>>**>><><>>>**>*<***><<>>*>><<>>*<<*<>>>>>*<*<**><<><*>*<**>*<<>*>><><>><<>*><<<<**<>*>***><**<*>*>><><<>>><<<>><>><<<*>>**><<*<<<<><>**>><*>>><*<>>>***>>**<*<><<>>>>*><<>*>*><<>>>>><***>**><<<><><<<>>>*>***<*<<><<**>><>><><><><>>>*><<<<*>*<<*<>>>*<<<<<<><*><**><*>>*<<>*<**<><***>>*><>>><>>**<<>**>*<*<*>*<***>***<<*<*>>>>>
    
    ....
    
    expected '0000011101110000100100111110110001100…' to equal '0000011101110000100100111110110001100…'
    
  • benjaminzwhite Avatar

    Thanks for a great kata @donaldsebleung - I'm starting to work on understanding interpreters (and I just started learning about esolangs) so this kata was a perfect exercise.

    Also, it's just the right difficulty: not too difficult for a first experience but also not too trivial - you have to account for some complexity, and there are some good debugging cases.

    Thanks again! Looking forward to working through the series and other related kata now.

  • NikCSharp Avatar

    [[]>>*>] How does this with a tape of 000 return 000?

  • hoardinghopes Avatar

    Help please!

    • Code tape: [>*]
    • data tape: 00000.

    As I understand the brackets, the opening bracket ([) checks the current value of the pointer in the data tape.

    If the current value is 0, then control jumps to the position after the closing bracket and executes that (in this example, the program terminates as there are no more commands).

    If the current value is 1, control passes to the next command (in this case >).

    Therefore, if I've got this right, this series of commands should immediately terminate because the data tape starts with 0 so the opening bracket should jump control to beyond the closing bracket.

    But the testcase that I'm struggling with expects the output to be 011111, which means that the opening bracket found a 0 and passed control to the next command (>) i.e. the opposite of what I'm expecting.

    Any thoughts?

  • akar-0 Avatar
  • Dan-PC Avatar

    From C++ test cases: [[]*>*>*>], 000 is for some reason supposed to return 000, how??? [ - jump past matching ], since everything is zero anyway

    *> - flip the first bit and go to the second

    *> - flip the second and go to the third

    *> - flip the third, go out of bounds and terminate since we're out of bounds.

    We flipped all three bits, the tape is now 111. My solution passes everything except for this one, even random tests.

  • renku Avatar

    This comment has been hidden.

  • eysidisi Avatar

    This comment has been hidden.

  • einh213 Avatar

    This comment has been hidden.

  • ejini战神 Avatar

    There should be fixed tests with input containing [ and ] in JS at least

  • akar-0 Avatar

    Nice kata. However I think the description is misleading when saying Smallfuck terminates when [...] All commands have been considered from left to right. Indeed, for example in case the code is [>*] and the tape contains only '0', all inner commands are ignored. At first I understood I needed to check that every code's cell was executed at least once before ending, and it's not the case. IMHO description would be clearer if it said that the program terminates when code's pointer (sorry if pointer is not the correct word) goes out of bound, just like for the tape.

  • mrcastro Avatar

    Poorly explained kata, and severe lack of examples to boot.

  • shvedoff98 Avatar

    I pass all test_cases successfully,however after trying to attempt,compiler shows the next warning that leads to abortion. What am i doing wrong?

    double free or corruption (out) UndefinedBehaviorSanitizer:DEADLYSIGNAL ==1==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f294086da10 bp 0x7ffc8c9815c0 sp 0x7ffc8c981370 T1) ==1==The signal is caused by a READ memory access. ==1==Hint: address points to the zero page. ==1==WARNING: invalid path to external symbolizer! ==1==WARNING: Failed to use and restart external symbolizer! #0 0x7ff45c353a0f (/lib/x86_64-linux-gnu/libc.so.6+0x40a0f) #1 0x7ff45c39c966 (/lib/x86_64-linux-gnu/libc.so.6+0x89966) #2 0x7ff45c3a39d9 (/lib/x86_64-linux-gnu/libc.so.6+0x909d9) #3 0x7ff45c3aaf69 (/lib/x86_64-linux-gnu/libc.so.6+0x97f69) #4 0x429a1a (/workspace/test+0x429a1a) #5 0x426f1e (/workspace/test+0x426f1e) #6 0x426a27 (/workspace/test+0x426a27) #7 0x42662b (/workspace/test+0x42662b) #8 0x42d8f5 (/workspace/test+0x42d8f5) #9 0x425cdd (/workspace/test+0x425cdd) #10 0x7ff45c334bf6 (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6) #11 0x404619 (/workspace/test+0x404619)

    UndefinedBehaviorSanitizer can not provide additional info. ==1==ABORTING

  • aarvillag Avatar

    How can check the output I failed? I do not see the code input. I only see the tape input and the output. Thanks

  • clcraig Avatar

    C translation. Please review.

  • Harleigh Avatar

    Seeing a few questions on the bracket cmds, I thought I might try to offer (a rather verbose) explanation of these commands. Nomenclature: The string of commands (e.g. '>') I call 'code-tape' and the string of 0's and 1's (e.g. '10010') I call data-tape. Additionally, 'code pointer' points to the current cmd to execute

    • Cmd "Left Bracket" (i.e.'['):
      • "Left Bracket" command executes if the value of current cell on the data-tape is a '0' (otherwise move onto the next command)
      • Move to the right in the code-tape till matching right bracket is found; once found, consume the right bracket token (hence we jump to the code-cell directly to the right of the matching right bracket)
    • Cmd "Right Bracket" (i.e.']'):
      • "Right Bracket" command executes if the value of current cell on the data-tape is not '0' (otherwise, just move onto the next command)
      • Move to the left in the code tape till matching left-bracket is found. Once matching left bracket is found, stay at the bracket cmd on the command tape (i.e. don't consume it like the other bracket cmd)
    • Lastly, your code needs to be able to manage nested brackets
  • zLuki Avatar

    Awesome kata!

  • mjpieters Avatar

    This comment has been hidden.

  • imWalker Avatar

    I have passed all the test cases,but the cost of time is over, so i failed!

  • AgentMC Avatar

    I suggest to have the "bad source" with unmatched brackets in tests. That way the [ and ] operations processing would be tested for not going out of the code bounds. I feel that my current solution would fail this way.

  • hpv Avatar

    Why I really like this kata is the fact that it was a good example of TDD. I didn't understood the jump description, but started implementing the other 3 commands and passed the user-tests. Of course I failed the final tests, but that is TDD => test - fail - refactore - pass. The explaination in the test-log was really helpfull and after understanding what [] are doing or are expected to do it was simply refactoring. To make sure my already implemented functionality is not broken I used the user-tests and that it what TDD is for: don't be afraid to change and only implement what is asked. Great learning effect - Thanks

  • ekovtun Avatar

    I don't understand what symbols "[" and "]" do. Please give examples.

  • maximus-lewson Avatar

    This comment has been hidden.

  • jerson Avatar

    Me gustó el ejercicio ♥

  • Tahlwyn Avatar

    Any possibility of adding a Rust translation?

  • Welpy Avatar

    C++ translation added. Please review!

  • errajibadr Avatar

    The instructions are so confusing !!!!

    i got it this way :

    [[][][]] the corresponding brackets for the bracket index 0 is the last one and vice versa . but it seems it's not this?

    Can u explain me the right instruction plz, thanks!!

  • mahaveer0496 Avatar

    This comment has been hidden.

  • flanagansshenanigans Avatar

    I have it running perfectly locally, but when I attempt it stalls on the following:

    "[>*]", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"

    Instantanous locally, on your system it times out after 12 seconds.

    If I alter the "Run Sample Tests" to contain the attempt stuff it runs perfectly fine. Only fails on the attempt.

  • yamane10 Avatar

    This comment has been hidden.

  • TanYiXun Avatar

    gotta admit, it was difficult af, but in the end managed to finish it. Good job op!

  • rhink Avatar

    I was confused by the [ and ] brackets in the code, since they aren't mentioned in any of the examples of the instructions. But browsing through the comments I saw some testcases which helped me understand what exactly they do.

  • WeaponMan Avatar

    This comment has been hidden.

  • Feips Avatar

    This comment has been hidden.

  • roh777 Avatar

    Description is poorly written. The programming challenges should have clear and well defined instructions with primitive examples for basic cases of command. The trickiest command of "[" and "]" were not assigned any example cases in attempt. This description ruined the whole KATA experience for me.

  • Naiten Avatar

    The description is a bit confusing. Does the termination case "All commands have been considered from left to right" mean just "the end of command tape was reached" or all the commands should actually be performed? I consider the former and my code passes, but it would be nice if the description was fixed.

  • Naiten Avatar

    Can I get some extra fake internet points for making (possibly) the smallest Smallfuck interpretator? :P

  • ericfmeyer Avatar

    Deleted Nevermind, I was confused... Now working on nested loops.

  • GrahamD Avatar

    Is there a C# test case I can use for nested loops?

    My code keeps timing out, and I can't print the input (my Console.WriteLine instructions aren't getting hit for whatever test is timing out), but I'm fairly certain it's taking too long to process code containing at least one nested loop.

    In Visual Studio, my code runs fine against all the sample tests, and I "Simple Loop" test I devised myself, but I can't find any real-world examples of the kind of test that's causing my solution to timeout on Codewars. :(

    It'd be really great to include such a test in the sample tests for this Kata.

    Edit: Nevermind about the test. I found the bug in my FindMatchingBracket method, which was causing an infinite loop under certain circumstances. I've now successfully completed the Kata.

    It was good, but it took me awhile to wrap my head around the requirements for [ and ]. I'd still definitely like to see a test using those under Sample Tests, and/or clearer instructions for what they mean.

  • rjrahul Avatar

    As per the description it says, ']' - Jump back to matching [ (if value at current cell is nonzero). The statement in bracket 'if value at current cell is nonzero' is not correct. If we encounter ']' we need to always return back to matching '['.

    Consider a scenario where matching '[' was encountered at 0 and current pointer is at non zero it needs to move forward.

  • Charlie Yu Avatar

    This comment has been hidden.

  • Knar Avatar

    This comment has been hidden.

  • Souzooka Avatar

    Hey, I've made a C# translation, please review and approve.

  • b1scuit-thi3f Avatar

    This comment has been hidden.

  • scryptic1 Avatar

    This comment has been hidden.

  • zruF Avatar

    I don't know, whether this is related to the codewars performance or not, but I keep getting this error while submitting my solution:

    The server timed out running the request. This may be due to an issue with the backend server. Please try again.

    BTW: The example testcases are all passing fine.

  • ice1000 Avatar

    Very simple easy kata, actually easier than the 2kyu brainf__k :)

  • henrebotha Avatar

    This kata slew me. Hot damn.

  • imprezobus Avatar

    This comment has been hidden.

  • MP7373 Avatar

    This comment has been hidden.

  • drafa Avatar

    This comment has been hidden.

  • ashrit72052 Avatar

    This comment has been hidden.

  • AndrewTucker Avatar

    Implementing a simple TM in JavaScript was fun. One of my favorite kata so far. Looking forward to the next 2.

  • DaniGoz Avatar

    I'm having an issue with the Java translation:

    It states that I've passed all tests having 0 failures when I click on Attempt but the button doesn't switch to submit my final solution so I can't finish it and get the honor.

    Can you please look into it?

    Thanks.

  • anter69 Avatar

    Thanks, great kata! After doing some other "interpreter" type katas, it was moderately easy :-)

  • wneumann Avatar

    Swift translation kumited. Please review and accept if satisfactory.

  • sarabaduARG Avatar

    Really good kata serie

  • hhummel Avatar

    This series makes me want to learn how compilers work.

  • mkeller0815 Avatar

    This is also a really nice one.

  • ggmoy Avatar

    Ruby-Translation kumited!

    http://www.codewars.com/kumite/58d5c635ba746247150000db?sel=58d5c635ba746247150000db

    Could you check and approve it, please?

  • ggmoy Avatar

    Java-Translation kumited!

    http://www.codewars.com/kumite/58d3c04d7a4ea9bb2f00008f?sel=58d3c04d7a4ea9bb2f00008f

    Could you check and approve it, please?

  • ggmoy Avatar

    Python-Translation kumited!

    http://www.codewars.com/kumite/58d2d9d51e4ac7002b000321?sel=58d2d9d51e4ac7002b000321

    Could you check and approve it, please?

  • Chestnut-Rice Avatar

    Had a lot of fun doing this Kata, even a guy at my job got interested in it :D Thanks!

  • tpunt Avatar

    A great challenge, Donald!

    FYI, the link to 3rd esolang interpreter challenge is broken on the description page.

  • glebec Avatar

    This comment has been hidden.

  • CodeVortex Avatar

    Despite being oddly named, this kata was refreshingly exciting to solve!

  • nickkwest Avatar

    Trivial having already done boolfuck since I was able to reusee my class for that, but still fun!

    I'd recommend ordering all your *fuck Katas into a series with links to the others on each Kata since they are so related, build on eachother, and increase in complexity.

  • Austin Haws Avatar

    This comment has been hidden.