7 kyu

Pair Zeros

1,248 of 2,360Nianpeng
Description
Loading description...
Algorithms
Arrays
Fundamentals
Functional Programming
  • Please sign in or sign up to leave a comment.
  • 66  Avatar

    Please review: C++ Translation

  • JohanWiltink Avatar

    LC translation

    this translation modifies the description

  • sophiechannon Avatar

    I am attempting this kata in Ruby and passed all the test cases. However, in the random tests, if the input array has 3 + 0s in it I am failing.

    When I check the expected compared to my solution, the expected seems to have always deleted the 3rd & 4th 0 of the input array, but surely it should only be deleting the 4th as that's the second 0 in the pair. Surely only every other occourance should be deleted? I can see people have passed the test on Ruby so am I just missing something here? Some examples below:

    Examples: [5, 4, 3, 7, 4, 3, 2, 9, 2, 9, 7, 1, 2, 8, 0, 0, 3, 2, 7, 4, 5, 4, 9, 0, 4, 0, 5, 2, 5, 5, 4, 0, 2, 3, 5, 4, 6, 2, 5, 4, 9] input [5, 4, 3, 7, 4, 3, 2, 9, 2, 9, 7, 1, 2, 8, 0, 3, 2, 7, 4, 5, 4, 9, 4, 5, 2, 5, 5, 4, 0, 2, 3, 5, 4, 6, 2, 5, 4, 9] expected [5, 4, 3, 7, 4, 3, 2, 9, 2, 9, 7, 1, 2, 8, 0, 3, 2, 7, 4, 5, 4, 9, 0, 4, 5, 2, 5, 5, 4, 0, 2, 3, 5, 4, 6, 2, 5, 4, 9] my result

    [6, 3, 9, 2, 9, 0, 7, 7, 5, 4, 9, 1, 7, 6, 4, 5, 0, 6, 0, 9, 6, 6, 3, 9, 0, 2, 4, 5, 7, 3, 8, 1, 2, 9, 4, 7, 4, 0, 0, 6, 5, 4, 4, 4, 4, 2, 7, 8, 6, 1] input [6, 3, 9, 2, 9, 0, 7, 7, 5, 4, 9, 1, 7, 6, 4, 5, 6, 9, 6, 6, 3, 9, 2, 4, 5, 7, 3, 8, 1, 2, 9, 4, 7, 4, 0, 6, 5, 4, 4, 4, 4, 2, 7, 8, 6, 1] expected [6, 3, 9, 2, 9, 0, 7, 7, 5, 4, 9, 1, 7, 6, 4, 5, 6, 0, 9, 6, 6, 3, 9, 2, 4, 5, 7, 3, 8, 1, 2, 9, 4, 7, 4, 0, 6, 5, 4, 4, 4, 4, 2, 7, 8, 6, 1] my result

    [1, 4, 7, 5, 6, 0, 8, 1, 0, 6, 6, 5, 2, 2, 6, 2, 7, 4, 7, 0, 2, 3, 8, 4, 0, 9, 8] input [1, 4, 7, 5, 6, 0, 8, 1, 6, 6, 5, 2, 2, 6, 2, 7, 4, 7, 2, 3, 8, 4, 9, 8] expected [1, 4, 7, 5, 6, 0, 8, 1, 6, 6, 5, 2, 2, 6, 2, 7, 4, 7, 0, 2, 3, 8, 4, 9, 8] my result

    Thanks

  • rowcased Avatar

    C Translation kumited (author inactive).

  • akar-0 Avatar

    COBOL translation (author inactive).

  • JohanWiltink Avatar
  • user9644768 Avatar

    Ruby 3.0 should be enabled.

  • skeletoo Avatar

    This comment has been hidden.

  • tmxk Avatar

    Wrong input in random tests: 2 more parameters (False and 1) are given.

  • jgdodson Avatar

    The submission tests for the python version seem to be in error. The pair_zeros function takes one argument but one of the tests passes it 3 arguments.

  • Grae-Drake Avatar

    The random JavaScript tests seem to be flawed. All of the normal tests pass and all of the random tests fail with messages like the following, which seem to be replacing 0's with NaN rather than removing them:

    Testing for [0, 0, 7, 8, 9, 7, 6, 2, 6, 2, 0, 0, 0, 9, 4, 9]

    It should work for random inputs too - Expected: '[0, NaN, 7, 8, 9, 7, 6, 2, 6, 2, NaN, 0, 9, 4, 9]', instead got: '[0, 7, 8, 9, 7, 6, 2, 6, 2, 0, 0, 9, 4, 9]'

  • Andrei-Zaneuski-epam Avatar

    I have error: Testing for [8, 0, 0, 0, 7, 0, 4, 1, 5, 7, 0, 0, 6, 6, 1, 0, 0] It should work for random inputs too - Expected: [8,0,7,4,1,5,7,0,6,6,1], instead got: [8,0,0,7,4,1,5,7,0,6,6,1,0] But as I understand it should pairing in this way:

    source: [8, 0, 0, 0, 7, 0, 4, 1, 5, 7, 0, 0, 6, 6, 1, 0, 0]
    paired:     ^--^  ^-----^              ^--^           ^--^
    result: [8, 0,    0, 7,    4, 1, 5, 7, 0,    6, 6, 1, 0   ]
    

    At least according to rule "0's generated by pairing can NOT be paired again" for 8 zeros in source we should have 4 zeros in result. What is wrong - test or my understanding?

  • vaspoz Avatar

    As I understand the rules, this test: Testing for [0, 0, 0, 3, 0, 4, 2, 0]

    should produce result: [0, 0, 3, 4, 2, 0] because arr[1] should collapsing with arr[0], arr[4] -> arr[2] and arr[7] stay at his place

    But expected result was: [0,3,4,2,0]

    How is that?

  • AntraxMiope Avatar

    Hi. Did I do something out of the ordinary? I passed the first tests, but something's wrong with the random ones :

    Random tests
    Testing for [9, 0, 5, 6, 3, 3, 6, 3, 4, 4, 4, 8, 5]
    
    Traceback:
       in 
       in 
    TypeError: pair_zeros() takes exactly 1 argument (3 given)
    
  • Dr.RiD Avatar

    This comment has been hidden.

  • dmitriy219 Avatar

    Testing for [9, 0, 8, 0, 0, 0, 6, 6, 0, 0, 3, 9, 0, 0, 2, 6] ^-----^ ^--^ ^--^ ^--^ As I can see, output should be [9, 0, 8, 0, 6, 6, 0, 3, 9, 0, 2, 6] So why do you expect [9,0,8,6,6,0,3,9,2,6] ?!

  • GiacomoSorbi Avatar

    Translated into both Ruby and Python, if you wish to approve them; also, let me know if you might want me to add random test cases to the JS version :)

  • bkaes Avatar

    expect(equalArray(a,b)) should get replaced by assertSimilar(a,b).

  • donaldsebleung Avatar

    Javascript version of Kata needs random test cases to prevent low-level cheats that exploit fixed tests/answers from passing.

  • PG1 Avatar

    This comment has been hidden.

  • Freywar Avatar

    What does "signal-digit" mean? I guess it should be "single".

  • wthit56 Avatar

    As @Zozo mentioned, the function name has a typo, and should really be corrected. To save older solutions from being rejected, you could add: pairZeros = pairZeors; at the top of your testing code.

    Also, the description could use some work. A full demonstration of how things are checked and what should happen to the zeros would make it much easier to grasp. Took me a few re-reads and a half-written comment with questions before I finally figured it out. ;P

    Here's an example you can use if you wish:

    pairZeros([0, 1, 0, 2])
    // paired: ^-----^ cull second zero
           == [0, 1, 2];
    //   kept: ^
    
    pairZeros([0, 1, 0, 0])
    // paired: ^-----^
           == [0, 1,    0];
    //   kept: ^
    
    pairZeros([1, 0, 7, 0, 1])
    // paired:    ^---^
           == [1, 0, 7,    1];
    //   kept:    ^
    
    pairZeros([0, 1, 7, 0, 2, 2, 0, 0, 1, 0])
    // paired: ^--------^ 
    //        [0, 1, 7,    2, 2, 0, 0, 1, 0]
    //   kept: ^         paired: ^--^
           == [0, 1, 7,    2, 2, 0,    1, 0];
    //   kept:                   ^
    
  • ZozoFouchtra Avatar

    A typo in function name : pairZeors. Should be modify soon !