Beta

Clue - Esoteric programming #4

Description
Loading description...
Fundamentals
  • Please sign in or sign up to leave a comment.
  • user6793616 Avatar

    I don't understand the rules. Moving on.

    • matt c Avatar

      Would you like some clarification on anything? I could then update the description to make this kata more friendly which would be great :)

    • user6793616 Avatar

      I read several times the rule about 0 and 1 and went through the example, but could make sense of it. It is not clear why the x suddenly is at the right and then again at the left. But even why the sequence of 0 1 changes like it does in the example is not clear for me from reading the rules. I cannot really say what needs to be improved as I have no idea what this is supposed to do.

    • matt c Avatar

      If you read the reference is there anything I could move from there to here?

    • user6793616 Avatar

      That is essentially the same text. Already at the first transition I don't understand why the x is not put after the zero as demanded by the end of the second rule.

    • matt c Avatar

      do you want to write out an example so I can follow clearly?

    • user6793616 Avatar

      OK, I finally managed to understand the rules. This is the information that I found missing:

      • The pointer moves to the next character when processing a 0 (this may be obvious, but it is nowhere stated as far as I can see)
      • When processing a 0, the pointer first moves, and then the last character is deleted (It can be conceived in the opposite order, but then the pointer must not really move at all if the 0 was the rightmost character -- the pointer should then only be made valid through wrapping). If the deleted character is the one being pointed at, the pointer will thus point to the next (i.e. the leftmost) character.
      • When processing a 1, the result of the NAND is first prepended, and only then the pointer moves to the digit following the pair (this is explained in the text, but I mention it here to highlight the apparent difference of processing sequence with the 0-processing). So it might be that the pointer is moved to the newly inserted NAND result.
      • The comments that follow each line in the example announce what will happen to get at the next line's string -- they do not explain the current line. This also confused me. I think it is better to put the program strings on separate lines and have the comments as separate paragraphs between them.
      • When it says the cycle method "must return the current iteration of the source code", it does not mean it should return the source code, but the number of times the run method was executed on the initial program. This was not clear to me as the term iteration is never explained in context, and when it says "iteration of the source code" it really sounds like a version of the source code.

      The notation with the x is not very clear. Looking back, it confused me. I would suggest using a ^ on a line just below the string.

      I would suggest this text for the example section:

      For example, the program 110 would work the following way (^ marks where the program pointer currently is):

      110
      ^
      
      
      > The pair `10`, at the right of the digit with the pointer, is NANDed and the resulting 1 is inserted at the left of the string without removing the pair itself. The pointer should move to the digit following that pair. As there is no such digit at the right side of that pair, we must cycle back to the beginning of the string and set the pointer to the first digit:
      
      > ```
      1110
      ^
      

      The pointer is still on a 1, so we NAND the pair 11 at the right of it and prepend the resulting 0. The pointer moves to after that 11, which is the last digit in the string:

      01110
          ^
      
      
      > As the pointer is now on a 0, we must remove the rightmost character, thus the 0 removes itself. At the same time, the pointer must move to the next digit which, by the cyclic nature of the string, is the leftmost digit:
      
      > ```
      0111 
      ^
      

      Again, the pointer is on a 0, so we remove the rightmost character from the string and at the same time move the pointer one position to the right:

      011
       ^
      
      
      > The pointer is now on a 1, so we NAND the next pair, which consists of the rightmost 1 and leftmost 0 (cycle!). 1 NAND 0 is 1, which is prepended to the string... etc.
      
      Finally, the intro has a spelling mistake. It should not be *"turning complete"*, but *"Turing complete"*.
      
      I was already planning to make the update, but then I read in the comments below that you prefer doing it yourself.
      
  • hufftheweevil Avatar

    I just cleaned up the markup in the description a bit. I also added a line that explained that the last part was an example.

    • matt c Avatar

      if there were issues could have notified me here and I could have fixed them too..

    • hufftheweevil Avatar

      You're right, sorry about that. At first I just fixed the headers, so it was just markup. But I should have let you add the example notes. Will do next time! :D

  • Voile Avatar

    This kata is pretty bad:

    1. "iteration" actually means "step",
    2. The first iteration does nothing,
    3. Test cases with over 1000 steps terminates at the 1001st step but nonetheless checks if cycle is 1000.

    At its current state it's pretty much broken.

  • Dentzil Avatar

    Hi matt c,

    I would suggest you to improve the description a bit, because it is now confusing to solve the kata completely:

    1. It is not explained, why at the first iteration the source code must be returned unchanged;
    2. There is no word, that the iteration number for some tests is limited.
    And I agree with the JohanWiltink's comment.

    Kind regards,
    D.

  • JohanWiltink Avatar

    I'm sorry, the programming language is (mostly) clear (would be better if iterations were clearly marked though, and did not flow over into each other), but the interface for the solution is obfuscated beyond normal comprehension.

    I have no idea what property goes where or what the argument to run() means.

    • matt c Avatar

      there is no argument passed into run()?? do you have any suggestions for the other fixes though?

    • JohanWiltink Avatar

      These are the example tests.

      Test.describe('Fixed Tests', _ => {
        Test.it('Tests',_=>{
          var clue = Interpreter('000000010000'), i=0;
          while(i++,true) {
            var re = clue.run(false);
            if(!re) break;
            if(i === 3) 
              sloth.assert(re,'0000000100');
            if(i === 5) 
              sloth.assert(re,'00000001');
            if(i === 11) 
              sloth.assert(re,'00');
          }
          sloth.assert(clue.cycle, 12);
        });
      });
      

      false looks like an argument to me?

    • JohanWiltink Avatar

      Clue seems to work iteratively. You have a program, you do an iteration, you have a new program. The implementation could have been a function to do just that, but there's a class with more functionality.

      I'm just unclear on what more needs to be done than iterating programs, and what the expected functionality of the provided methods is.

      I'm a bit frustrated. And I probably sound like it. Sorry.

    • matt c Avatar

      that was left from debugging, it means nothing.

      and yes as I read it the program does not end until no more iterations can be completed so that's why you have to create a class which returns iterations of an input program.

    • JohanWiltink Avatar

      Merde.

      A cycle is not a complete iteration. It's just one step.

      That would have been good to include in the Description, instead of having to dig for it on the external page.

    • JohanWiltink Avatar

      Also, I am apparently doing something wrong. But I can't for the life of me figure out what. The example test don't help because they really only test zero cycles, and the submit tests don't help because they skip too many steps. The wiki page doesn't help because I'm bloody doing what's in the example there.

      I'm stuck.

    • Dentzil Avatar

      Hi JohanWiltink,

      which tests can you not pass?

    • JohanWiltink Avatar

      Ehm, all of 'em, except 000000010000 which really only processes 0s.

      Here's some logging; first number is cycle, second number is pointer, then the (input - before the cycle) string with the to be processed element between *s:

      Test for: [0110100101101], length: 69
      
       0  0 *0*110100101101
       1  0 *0*110100101101
       2  1 0*1*1010010110
       3  5 10110*1*0010110
       4  9 110110100*1*0110
       5 13 1110110100101*1*0
      ✔ Test Passed: Value == '1111011010010110'
      
       6  0 *1*111011010010110
       7  4 0111*1*011010010110
       8  8 10111101*1*010010110
       9 12 110111101101*0*010110
      10 13 1101111011010*0*1011
      ✘ Expected: '111111111011010010110', instead got: '11011110110100101'
      

      And then it only gets worse from there of course.

    • Dentzil Avatar

      Hi JohanWiltink,

      ok, we see your algorithm works at least first 5 cycles correctly.
      This is the good point to start to debug from 5th cycle.

      According to "the language specification": 1 takes the next two characters ... The program pointer then moves to just beyond the second input that was read for NAND.. Therefore the pointer in the 6th cycle (after move in the 5th cycle) must be at the index 2 (after adding new code item): 6 2 11*1*1011010010110

      Therefore your problem is in the shift of the pointer through the end of the source code.

      And you should take into account that the shift occurs before the new code item is added.

      I hope, it will help you.

    • JohanWiltink Avatar

      When NAND, looking for its operands, runs off the end of the program, it starts again at the beginning ?!? I just took zeroes. Is this documented somewhere?

    • Dentzil Avatar

      Exactly: There is a program pointer that initially starts in the beginning of the string, moving forward after every instruction, returning to the beginning when reaching the end of the string. Take a look here and here.

    • JohanWiltink Avatar

      That doesn't say where NAND gets its operands. But it is on that second linked page.

      Having to dig for it not even on a page linked from the Description, but on a page linked from that page, sorry, hadn't thought that would be necessary (or useful).

      Thanks.

    • Dentzil Avatar

      You are welcome. ;)

    • matt c Avatar

      Thanks Dentzil.

      Issue marked resolved by matt c 9 years ago
  • Hacker Sakana Avatar

    Is this kata still in draft? Cannot submit my solution.

    • matt c Avatar

      it's not in draft.

      post your solution below and mark as a spoiler, I'll see if it's something wrong with your code.

    • Hacker Sakana Avatar

      Submission timed out while communicating with our servers. This may infrequently happen if our servers are extremly busy. Please try again. If issues persist you can check status.codewars.com to see if server issues are being investigated.

      Still getting this message when I try to submit... No idea what's going wrong... :(

      ...while everything is okay in other katas

    • matt c Avatar

      post your solution below and mark as a spoiler, I'll see if it's something wrong with your code.

    • Hacker Sakana Avatar

      This comment has been hidden.

    • matt c Avatar

      Your code does execute properly when I run it (it does fail tests however), try running it in firefox maybe? Also the interpreter isn't iterating 3 times, it iterates 2 times, the run returns the state of the string before it's processed so for example:

      input: 000000010000
      output(1): 000000010000
      output(2): 00000001000
      output(3): 0000000100
      

      The input has only been run against twice.

    • Hacker Sakana Avatar

      run is a function which must return a string of the current source code after it has been processed using the rules below.

      Then better modify your description. Moreover, at last I passed the final tests, with a dirty -- which I suppose dirty -- solution. There is a bug in your testing fixture.

      And, I found out what caused the message I described above. It sounds strange but it was true that the testing code has run into an infinite loop. It should have prompted something like "it takes longer than 8000ms ...", assumed to be a bug of CW.

    • matt c Avatar

      Sorry, the description still holds true, just the first time run is called you must return the source unprocessed because this if the first time you are using the run there are examples in the default test cases which you could have inferred that from.

    • matt c Avatar

      Do you know exactly where the testing code was running into an infinite loop because when I ran mine I always ran.

    • Hacker Sakana Avatar

      I'm not sure. I will try to debug it when I come back. It need some time I think.

    • matt c Avatar

      I can run my solution many times without timing out, I don't know what your problem is.

    • matt c Avatar

      there was a bug in my code where the loop would stop if the user returned a falsy value. That has been fixed and your solution is invalid.

    • Hacker Sakana Avatar

      Okay, problem solved. I did it by preprocessing the code to make it look natural (in order to pass your tests :) ).