Skip to content

Instantly share code, notes, and snippets.

@dferber90
Last active January 21, 2020 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dferber90/162411bbbf414839d4129b6eba546215 to your computer and use it in GitHub Desktop.
Save dferber90/162411bbbf414839d4129b6eba546215 to your computer and use it in GitHub Desktop.
TENS! cheat
// This is a cheat for the game TENS! by @ryanflorence
// at http://ryanflorence.com/tens/
// see https://mobile.twitter.com/ryanflorence/status/1219351388775256064
//
// To use this cheat, open http://ryanflorence.com/tens/ and paste the code
// into your terminal and execute it. The game will start for you.
// The solutions will be highlighted and you just need to click them.
// Solutions with two numbers are red, solutions with three numbers are green.
//
// Have fun
(() => {
const startButton = document.getElementById("startButton");
const startOver = document.getElementById("startOver");
if (startButton) startButton.click();
if (startOver) startOver.click();
function solve() {
const buttons = document.querySelectorAll("button:not([id])");
const values = Array.from(buttons).map(x => Number(x.innerText));
let found = false;
// skip when there are not enough buttons
if (buttons.length < 2) return;
// starting with the first button, try all combinations of 2 buttons
let i, j;
for (i = 0; i < values.length - 1; i++) {
if (found) continue;
for (j = i + 1; j < values.length; j++) {
if (found) continue;
if (values[i] + values[j] === 10) {
console.log("found", values[i], values[j]);
buttons[i].style.backgroundColor = "red";
buttons[j].style.backgroundColor = "red";
found = true;
}
}
}
// skip when a solution was found or when there are not
// enough buttons for a solution of three numbers.
if (buttons.length < 3 || found) return;
// starting with the first button, try all combinations of 3 buttons
let a, b, c;
for (a = 0; a < values.length - 2; a++) {
if (found) continue;
for (b = a + 1; b < values.length - 1; b++) {
if (found) continue;
for (c = b + 1; c < values.length; c++) {
if (found) continue;
if (values[a] + values[b] + values[c] === 10) {
console.log("found", values[a], values[b], values[c]);
buttons[a].style.backgroundColor = "green";
buttons[b].style.backgroundColor = "green";
buttons[c].style.backgroundColor = "green";
found = true;
}
}
}
}
}
setInterval(solve, 100);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment