Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- """
- Very Simple Mastermind
- """
- import random
- LENGTH = 4
- NB_SYMBOL = 5
- def main():
- """
- Main
- """
- combination = ''.join(str(random.randint(1, NB_SYMBOL))
- for _ in range(LENGTH))
- # print(combination) # for debug
- found = False
- nb = 0
- while not found:
- nb += 1
- current = (input('Your proposition? ').strip() + '1111')[:LENGTH]
- nb_good = sum((1 if value == combination[i]
- else 0)
- for i, value in enumerate(current))
- found = (nb_good == LENGTH)
- # print(current) # for debug
- print('{} good values, {} bad values'
- .format(nb_good, LENGTH - nb_good))
- print('You found the good combination {} in {} steps.'.format(current, nb))
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement