title: generating a list in arrays and use of functions
body: <p>I am wondering how to make an array with values that start at 1111 and go all the way up to 8888. I am asking this because I need to generate a list of 4 digit numbers with each digit ranging from 1-8. I would like to have this in a loop form. Also, I am lost on my functions trim, <strong>methodicalEliminate</strong>, <strong>guessAndEliminate</strong>, and <strong>guessThreeThenEliminate</strong> in my following program. Here are the directions:</p>
  
  <p>This assignment focuses on the use of arrays in a program, including using one as a parameter to a function. </p>
  
  <p>PROBLEM DESCRIPTION
  In the game of Mastermind, a player is only given a finite number of guesses to try to identify the hidden combination (such as twelve guesses). Often that is the only constraint in playing the game. 
  But some players might make a competition with each other to see who can guess the other's combination in fewer tries. In this case, the problem is not only to come up with a strategy that can find the answer within a specified limit, but to find one that is likely to require the minimal number of guesses. </p>
  
  <p>Here is where the computer comes in -- one can write a program that would try out different guessing strategies, and see how they work out. Since a computer can do the analysis and computations more rapidly than a person, it could just pretend to play Mastermind on our behalf using any strategy we choose, and tell us how long it took to do that. </p>
  
  <p>OVERALL SOLUTION</p>
  
  <p>Of course, it would be extremely difficult to teach the computer to reason along the same lines as a person. For example, if we guessed a combination 1111 and got one black peg, we would make a mental note that the answer has exactly one 1 in it, and then proceed to make other guesses with that one fact in mind. If we next guesses 1222 and got one white peg, we would know there were no 2's, and that the single 1 is not in the first position. But how to keep track of such information after a series of guesses would be rather hard. </p>
  
  <p>Fortunately, for a computer simulation with an array, we can record all of our known facts in a different way. We just maintain a list of all possible answers that there could be, and then remove numbers from the list that could no longer be the solution. If our first guess tells us there is exactly one 1 digit, we would remove all the numbers that do not have that feature. When we find out there are no 2's, we eliminate all the values that contain 2's. Eventually, the only number left would be the correct answer. </p>
  
  <p>SOME SIMPLE STRATEGIES</p>
  
  <ol>
  <li><p>This is a strategy that many players use, resembling what was described above. Just methodically got through the possibilities in a straightforward fashion. The first guess of 1111 would answer how many 1's are in the solution; the next guess would answer how many 2's are in the solution, and also say something about where any 1's might be, and so on. 
  With our list approach, which contain a whole lot of possibilities in order beginning with 1111, 1112, 1113, 1114, etc., our next guess would always be the first in the list. </p></li>
  <li><p>The next strategy is for those who like a little more excitement. The guesses appear to be more or less random, with the hopes that a lot more information can be discovered. Simulating this approach is surprisingly simple -- if you have a list of numbers, just pick one at random. If you have 837 possibilities to choose from in an array, just pick a random subscript in the range of 0 to 836. </p></li>
  <li><p>This third strategy considers the possibility that answers that give similar results to a given guess are in a sense similar to each other. So to try to get a little more information, it will still pick some numbers at random without regard to how they were evaluated, and then only start thinking about the results. 
  To implement this one, let us just pick any three possible answers and guess them, temporarily ignoring how many black pegs and white pegs they earn us. Only after making those guesses will we trim the list of possibilities, then proceeding as the second strategy above. </p></li>
  </ol>
  
  <p>SAMPLE INTERFACE
  These are the sample results from the current implementation: Please enter a combination to try for, or 0 for a random value:  0
  Guessing at 2475</p>
  
  <pre><code>Guessing 1111...
  Guessing 2222...
  Guessing 2333...
  Guessing 2444...
  Guessing 2455...
  Guessing 2456...
  Guessing 2475...
  </code></pre>
  
  <p>Methodical Eliminate required 7 tries.</p>
  
  <pre><code>Guessing 6452...
  Guessing 2416...
  Guessing 2485...
  Guessing 2445...
  Guessing 2435...
  Guessing 2425...
  Guessing 2475...
  </code></pre>
  
  <p>Guess and Eliminate required 7 tries.</p>
  
  <pre><code>Guessing 7872...
  Guessing 6472...
  Guessing 1784...
  Guessing 2475...
  </code></pre>
  
  <p>Guess Three then Eliminate required 4 tries.</p>
  
  <p>Play another game?  (y/n) y
  Please enter a combination to try for, or 0 for a random value:  0
  Guessing at 4474</p>
  
  <pre><code>Guessing 1111...
  Guessing 2222...
  Guessing 3333...
  Guessing 4444...
  Guessing 4445...
  Guessing 4464...
  Guessing 4474...
  </code></pre>
  
  <p>Methodical Eliminate required 7 tries.</p>
  
  <pre><code>Guessing 3585...
  Guessing 7162...
  Guessing 4474...
  </code></pre>
  
  <p>Guess and Eliminate required 3 tries.</p>
  
  <pre><code>Guessing 8587...
  Guessing 1342...
  Guessing 1555...
  Guessing 7464...
  Guessing 6764...
  Guessing 4468...
  Guessing 4474...
  </code></pre>
  
  <p>Guess Three then Eliminate required 7 tries.
  NOTE: This program allows each digit to go up to 8 instead of 6. Even though there are 4096 possible answers, it still finds them rather rapidly. </p>
  
  <p><strong>PROGRAM SPECIFICATIONS</strong>
  The assigned program must implement all of the following functions. Additional ones are permitted as desired -- these below are required. Future assignments will not detail the functions as below -- but will instead require the students to design their own function descriptions in advance to writing the program. main:
  Simply governs the overall behavior of the program.  A number will be
  chosen as the target combination, and then each strategy will attempt
  to find it.
  Calls:  generateAnswer,      (to compare all three must have the same answer)
          methodicalEliminate, guessAndEliminate, guessThreeThenEliminate</p>
  
  <p><strong>generateAnswer:</strong>
  Either lets the user at the keyboard choose the mystery combination,
  or gives the option to have the computer generate a random combination.
  (For a competitive game, it might be interesting to know what sorts
  of combinations would be the hardest to guess!)
  Parameters:   none!
  Returns:      a 4-digit combination, each digit in the range 1 to 8</p>
  
  <p>generateSearchSpace:
  Populates an array with all possible combinations of four-digit
  values in the range 1 to 8.
  Parameters:
      guesses (modified int array)    list of guesses
      length  (output int)        number of values in list
  Pre-condition:
      The array must be allocated to no fewer than 4096 elements.</p>
  
  <p><strong>trim</strong>:
  Analyzes the response to a particular guess and then eliminates
  any values from the list of possibilities that are no longer
  possible answers.  In each case, it assumes that a value in the
  list is an answer, and evaluates the guess accordingly.  If the
  number of black and white pegs is not the same as those specified,
  then it cannot be the correct answer.
  <strong>Parameters:</strong>
      guesses (modified int array)    list of guesses
      length  (modified int)      number of values in list
      guess   (input int)     a guess that has been evaluated
      black   (input int)     how many black pegs that guess earned
      white   (input int)     how many white pegs that guess earned
  <strong>Pre-condition:</strong>
      black and white actually do contain the results of comparing
      the guess with the actual answer
  <strong>Post-condition:</strong>
      length has been reduced (we learned something)
      the viable answers occupy the first 'length' positions
          in the guesses array (so the list is shorter)
  Calls:  evaluate</p>
  
  <p><strong>methodicalEliminate</strong>:
      beginning with a list of all possible candidate answers
      continually guesses the first element in the list, and
      trim answers accordingly, until an answer is found
  Parameter:
      answer  (input int)     the actual answer
                      (necessary to get black/white pegs)
  Returns: number of guesses required to find the answer
  Calls:   generateSearchSpace, evaluate, trim</p>
  
  <p><strong>gusssAndEliminate</strong>:
      beginning with a list of all possible candidate answers
      continually guesses a random element in the list, and
      trim answers accordingly, until an answer is found
  Parameter:
      answer  (input int)     the actual answer
  Returns: number of guesses required to find the answer
  Calls:   generateSearchSpace, evaluate, trim</p>
  
  <p><strong>gusssThreeThenEliminate</strong>:
      beginning with a list of all possible candidate answers
      first guesses three answers at random before trimming
      the list of possibilites, and then narrows on the answer
      one random guess at a time
  Parameter:
      answer  (input int)     the actual answer
  Returns: number of guesses required to find the answer
  Calls:   generateSearchSpace, evaluate, trim</p>
  
  <p>NOTE: These last functions use the correct answer to evaluate
  each guess and then use the black/white pegs for the guessing
  strategy.  NOne of these strategies may peek at the answer to
  decide what to do next!</p>
  
  <p>ALSO: The following functions should also appear in this program
  from the previous assignment, though they are not themselves
  part of the grade for this one.</p>
  
  <p>evaluate:
  evaluates a combination by comparing it with the answer
  Correctness is indicated by black pegs (correct digit in correct position)
  and white pegs (correct digit in incorrect position)
  Parameters:
      answer  (input int) the correct combination
      guess   (input int) the current guess
      black   (output int)    number of black pegs
      white   (output int)    number of white pegs
  pre-conditions:
      answer and guess are both 4-digit numbers with no zero digits
  post-conditions:
      black and white are both > 0  and their sum is &lt;= 4
  Calls: nthDigit, clearNthDigit</p>
  
  <p>nthDigit:
  identified the n'th digit of a combination
  whether digits count from left to right or right to left is unspecified
  Parameters:
      combination (input int) combination to examine
      position    (input int) which digit to examine
      (returned)  (output int)    the value of the actual digit
  pre-conditions:
      combination has the appropriate number of digits, and
      0 &lt; position &lt;= number of digits
  post-condition:
      0 &lt;= returned digit &lt;= 9    (single digit)</p>
  
  <p>clearNthDigit:
  ears the n'th digit of a combination to zero, so it will no longer match
  digits must be counted in the same manner as nthDigit above.
  parameters:
      combination (in/out int)    combination to modify
      position    (input int) which digit to set to 0
  pre-condition:
      same as those for nthDigit above
  post-condition:
      corresponding digit is set to zero
  Calls: nthDigit (optional, depending on the implementation)</p>
  
  <p>Thank you for reading such this long question, and I hope you can help me on arrays!</p>