Consider a game, wherein the player has to guess a target word. All the player knows is the length of the target word.

To help them in their goal, the game will accept guesses, and return the number of letters that are in the correct position.

Write a method that, given the correct word and the player's guess, returns this number.

For example, here's a possible thought process for someone trying to guess the word "dog":

```cs
CountCorrectCharacters("dog", "car"); //0 (No letters are in the correct position)
CountCorrectCharacters("dog", "god"); //1 ("o")
CountCorrectCharacters("dog", "cog"); //2 ("o" and "g")
CountCorrectCharacters("dog", "cod"); //1 ("o")
CountCorrectCharacters("dog", "bog"); //2 ("o" and "g")
CountCorrectCharacters("dog", "dog"); //3 (Correct!)
```
```python
count_correct_characters("dog", "car"); #0 (No letters are in the correct position)
count_correct_characters("dog", "god"); #1 ("o")
count_correct_characters("dog", "cog"); #2 ("o" and "g")
count_correct_characters("dog", "cod"); #1 ("o")
count_correct_characters("dog", "bog"); #2 ("o" and "g")
count_correct_characters("dog", "dog"); #3 (Correct!)
```

The caller should ensure that the guessed word is always the same length as the correct word, but since it could cause problems if this were not the case, you need to check for this eventuality:

```cs
//Throw an InvalidOperationException if the two parameters are of different lengths.
```
```python
#Raise an exception if the two parameters are of different lengths.
```

You may assume, however, that the two parameters will always be in the same case.

Source: codewars | Difficulty: EASY
Tags: String algorithms

Game theory

Ad-hoc

Starter code: def count_correct_characters(correct, guess):
	

Solutions:
def count_correct_characters(c, g):
	if len(c) != len(g):
		raise Exception('Error')
	return sum((1 for (i, j) in zip(c, g) if i == j))


def count_correct_characters(s, t):
	assert len(s) == len(t)
	return sum((a == b for (a, b) in zip(s, t)))


def count_correct_characters(correct, guess):
	if len(correct) == len(guess):
		return sum((1 for (cc, cg) in zip(correct, guess) if cc == cg))
	else:
		raise Exception


def count_correct_characters(correct, guess):
	if len(correct) != len(guess):
		raise Error('The two lengths are not the same')
	return sum((correct[i] == guess[i] for i in range(len(correct))))


def count_correct_characters(correct, guess):
	if len(correct) == len(guess):
		return sum((c == g for (c, g) in zip(correct, guess)))
	else:
		raise Exception('guess contains the wrong number of characters')


def count_correct_characters(correct, guess):
	if len(correct) != len(guess):
		raise ValueError('Error: different word lengths')
	return sum((a == b for (a, b) in zip(correct, guess)))


def count_correct_characters(correct, guess):
	print(correct, guess)
	if len(correct) != len(guess):
		return error
	a = list(correct)
	b = list(guess)
	print(a, b)
	c = 0
	for i in range(len(a)):
		if a[i] == b[i]:
			c = c + 1
	return c


def count_correct_characters(correct, guess):
	if len(correct) != len(guess):
		raise Exception()
	return sum((l1 == l2 for (l1, l2) in zip(correct, guess)))


def count_correct_characters(correct, guess):
	if len(correct) != len(guess):
		raise Exception('Wrong length')
	res = sum((1 for (a, b) in zip(correct, guess) if a == b))
	return res


def count_correct_characters(correct, guess):
	if len(correct) != len(guess):
		raise Exception
	return sum((a == b for (a, b) in zip(correct, guess)))


def count_correct_characters(correct, guess):
	assert len(correct) == len(guess)
	return len([a for (a, b) in zip(correct, guess) if a == b])


def count_correct_characters(a, b):
	return len([i for i in range(len(a)) if a[i] == b[i]]) if len(a) == len(b) else error


def count_correct_characters(a, b):
	assert len(a) == len(b)
	return sum((a[i] == b[i] for i in range(len(a))))


def count_correct_characters(correct, guess):
	num = 0
	if len(correct) != len(guess):
		raise Exception('The lengths are not the same')
	for n in range(len(correct)):
		if list(correct)[n] == list(guess)[n]:
			num += 1
	return num


def count_correct_characters(correct, guess):
	if len(correct) != len(guess):
		raise Exception()
	return sum((c == g for (c, g) in zip(correct, guess)))


def count_correct_characters(correct, guess):
	if len(correct) != len(guess):
		raise Exception
	return sum((i == j for (i, j) in zip(correct, guess)))


def count_correct_characters(correct, guess):
	if len(correct) != len(guess):
		raise 'Error!'
	else:
		count = 0
		for (i, x) in enumerate(correct):
			for (j, y) in enumerate(guess):
				if i == j and x == y:
					count += 1
		return count


def count_correct_characters(correct, guess):
	if len(correct) != len(guess):
		raise ValueError
	else:
		return sum((1 for (x, y) in zip(correct, guess) if x == y))


def count_correct_characters(correct, guess):
	if len(correct) != len(guess):
		raise Exception()
	count = 0
	for i in range(len(guess)):
		if correct[i] == guess[i]:
			count += 1
	return count


def count_correct_characters(c, g):
	if len(c) != len(g):
		raise ValueError('Is this the error you wanted?')
	else:
		return sum([1 for i in zip(c, g) if i[0] == i[1]])