7 kyu

Simple Fun #367: Flip Cards

Description
Loading description...
Puzzles
Games
  • Please sign in or sign up to leave a comment.
  • zdreagin Avatar

    Seven cards are placed on a table. Each card has an O on one side and an X on the opposite side. Three of the cards have the X side facing up, and the other four have the O side facing up, however you can't see which cards are which. Your task is to divide the cards into 2 piles that each contain an equal number of cards with an X facing up. Although you cannot see the cards, you are allowed to flip each card or leave it as it is. The cards are labelled "C1" through "C7". Return an array containing two subarrays which, between the two of them, contain all seven cards, either as they are (i.e. "C3") or flipped (i.e. "C3.flip").

    This is a puzzle more than a programming challenge. If you are confused, I would advise experimenting by dividing the cards into two piles of varying sizes, and working through the possibilities for what the end results will be by flipping different amounts of cards, keeping in mind that you don't know which side is originally facing up on each card.

  • Wisdou Avatar

    Very fascinating Kata, thanks myjinxin2015!

  • Chasab Avatar

    Am i supposed to code something for this? I don't see any way to manipulate or view any of the data, all i seem to be able to change are the Cx/Cx.flip returns, however without the ability to see what each represents there is no way to code a proper solution to "attempt" this kata. probably just going to skip it and see if this involves some for of "breaking" the tests.

    • myjinxin2015 Avatar

      It's hard to give an explanation or hint ;-) You can take these seven cards as a 7 bit binary number, 3 bits are 1, 4 bits are 0. such as 1110000, 0000111, etc. Your goal is to flip some bits, so that the result has same numbers of 1 in two groups. Tips: you should flip an odd number of cards. If you flip even number of cards in any case, the numbers of 1 still be a odd number. And obviously, flip 1 or 7 cards are not good choices.

  • alexosunas Avatar

    I tried but I don't understand what is needed in this kata, I really don't want to skip it but I think requirements need more clarification.

  • Voile Avatar

    Approved