Lingo is a game in which a word has to be guessed. The amount of letters of the word is given, and usually also the first letter is known. To guess the word, the player can say a word of the right amount of letters. The computer then indicates which letters are correct and in the right place and which letters occur in the word that needs to be guessed, but aren't in the right place. In the example underneath the two kinds of tips are respectively indicated with a red and a yellow color.
If you weren't already familiar with the game, you could play it online here1 as an example to train yourself. But be careful, it may be addictive.
Write a function lingo with two parameters: guessed and searched. Strings should be given to both parameters that respectively contain a word that was given by the user and the hidden word the user must find. You may assume that both strings consist of lowercase letters and have the same length. The function must print a string as a result that contains a word that the user has given, but of which the letters that are correct and in the right place are between square brackets and the letters that do occur in the word to be guessed but are not in the correct place between round brackets. Here, we should observe the rules below:
One letter from the searched word can never lead to multiple markings in the guessed word. If a letter occurs multiple times in the word searched, the letters that are in the right place should be marked before the letters that are not in the right place.
If a certain letter from the searched word occurs two or more times in the word guessed, and one of them is in the right place, this position should be marked.
If a certain letter from the searched word occurs twice or more in the guessed word, but all of them are in the wrong place, the leftmost position should be marked.
Consecutive letters that are between two square brackets, should all be placed between one pair of square brackets.
Consecutive letters that are between two round brackets, should all be placed between one pair of round brackets.
>>> lingo('camelot', 'cembalo')
'[c](a)[m](elo)t'
>>> lingo('inquisition', 'reconquista')
'(inqu)i(s)i(t)i(o)n'
>>> lingo('python', 'embryo')
'p(y)th(o)n'
>>> lingo('megalomaniacally', 'circumstantiated')
'(me)g(a)loma(ni)a(c)[a]lly'