I'm new to python and I need to write a "Bulls and Cows" game (a.k.a Mastermind) and it goes like this:
You get 2 inputs at first; 1 for the length of the secret (can be 4-6), and 2nd for the base (can be 6-10). You can ASSUME that both the secret and the guess will have the given length (you don't need to make sure of that) Later on, you have another 2 inputs. 1 for the secret (a chain of numbers seperated by space) and the 2nd for the base (a chain of numbers seperated by space). if the secret has a number that equals or exceeds the base, the program will output ERROR and exit.
An example to clarify:
5 (First input, length should be 5)
8 (The base. It means that no number is allowed to be 8 or beyond. You are only allowed to use 0,1,2,3,4,5,6,7)
1 2 7 2 5 (this is the secret)
7 2 2 1 1 (this is the guess)
OUTPUT:
1 BULLS 3 COWS
Another example:
6
9
0 0 0 0 0 6
8 22 2 2 1 4
OUTPUT:
0 BULLS 0 COWS
Ok, so I started writing the code, and I wasn't sure what exactly I am supposed to be using, so I did this so far:
#get the length of the guess - an int number between 4(included) to 6(included)
secretL = input()
#get the base of the guess - an int number between 6(included) to 10(included)
secretB = input()
#get the guess
secret = raw_input()
secretsNumbers = map(int, secret.split())
#turn the chain into a singular INT number in order to make sure each of its digits does not equal or exceeds base, using %10
secretsNumbersMerge = int(''.join(map(str,secretsNumbers)))
newSecretsNumbersMerge = secretsNumbersMerge
while newSecretsNumbersMerge!= 0:
checker = newSecretsNumbersMerge%10
if checker<secretBase:
newSecretsNumbersMerge = newSecretsNumbersMerge/10
else:
print ("ERROR")
quit()
guess = raw_input()
guessNumbers = map(int, guess.split())
So far it's all good. This really makes sure the secret meets the base demands. Now I'm at the main point where I should check for bulls and cows and I'm not quite sure how to proceed from this point.
My idea is to first check for Bulls and then remove them (so it won't get mixed with cows), and then check for cows but yeah.. I'm clueless.
I'm not even sure what to use in Python.
Thanks in advance!