console.log("Loading dictionary...");
var dict = JSON.parse(fs.readFileSync("words_dictionary.json").toString());
console.log("Done.");
var count = 0;
var possibilities = [];
function printAllKLength(set, k) {
let n = set.length;
printAllKLengthRec(set, "", n, k);
}
// The main recursive method to get all possible strings of length k
function printAllKLengthRec(set, prefix ,n, k) {
count++;
if (count % 1000000 === 0)
console.log(count / 1000000 + 'm')
// Base case: k is 0, return prefix
if (k == 0) {
solveJam(prefix)
return;
}
//One by one add all characters from set and recursively call for k equals to k-1
for (let i = 0; i < n; ++i) {
//Next character of input added
let newPrefix = prefix + set[i];
//k is decreased, because we have added a new character
printAllKLengthRec(set, newPrefix, n, k - 1);
}
}
function generateLetterCombos() {
let set1=[' ', 'a', 'b', 'c', 'd,', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
let k = 6;
printAllKLength(set1, k);
console.log(possibilities);
}
String.prototype.replaceAt = function(index, replacement) {
return this.substr(0, index) + replacement + this.substr(index + replacement.length);
}
function solveJam(input) {
var puzzle = "a_i_ m_s___e";
const blanks = [1, 3, 6, 8, 9, 10]
for (i = 0; i < 6; i++) {
puzzle = puzzle.replaceAt(blanks[i], input.charAt(i));
}
//every word has to be in the dictionary
var words = puzzle.split(" ");
var pass = true;
for (w = 0; w < words.length; w++) {
if (w in dict) {}
else {
pass = false;
break;
}
}
if (pass == true) {
console.log(input);
possibilities.push(input);
}
}
generateLetterCombos();