Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Wooly Bully on the Farm solution in Clear category for Bulls and Cows by Tinus_Trotyl
from itertools import permutations
def breed(x, y): # returns the bulls an cows of permutation y in cattle x
bulls = cows = 0
for i in range(4):
if y[i] == x[i]: bulls += 1
elif y[i] in x : cows += 1
return bulls, cows
def checkio(data): # setup stock of all permutatoins then reduce to valid guesses
stock = list(permutations(range(10),4))
for guess in [(int(i[5]), int(i[7])) for i in data]:
stock = [cattle for cattle in stock if breed(cattle, stock[0]) == guess]
return "".join(str(x) for x in stock[0])
March 5, 2018
Comments: