mastermind

Solutions on MaxInterview for mastermind by the best coders in the world

showing results for - "mastermind"
Matthias
26 Jun 2019
1def right_inwrongplace(userGuess, number):
2    # Create a list of Boolean values representing correct guesses.
3    # for exemple: if numbers = [1,2,3,4] and guess = [1,2,9,9], correct_places will be [True,True,False,False]
4    correct_places = [True if v == number[i] else False for i, v in enumerate(userGuess)]
5    # create a list with only the incorrect guesses.
6    g = [v for  i, v in enumerate(userGuess) if not correct_places[i]]
7    # create a list with the numbers which weren't guessed correctly.
8    n = [v for  i, v in enumerate(number) if not correct_places[i]]
9    #return the amount of guesses that are correct but in the wrong place. (the numbers that are in both lists) 
10    return len([i for i in g if i in n])
11
similar questions
queries leading to this page
mastermind