5 kyu

Rule 30

406 of 899MircoT
Description
Loading description...
Lists
Arrays
Binary
Puzzles
  • Please sign in or sign up to leave a comment.
  • saudiGuy Avatar
  • nomennescio Avatar

    The description declares n to be the number of iterations, then goes on describing how the nth cell should be processed. It seems this is however not intended, but all indices must be considered.

    Furthermore, although it's alluded to, there's no explicit rule stating that the array needs to have a 0 added to the front and the back.

    Please adapt description.

  • geoffp Avatar

    Nice kata, but the handling of all-zero sequences seems overly strict. Since sequences are bounded by implicit 0s, any sequence consisting only of 0s is equivalent to any other (and all of them are equivalent to the empty sequence). One of the sample tests insists on the returned answer being {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, even though any other all-zero sequence would be just as correct. Maybe leading and trailing 0s should be disregarded when checking solutions?

  • akar-0 Avatar

    Fork removing one fixed test where n had a negative value in JS: https://www.codewars.com/kumite/6263ee4c9eeaac004ba2541e?sel=6263ee4c9eeaac004ba2541e

  • behan Avatar

    "a non-negative integer n" n can be a negative number!

  • Kees de Vreugd Avatar

    Nice, a starting zero doesn't have a left neighbour. Now what?

  • akar-0 Avatar

    COBOL translation updated according to current description.

  • JohanWiltink Avatar

    LC translation

    This translation removes input validation from the description.

  • trashy_incel Avatar

    C translation

    • no input validation
    • number of iterations is >= 0
  • JohanWiltink Avatar

    You have to write a function that takes as input an array of 0 and 1 and a positive integer

    • values different from 0 and 1 must be considered as 0
    • a negative number of iteration never changes the initial sequence
    • you have to return an array of 0 and 1

    These rules are inconsistent. Worst part is that you have to return the original input unlaundered for negative iterations but you do have to launder for 0 iterations. And all of that contradicts "positive integer."

    Please just skip the input validation already.

  • akar-0 Avatar
  • akar-0 Avatar

    Values other than 0 and 1 are not tested in Python, JS and Ruby. Currently only Haskell actually tests it.

  • akar-0 Avatar

    Tests in Haskell are unusable:

    Falsifiable (after 3 tests and 2 shrinks):
      [2]
      Positive {getPositive = 1} expected [0,0,0] but got [1,1,1]
    

    We should be given the input, or we cannot do anything with it.

  • user9644768 Avatar

    Ruby 3.0 should be enabled.

  • user9644768 Avatar

    Ruby 3.0 should be enabled.

  • Rambutan Avatar

    This took at least twice as long to figure out the correct way to handle leading and trailing zeros as it did to figure out the main logic of the challenge!

  • null_ptr Avatar

    Would it be possible to remove leading and trailing zeroes from the test cases? My solution is producing correct answers, but the random tests keep failing due random leading and trailing zeroes. (seemingly random. spent the last hour or two trying to figure out workaround for the tests without luck.)

  • StarenseN Avatar

    Hello! Great kata.

    Just a remark: in random test, inputs that have leading or ending 0 (like [0, 1, 0 xxx 0, 0], I think this kind of input makes no sense and break the Rule 30. Tell me if I'm wrong but row of cells should always have leading 1 or ending 1 (by only counting existing cells which make sense).

    I say that because I was upset to have coded something that fit the rules but failed at something unexpected (I don't think it's mentionned in the instructions). And manage to fix it.

    Cheers !

  • hksong Avatar

    This comment has been hidden.

  • user8052336 Avatar

    Hello!

    During submission, my method (ruby kata) seems to pass the tests but fail anyway? the error I get is:

    *': negative argument (ArgumentError) from rule30' from block in ' from block in describe' from measure' from describe' from ` ' 10 Passed 0 Failed

    Could anyone confirm whether ths is my mistake or a problem with the testing?

    thanks in advance

  • pivek303 Avatar

    Hi all, I believe I found a some sort of a pattern in these random tests.

    For example:

    Random tests Testing for [1, 1] and 2 It should work for random inputs too: [1, 1, 0, 0, 1, 1] should equal [1, 1, 0, 0, 1, 0, 0, 0, 1, 1]

    The correct result is my result because it has correct number (6) of elements (each iteration causes creation of 2 new elements; there are 2 elements initially and then 2 iterations). Of course, one can check the correctness even by hand on a piece of paper. The test answer is the list of 10 elements. Funny thing is, that the result suggested by the test is exactly the result of:

    rule30([1, 1, 0, 0, 1, 1], 2)

    So the testing routine seems to take the correct result as the first argument of tested function. I ran my function several times and it always was stopped by the very first random test.

  • saferthanhouses Avatar

    Hey all, In JS: I'm passing almost all of the tests except for several in which I get a random 'null' value that appears within my result, otherwise the result is correct. Through my own testing I cannot reproduce these null values. I'm wondering if there are any edge-cases I might be missing that are interfering with my code, but I have read through the spec and cannot see any. Has anyone experienced similar?

  • hugomfcruz Avatar

    This comment has been hidden.

  • Klemsus Avatar

    Standart tests passed, but random tests for JS are failed because it expected addition zeros at the begin and the end. From start array [0,0] with 36 iteration my script returns 74 zeros (36 in both direcitons plus initial two), but expecting array is 76 zeros. Is it correct?

  • volker48 Avatar

    I don't see how with 1 iteration the rule goes from [1] to [1, 1, 1]. I understand that since 1 is next to both borders of the list that we add in 0 to both sides of the 1 which gives us [0, 1, 0], but how do we then get [1, 1, 1] from that? Do we change all cells under consideration to the value in the new cell row? That is, since was have [0, 1, 0] and the rule says 1, both left neighbor, current cell, and right neighbor all become one? The way its worded it sounds like only the current cell changes, which in the case of [0, 1, 0] its already a one so we should just stay [0, 1, 0] not become [1, 1, 1].

  • Insti Avatar

    The tests for "invalid" input add nothing to the kata and just pollute the solution. They should be removed, and we should always receive valid input.

  • Insti Avatar

    I have a solution which passes all the standard tests, but fails all the ruby random tests. The random tests seem to be padding the results with [0,0] which does not happen in the standard tests.

  • 5thWall Avatar

    Description needs to be more clear how the initial state grows in size.

  • jolaf Avatar

    This two sentences look unclear and contradictionary, could you please clarify them? the list must be considered circular the border of the list are always 0

    Probably it would be enough to formulate when and how the array should grow.

  • ZozoFouchtra Avatar

    This comment has been hidden.

  • ChristianECooper Avatar

    This comment has been hidden.

  • GiacomoSorbi Avatar

    Dai Mirco: prometto che se fixi i test cases ti traduco il kata in JS e Ruby, faccio revisione generale e te l'approvo appena possibile :D

    Per farlo in Haskell invece non saprei se riesco, ma ci posso pensare, visto che si presta assai a una bella trasposizione funzionale, mh...

    [Trying the fellow-countrymenship card here, but I will do it for real :D]

  • GiacomoSorbi Avatar

    Mh, could you check about the 9th test case? I don't get how comes I pass previous and much longer trials, but fail on this one.

    Plus, apparently checking step-by-step doesn't help me in finding the error, mh... Well, I'll give it a further shot after lunch anyway. And thanks for this interesting kata :)