-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
42 lines (34 loc) · 1.11 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//!(function () {
trie = new Trie();
//var wordArray = "encyclopedia".split('');
attempted = [];
trie.build(words);
characterCount = function (characterCount) {
var max;
for (var exclude in attempted) {
delete characterCount[attempted[exclude]];
}
for (var character in characterCount) {
if (characterCount.hasOwnProperty(character)) {
if (max === undefined) {
max = character;
} else if (characterCount[character] > characterCount[max]) {
max = character;
}
}
}
attempted.push(max);
return max;
}
//trie.prune(wordArray.length - 1);
//for (var attempts = 0; trie.leafCount() > 1; attempts++) {
// var guess = characterCountMax(trie.characterCount());
// var indices = [];
// for (var index in wordArray) {
// if (guess === wordArray[index]) indices.push(parseInt(index));
// }
// console.log("Guessing: " + guess + " with indices " + JSON.stringify(indices));
// trie.filter(guess, indices).prune(wordArray.length - 1);
//}
//console.log("Found word in " + attempts + " guesses!");
//})();