Truco para el marcador del juego "Letterbox" del New York Times

Escribí un bookmarklet que encuentra una solución de dos palabras para el juego "Letterbox" del New York Times. Funcionó, pero por diversión decidí que una IA lo reescribiera para que fuera más rápido. Aquí está el código que creó, pero tardó varios intentos antes de que pudiera abrir una nueva pestaña. Funciona mucho más rápido que lo que escribí.

javascript:(function(){
    const gameData = window.gameData;
    if (!gameData?.sides || !gameData?.dictionary) return alert("Game data not found!");

    const sides = gameData.sides.join('');
    const requiredChars = {};
    for (let c of sides) requiredChars[c] = (requiredChars[c] || 0) + 1;
    
    const words = gameData.dictionary.map(w => ({ w, f: w[0], l: w.at(-1) }));
    const validCombinations = [];

    function usesAllChars(w1, w2) {
        const count = { ...requiredChars };
        for (let c of w1 + w2) if (count[c]) count[c]--;
        return !Object.values(count).some(v => v > 0);
    }

    for (let i = 0; i < words.length; i++) {
        for (let j = 0; j < words.length; j++) {
            if (i !== j && words[i].l === words[j].f && usesAllChars(words[i].w, words[j].w)) {
                validCombinations.push([words[i].w, words[j].w]);
            }
        }
    }

    validCombinations.sort((a, b) => a.join('').length - b.join('').length);

    const newTab = window.open("", "_blank");
    if (!newTab || newTab.closed) {
        alert("Pop-up blocked! Please allow pop-ups for this site.");
        return;
    }

    newTab.document.write(`<!DOCTYPE html>
        <html><head><title>Letterbox Solver</title>
        <style>body{font-family:Arial;padding:20px;}table{width:100%;border-collapse:collapse;}th,td{border:1px solid #ddd;padding:8px;text-align:left;}th{background:#f2f2f2;}</style>
        </head><body><h1>Letterbox Word Combinations</h1>
        <table><tr><th>Word 1</th><th>Word 2</th><th>Combined Length</th></tr>
        ${validCombinations.map(([w1,w2]) => `<tr><td>${w1}</td><td>${w2}</td><td>${w1.length + w2.length}</td></tr>`).join('')}
        </table></body></html>`);
    newTab.document.close();
})();

It works great. To use this, first copy the code above. Then set your browser to display the bookmark bar. Then right click on the bar and select the “new bookmark” item (I am using a chrome base browser).

Change the title, and then paste the copied code into the address field and click save.

Now when you are playing the game, you can click on this bookmarklet and it will open a new tab with all of the two word solutions to the game.

Enjoy.

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *