如果你调用 Master.guess 的次数大于 allowedGuesses 所限定的次数或者你没有用 Master.guess 猜到秘密单词,则得到 "Either you took too many guesses, or you did not find the secret word." 。
如果你调用 Master.guess 猜到秘密单词,且调用 Master.guess 的次数小于或等于 allowedGuesses ,则得到 "You guessed the secret word correctly." 。
for (intguess=0; guess < H.length; ++guess) { if (!path.contains(guess)) { ArrayList<Integer>[] groups = newArrayList[7]; for (inti=0; i < 7; ++i) groups[i] = newArrayList<Integer>(); for (Integer j: possible) if (j != guess) { groups[H[guess][j]].add(j); }
ArrayList<Integer> maxgroup = groups[0]; for (inti=0; i < 7; ++i) if (groups[i].size() > maxgroup.size()) maxgroup = groups[i];
classSolution(object): deffindSecretWord(self, wordlist, master): N = len(wordlist) self.H = [[sum(a==b for a,b in itertools.izip(wordlist[i], wordlist[j])) for j in xrange(N)] for i in xrange(N)]
possible, path = range(N), () while possible: guess = self.solve(possible, path) matches = master.guess(wordlist[guess]) if matches == len(wordlist[0]): return possible = [j for j in possible if self.H[guess][j] == matches] path = path + (guess,)