Skip to content

Instantly share code, notes, and snippets.

@rmasters
Created March 29, 2020 13:47
Show Gist options
  • Save rmasters/fd36bae985bdfdad3b44a4e76267da52 to your computer and use it in GitHub Desktop.
Save rmasters/fd36bae985bdfdad3b44a4e76267da52 to your computer and use it in GitHub Desktop.
Beats http://zzzscore.com/1to50/ in ~5 seconds. Can be made faster if your laptop isn't on it's last legs.
// http://zzzscore.com/1to50/ beater
function getPositions(root) {
const elems = new Map();
for (const elem of root.querySelectorAll('div')) {
const num = parseInt(elem.innerText);
if (num > 0) { // Ignore spacer/styling elements
elems.set(parseInt(elem.innerText), elem);
}
}
return elems;
}
function tap(elem) {
// document.createEvent('TouchEvent') doesn't seem to work, and this page uses jquery.tap(cb) anyway
$(elem).trigger('tap');
}
function solve() {
// This contains all elements 1-50, not just visible ones
const grid = document.getElementById('grid');
// Solve the next number
// Solving is pretty fast. It crashed firefox so we'll have to slow it down
function solveNext(grid, n, maxN) {
console.log(`Tapping ${n}`);
positions = getPositions(grid);
tap(positions.get(n));
if (n < maxN) {
// Delay the next solve by 100ms - might not be necessary, but on my overburdened laptop this prevents
// killing the browser. Possibly some unoptimised javascript animation going on when you tap a square.
window.setTimeout(solveNext.bind(this, grid, n + 1, maxN), 100);
}
}
solveNext(grid, 1, 50);
}
solve(); // suck it weller
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment