6 kyu

Simple palindrome game

54 of 144KenKamau
Description
Loading description...
Strings
Algorithms
  • Please sign in or sign up to leave a comment.
  • ejini战神 Avatar

    There should be fixed and sample tests like this one where the first string has 3 or more occurences of the same character that is not in the second string within all languages

    str1 = qdgbsfebddqcmj 
    str2 = nmvsqjzbiwecuw
    

    Probability of random tests to generate such cases should also be increased

  • iv2101 Avatar

    The statement is unclear. Please clarify that P1 and P2 are creating one string (I first read it as P1 a string separate from P2), that they are adding characters to the end of the string (is this correct?), and that you assume optimal strategy with full information (they see each other's hands). Interesting problem otherwise!

    • KenKamau Avatar

      I've updated the description. Confirm it's OK.

    • iv2101 Avatar

      I would spell the details out, maybe like this:

      In this Kata, two players, Alice and Bob, are playing a palindrome game. Alice starts with string1, Bob starts with string2, and the board starts out as an empty string. Alice and Bob take turns; during a turn, a player selects a letter from his or her string, removes it from the string, and appends it to the board; if the board becomes a palindrome (of length >= 2), the player wins. Alice makes the first move. Since Bob has the disadvantage of playing second, then he wins automatically if letters run out and the board is never a palindrome. Note also that each player can see the other player's letters.

      The problem will be presented as solve(string1,string2). Return 1 if Alice wins and 2 it Bob wins.

    • KenKamau Avatar

      Description updated.

      Issue marked resolved by KenKamau 7 years ago
    • iv2101 Avatar

      Many thanks, much clearer now! Let me go solve it;)

    • KenKamau Avatar

      Ok. Good luck!

  • Thoms Avatar

    I got this in the random tests:

    Falsifiable (after 41 tests): expected: 2 but got: 1 "xehtzzbajpcze" "cjjsshesortelnxefoqgdogybqurdiqtyo"

    The character 'z' does not belong to the second string, and the first string has more then one. So, couldn't P1 win by picking 'z', and then again another 'z' after whathever P2 does?

  • gkatsanos Avatar

    damn, I wanna start this one but it looks complex.

    • KenKamau Avatar

      No its not! It's a 6kyu for a reason.

      Ask youself, what does it take for P1 to form a palindrome? And then understand that in all other scenarios, P2 must win. It's a piece of cake!

  • Blind4Basics Avatar

    Nice one. One missing fixed test, though (I stumbbled on it in the random ones):

    s1, s2 = 'qtkxttl', 'utvohqk'
    return 2
    
  • ZED.CWT Avatar
    gzyqsczkctutjves hpaqrfwkdntfwnvg
    Expected: 1, instead got: 2
    

    cannot i just take a g from string1 and another g from string2?

    • KenKamau Avatar

      Let me look at it.

    • KenKamau Avatar

      Hi Zed, should be good now.

    • ZED.CWT Avatar
      rmevmtw uavtyft
      Expected: 1, instead got: 2
      // take a 'v' and another 'v'
      

      Is there some order requirments i am missing?

    • KenKamau Avatar

      The description was not very clear. I have completely changed it. Let me know if it now makes sense.

    • ZED.CWT Avatar

      Now i finally get your idea

    • HerrWert Avatar

      I'd say the description could still be improved. I understood it as if each player were removing a character at a time from his/her own string to form a palindrome with the remaining letters.

      However, now I see that each player is selecting letters to help build one common string until it becomes a palindrome (if possible). So I think some kind of indication that players are contributing letters to a common string would be helpful.

    • KenKamau Avatar

      Thanks. I will update

  • Unnamed Avatar

    And tenchnically a string of length 1 is a palindrome...

  • JohanWiltink Avatar

    The example gives the impression that characters should be taken in order, but your below comment says not.

    Neither the Description nor the tests specify when to return 1 and when 2 when both are possible.

    Missing the puzzle tag .. :/

  • myjinxin2015 Avatar

    why s1="eyfjy", s2="ooigvo" should return 1?

    BTW: no sample tests ;-)