Public feed #531135

Mine

public python v1 · immutable
Raw Edit
·published 2007-06-02 11:34 UTC
rendered paste body
def testAttempt(attempt, goal) :	"""	Compares the player's attempt with the randomly generated sequence	and return the results in a list.		If a given coulour appears more than once in either sequence, we'll	have a problem so we use a counter on each colour so that if a colour	appears twice in one sequence and just once in the other, it will be	counted as one in the results, for example, if the goal is :		[1, 2, 3, 4, 5, 6] and the player's guess is [2, 1, 1, 1, 1, 1]		the results will be [0, 2]	"""		#begin preconditions	assert type(attempt) is list	assert len(attempt) == 6	assert type(goal) is list	assert len(goal) == 6	#end preconditions		#We initialize the results list	res = [0, 0]		# First we check the number of correct colours and we put their	#indexes in a list so we can remove them afterwards.	tmp = [[], [], []]	for i in range(len(attempt)) :		if attempt[i] == goal[i] :			res[0] += 1			tmp[0].append(i)		for i in range(len(attempt)) :		if i not in tmp[0] :			tmp[1].append(attempt[i])			tmp[2].append(goal[i])	for i in tmp[1] :		for j in tmp[2] :			if i == j :				res[1] += 1				tmp[2].remove(j)				break		return res