title: How do I use brute force to solve and store solutions to multiple choice questions?
body: <p>I am having some trouble understanding this brute force approach. I am using Perl to extract questions and their choices. All of the questions right now are being stored inside of an array. I am not sure what to do with the answers.</p>
  <p>How should I store the answers and organize my code so it does something similar to this...</p>
  <ol>
  <li><p>Select the first option for the question. (So pass one, all the questions should have option A selected).</p>
  </li>
  <li><p>Submit to check for correct answers.</p>
  </li>
  <li><p>Parse answers, if the given answer was correct mark that as &quot;correct&quot; answer and forget trying to select any other choice for that question.</p>
  <p>Otherwise, continue through the list of answers for that question on the next pass.</p>
  </li>
  </ol>
  <p>So the next pass would pick the second answer for the that question, until after multiple submits it finds all of the &quot;correct&quot; answers via brute force.</p>
  <p>I am having trouble how to store the answers and associate them with the question, cross them off as they are wrong or tag it &quot;found&quot;.</p>
  <p>I was thinking about using a hash. Please let me know any suggestions on how I should structure the code.</p>
  <p>Thanks!</p>
  <p><strong>EDIT</strong></p>
  <p>Sample data --</p>
  <p>So I am using a HASH method... my hash looks something like this:</p>
  <p>print out of the hash :</p>
  <pre><code>question_123 =&gt; a,b,c,d
  question_155 =&gt; a,b,c
  question_234 =&gt; T,F
  </code></pre>
  <p>Now I have to find a way to go through each option until I find the correct answer for that question.</p>
  <p><strong>EDIT</strong></p>
  <p>To clarify somethings let us assume there is a pool of 10 questions. The user clicks &quot;Begin Practice&quot; which generates 4 random questions from the pool of 10. Thus, at this current state I have four questions with their answers. I go through and add these questions and their answers to a data structure (one from below... or using files to store them). Next I being to pick an answer. Then the user must submit these questions for review. Once the submit button is hit, the prompt says if question x is correct or incorrect. Based on this, the data structure must update which is the correct answer for that question.</p>
  <p>Now to rinse and repeat. This time another four set of random questions is generated from that same pool. This time, two new questions are found so these must be added to the data structure. Similar logic should be used to find the answers. Also, each answer option (selection) always has an unique numeric value attached to it so my server can check the answer ID with the value. On my server side each question just has an ID and it's associated right answer. Using my table would defeat the purpose of this experiment.</p>
  <p>Visual of what is happening:</p>
  <pre><code>Pass One -- 4/10 Random Questions
  
  1. Who is the US president?
  21. Barrak
  22. Chap
  23. Jim
  24. Nivea
  
  2. How many states are there?
  25. 99
  26. 90
  27. 51
  
  3. What is the color of the sky?
  28. blue
  29. black
  30. none
  
  4. Is time relative?
  31. False
  32. True
  </code></pre>
  <p>So, on the first pass the selections should be like the following:</p>
  <pre><code>1 =&gt; a - 21
  2 =&gt; a - 99
  3 =&gt; a - 28
  4 =&gt; False - 31
  </code></pre>
  <p>Hit the submit button. Server responds with :</p>
  <pre><code>1. Correct
  2. Incorrect
  3. Correct
  4. Incorrect
  </code></pre>
  <p>Now update the data structures with correct answer found.</p>
  <p>Program now requests new set of questions at the prompt. This time the server returns:</p>
  <pre><code>Pass Two -- 4/10 Random Questions
  
  4. Is time relative?
  31. False
  32. True
  
  6. What is not a plant?
  65. Cow
  66. Rose
  67. Tree
  
  1. Who is the US president?
  21. Barrack
  22. Chap
  23. Jim
  24. Nivea
  
  8. What is a programming language?
  99. C++
  100. Tylenol
  101. Mr.Monster
  </code></pre>
  <p>See, now on this pass two new questions arose. For these guys the first options have to be selected but for the repeated ones, the next up should be picked unless the correct answer has already been found.</p>
  <p>So this will be sent to the server:</p>
  <pre><code>4. True - 32
  6. Cow - 65
  1. Barrack - 21
  8. C++ - 99
  </code></pre>
  <p>The server responds with:</p>
  <pre><code>4. Correct
  6. Correct
  1. Correct
  8. Correct
  </code></pre>
  <p>Same deal with the response. Hope this really clears things up. Also note that each answer will always have an unique numerical value attached to it.</p>