<p>As I can see, this a variation of mastermind board game <a href="http://en.m.wikipedia.org/wiki/Mastermind_(board_game)" rel="nofollow">http://en.m.wikipedia.org/wiki/Mastermind_(board_game)</a></p>

<p>Also, you can find more details about the problem in this paper</p>

<p><a href="http://arxiv.org/abs/cs.CC/0512049" rel="nofollow">http://arxiv.org/abs/cs.CC/0512049</a></p>
Choosing permutations with constraints
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="https://stackoverflow.com/questions/1185634/how-to-solve-the-mastermind-guessing-game">How to solve the “Mastermind” guessing game?</a>  </p>
</blockquote>



<p>I have to choose <code>k</code> items out of <code>n</code> choices, and my selection needs to be in the correct order (i.e. permutation, not combination). After I make a choice, I receive a hint that tells me how many of my selections were correct, and how many were in the correct order.</p>

<p>For example, if I'm trying to choose <code>k=4</code> out of <code>n=6</code> items, and the correct ordered set is <code>5, 3, 1, 2</code>, then an exchange may go as follows:</p>

<pre><code>0,1,2,3
(3, 0) # 3 correct, 0 in the correct position

0,1,2,5
(3, 0)

0,1,5,3
(3, 0)

0,5,2,3
(3,0)

5,1,2,3
(4,1)

5,3,1,2
(4,4)

-&gt; correct order, the game is over
</code></pre>

<p>The problem is I'm only given a limited number of tries to get the order right, so if <code>n=6, k=4</code>, then I only get <code>t=6</code> tries, if <code>n=10,k=5</code> then <code>t=5</code>, and if <code>n=35,k=6</code> then <code>t=18</code>.</p>

<p><strong>Where do I start to write an algorithm that solves this?</strong> It almost seems like a constraint solving problem. The hard part seems to be that I only know something for sure if I only change 1 thing at once, but the upper bound on that is way more than the number of tries I get.</p>