Anonymous user
Mastermind: Difference between revisions
→{{header|Python}}: Edited Python example to match rules as discussed under the section about the Julia implementation
(→{{header|Python}}: Edited Python example to match rules as discussed under the section about the Julia implementation) |
|||
Line 2,167:
def encode(correct, guess):
output_arr = [''] * len(correct)
for i, (correct_char, guess_char) in enumerate(zip(correct, guess)):
output_arr[i] = 'X' if
return ''.join(output_arr)
Line 2,203 ⟶ 2,191:
print("You will need to guess a random code.")
print("For each guess, you will receive a hint.")
print("In this hint, X denotes a correct letter, and O a letter in the original string but in a different position.")
▲ print('')
number_of_letters = safe_int_input("Select a number of possible letters for the code (2-20): ", 2, 20)
Line 2,215 ⟶ 2,202:
while True:
print(
guess = input(f"Enter a guess of length {code_length} ({letters}): ").upper().strip()
Line 2,242 ⟶ 2,229:
For each guess, you will receive a hint.
In this hint, X denotes a correct letter, and O a letter in the original string but a different position.
Select a number of possible letters for the code (2-20): 4
Line 2,249 ⟶ 2,235:
*omitted first guesses*
Enter a guess of length 4 (ABCD):
------------------------------------
1: A A B B => O
------------------------------------
2:
------------------------------------
Enter a guess of length 4 (ABCD):
Your guess
</pre>
|