Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mastermind
#1
Im taking a basic python course in university and my class project is creating something like mastermind.

We have to create a program that guesses the 4-digit number you're thinking (digits from 1 to 6) in 9 tries or less. The only questions I can ask are: 'how many numbers are correct in the correct position?' and 'how many numbers are correct in the incorrect position?'.

Right now I have a program that loops 9 times through the 2 questions after guessing a number and stores the number and answers in a list. My problem is that my guesses are simply random numbers that do not take into account previous answers. I'd appreciate any tips on how to improve the guessed number every time. I can do it manually but I just can't figure out how to put it in Python.
Quote
#2
Start with a list of all the possible numbers. Your guess can be a random choice from that list. Each time you get the two answers, go through that list and remove any numbers that don't match the two answers and the number previously guessed. What will be really useful are two functions: one that returns True if number x has n digits of number y in the correct position, and another that returns True if number x has n digits of number y in the incorrect position. Only keep numbers in the list of possible guesses if they match both of those functions.
Craig "Ichabod" O'Brien - xenomind.com
Buddhist, biker, poet, coder, theist
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#3
Thanks! I did that and it worked perfectly. Now I'll just have to check that it always works in less than 9 tries.
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)