Skip to content

Instantly share code, notes, and snippets.

@bioid
Created March 17, 2016 17:53
Show Gist options
  • Save bioid/14dff59fe35323a07467 to your computer and use it in GitHub Desktop.
Save bioid/14dff59fe35323a07467 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 12 12:32:53 2016
@author: bioid
"""
from random import choice
colors = ['R', 'Y', 'G', 'B']
slots = [choice(colors) for x in range(4)]
def hits(guess, solution):
hits = 0
pseudo = 0
for i in range(4):
if guess[i] == solution[i]:
hits += 1
elif guess[i] in solution:
pseudo += 1
return hits, pseudo
def parseInput(string):
return [x for x in string.upper()]
while True:
print('Enter a guess:')
num_hits, pseudohits = hits(parseInput(input()), slots)
if num_hits == 4:
print('You win! The answer was: %s' %''.join(x for x in slots))
break
else:
print('hits: %s, pseudohits: %s' %(num_hits, pseudohits))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment