6 kyu

Check by Queen

319 of 626dukies_2000
Description
Loading description...
Fundamentals
  • Please sign in or sign up to leave a comment.
  • brodiemark Avatar

    Hi dukies_2000,

    Are you interested in having this problem translated into other languages?

    Regards,

    brodiemark

  • saudiGuy Avatar

    python new test framework is required. updated in this fork

  • Blind4Basics Avatar

    Python:

    In description: while ONE of these 25 elements will be represented by a "q" (queen) and a "k" (king). Both will be represented in lower case

    In tests, seems pretty invalid to me!!

     Log
    --------
    *q**k
    *q**k
    *q**k
    *q**k
    *q**k
    Test Passed
    Log
    --------
    k*q**
    k*q**
    k*q**
    k*q**
    k*q**
    Test Passed
    Log
    --------
    *q*k*
    *q*k*
    *q*k*
    *q*k*
    *q*k*
    Test Passed
    Log
    --------
    *k**q
    *k**q
    *k**q
    *k**q
    *k**q
    Test Passed
    Log
    --------
    qk***
    qk***
    qk***
    qk***
    qk***
    Test Passed
    Log
    --------
    k***q
    k***q
    k***q
    k***q
    k***q
    Test Passed
    Log
    --------
    q**k*
    q**k*
    q**k*
    q**k*
    q**k*
    Test Passed
    Log
    --------
    k***q
    k***q
    k***q
    k***q
    k***q
    Test Passed
    Log
    --------
    **qk*
    **qk*
    **qk*
    **qk*
    **qk*
    Test Passed
    Log
    --------
    ***kq
    ***kq
    ***kq
    ***kq
    ***kq
    Test Passed
    Log
    --------
    kq***
    kq***
    kq***
    kq***
    kq***
    Test Passed
    Log
    --------
    **qk*
    **qk*
    **qk*
    **qk*
    **qk*
    Test Passed
    Log
    --------
    *q*k*
    *q*k*
    *q*k*
    *q*k*
    *q*k*
    Test Passed
    Log
    --------
    **qk*
    **qk*
    **qk*
    **qk*
    **qk*
    Test Passed
    Log
    --------
    *q**k
    *q**k
    *q**k
    *q**k
    *q**k
    Test Passed
    Log
    --------
    k*q**
    k*q**
    k*q**
    k*q**
    k*q**
    Test Passed
    Log
    --------
    q*k**
    q*k**
    q*k**
    q*k**
    q*k**
    Test Passed
    Log
    --------
    ***k*
    ***k*
    ***k*
    ***k*
    ***k*
    
    • dukies_2000 Avatar

      Woah! I have no idea what happened here! I had just merged a Python translation. Although, I've never formally studied Python, is it possible that the code below is causing the problem when generating the random board?

      board[rand(0,4)][rand(0,4)] = 'q'
      board[rand(0,4)][rand(0,4)] = 'k'
      

      It looks fine to me, but it's the only thing I can think of that would produce such a result.

    • Blind4Basics Avatar

      2 problems here:

      1. this way, you could obtain queen and king at the same place. Bad.
      2. the board is surely generated this way: board = [['*']*5]*5. VERY BAD: this way, the same list instance of length 5 is put 5 times in the board. That's why all the rows of the same column contain 5 kings or 5 queens. And sometimes, due to the first point, you end up with only kings in the board.

      Lots of things still to learn, for the translator, here... ;)

    • kodejuice Avatar

      Sorry about that, i translated this kata the same week i learnt Python, About the problems

      1. i just thought i would get at least one distinct number when i call rand(0, 4) four times
      2. i guess i forgot to clone the list before placing it on the board
    • kodejuice Avatar

      I have clarified this issue but i cant seem to Publish my changes, getting a Error: python version python not supported error, So i forked it, Please approve the fork Python translation fork @dukies_2000

    • siebenschlaefer Avatar

      Fixed (without the new fork).

      Issue marked resolved by siebenschlaefer 7 years ago
    • dukies_2000 Avatar

      @kodejuice Thank you for clarifying the issue with the fork. @siebenschlaefer Many thanks for fixing the issue!

  • kodejuice Avatar

    Nice kata, you could have made it N x N though... Anyway heres a Python translation

  • JohanWiltink Avatar

    Input modification vulnerability in random tests fixed.

    This solution is now invalid.

    • dukies_2000 Avatar

      Wow, thanks for that! I had no idea that my random test could be vulnerable. Do you have any advice or know of any resources I could use to try and prevent this in the future?

      Meanwhile, thanks for fixing the 'board9' issue for me, and for all the advice you gave me on my previous kata. I have now unpublished that previous 'incarnation' as advised ; )

    • Voile Avatar

      Objects and arrays are mutable. If you pass them inside a function, the function can mutate them all it wants. And then if you reuse the same object for different purposes, unexpected things can happen.

      So the safe way is to always pass a deep clone of the object.

    • dukies_2000 Avatar

      Thank you so much :)

  • Voile Avatar

    Example tests are missing board9.