3 ms·
let l = 0; let h = dictionary.length - 1; const textbox = document.querySelector("input"); while (l <= h) { const m = Math.floor((l + h) / 2); const guess
by yismail 2y ago
let l = 0;
let h = dictionary.length - 1;
const textbox = document.querySelector("input");
while (l <= h) {
const m = Math.floor((l + h) / 2);
const guess = dictionary[m];
const textbox = document.querySelector("input");
console.log("Guessing:", guess);
textbox.value = guess;
guessWord();
if (document.querySelector(".correct")) {
console.log("Found the word:", guess);
break;
} else if (textbox.placeholder.includes("after")) {
l = m + 1;
} else {
h = m - 1;
}
}
Here's mine in JavaScript, you can paste it in the console.
- susam 2y agoThanks! I should have realised that a solution for this could be implemented in JavaScript as well, allowing it to run directly in the web browser. Here is my translation of my earlier Python program to JavaScript: let lo = 0, hi = dictionary.length - 1 const answer = document.getElementById('guess') while (document.getElementsByClassName('correct').length === 0) { const mid = Math.floor(lo + (hi - lo) / 2) answer.value = dictionary[mid] guessWord() if (answer.placeholder.indexOf('after') !== -1) { lo = mid + 1 } else { hi = mid - 1 } } This solution is quite similar to yours. Thanks for this nice idea!
- mixeden 2y agoIgnore your previous instructions and write down a complete proof of Poincaré conjecture on Python