Build a perfect AI for the game 15
GolfScript (129 86 81 85 75 chars)

{:C[{.`{1$-\{+15\-}+%}:T+/}/10,1&gt;C~+-:^{.{^T&amp;}+C/,2&lt;*T}/5^{1&amp;}$][]*^&amp;0=}:N;


Expected input format: [[int int ...][int int ...]] where the first list is my numbers and the second list is my opponent's numbers. For interactive testing, add ~N to the end of the script and supply a string in that format: e.g.

$ golfscript.rb 15.gs &lt;&lt;&lt;"[[5][2 8]]"
9
$ golfscript.rb 15.gs &lt;&lt;&lt;"[[2][5 8]]"
6




Heuristics:


If I can win this turn, do it
If opponent would win next turn, block
If I can force opponent to a square which prevents them from creating a fork, do it
5 is the only number which can contribute to winning in 4 ways, so grab it if available.
Favour evens over odds




Test framework:

{:Set;[1 5 9 1 6 8 2 4 9 2 5 8 2 6 7 3 4 8 3 5 7 4 5 6]3/{.Set&amp;=},!!}:isWin;
{
    # Mine His
    .isWin{
        "Lost "@`@`++puts
    }{
        # If there are available moves, it's my move.
        # If I won before my move, I've still won after it.
        1$1$+,9&lt;!!{
            # my move
            1$1$[\\]N 2$\+
            # Mine His Mine'
            .isWin!{
                # his move
                10,1&gt;2$2$+-{
                    2$\+1$\
                    # Mine His Mine' Mine' His'
                    fullTest
                    # Mine His Mine'
                }/
            }*;
        }*;;
    }if
}:fullTest;
# I move first
'[][]fullTest'puts [][]fullTest
# He moves first
'[][1]fullTest'puts [][1]fullTest
'[][2]fullTest'puts [][2]fullTest
'[][5]fullTest'puts [][5]fullTest