title: Clojure: Iterating over a vector of vectors to find the first vector that meets a certain condition
body: <p>To learn Clojure I'm working on a little Tic Tac Toe game. After completing the first part of the game with relative ease, I've struggled trying to build an intelligent computer player.</p>
  
  <p>For the test I'm writing to help guide this, I want to check that the computer picks spot 9 if it's the computer's turn and this is the board:</p>
  
  <p>X | O | 3<br>
  4 | X | O<br>
  7 | 8 | 9</p>
  
  <p>To begin the game, the board is defined like this, as a map with key-value pairs representing the location on the board and the contents of that space:</p>
  
  <pre><code>(def board {1 "1" 2 "2" 3 "3" 4 "4" 5 "5" 6 "6" 7 "7" 8 "8" 9 "9"})
  </code></pre>
  
  <p>I had a few thoughts about how to solve this problem. One was to define the winning sets like this:</p>
  
  <pre><code>(def winning-sets
      [[(board 1) (board 2) (board 3)],
       [(board 4) (board 5) (board 6)],
       [(board 7) (board 8) (board 9)],
       [(board 1) (board 4) (board 7)],
       [(board 2) (board 5) (board 8)],
       [(board 3) (board 6) (board 9)],
       [(board 1) (board 5) (board 9)],
       [(board 3) (board 5) (board 7)]])
  </code></pre>
  
  <p>Iterate over each set:</p>
  
  <pre><code>(for [set winning-sets]
      (filter #(= symbol %) set))
  </code></pre>
  
  <p>But that doesn't seem right...I don't know where I would go from there. The problem I'm trying to solve can be described like this:</p>
  
  <p><strong>Tell the computer to look over the 8 winning sets and find one set that has TWO of your symbols <em>and</em> ONE open spot.</strong></p>
  
  <p>I'm fairly new to Clojure, so I'm just not sure I understand the best way to approach this problem. I've been looking at the <a href="http://clojuredocs.org" rel="nofollow noreferrer">ClojureDocs</a> (checking out iterating functions like <code>for</code> and <code>loop</code> and <code>case</code>), but haven't been able to make this work.</p>
  
  <p>What would be the best way to iterate over those winning sets, currently in vector form, and find the set that has two of a specific symbol and one opening?  Or would it be best to store the winning sets in a different data structure?</p>
  
  <p><em>NOTE: I've read the responses to <a href="https://stackoverflow.com/questions/8340477/how-do-i-iterate-over-a-vector-of-vectors-in-clojure?rq=1">this question</a>, but haven't been able to apply them to mine.</em></p>