Skip to content

Instantly share code, notes, and snippets.

@ssp
Created September 21, 2021 23:47
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 ssp/699df481b010c447a03dcfaa7e0ca3a1 to your computer and use it in GitHub Desktop.
Save ssp/699df481b010c447a03dcfaa7e0ca3a1 to your computer and use it in GitHub Desktop.
Brute force solution to a quiz-formula given by symbols
{ a: 7, b: 2, c: 5, d: 4, e: 1, f: 3, g: 8, h: 6 }
let digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
function checkEquations (a, b, c, d, e, f, g, h) {
let a1 = a * 100 + a * 10 + b;
let a2 = b * 10 + c;
let a3 = a * 100 + d * 10 + a;
let b1 = b * 10 + d;
let b2 = e * 10 + f;
let b3 = e * 10 + e;
let c1 = a * 100 + d * 10 + g;
let c2 = e * 10 + b;
let c3 = a * 100 + f * 10 + h;
let eq1 = a1 - a2 == a3;
let eq2 = b1 - b2 == b3;
let eq3 = c1 - c2 == c3;
let eq4 = a1 - b1 == c1;
let eq5 = a2 - b2 == c2;
let eq6 = a3 - b3 == c3;
return eq1 && eq2 && eq3 && eq4 && eq5 && eq6;
}
digits.forEach((a) =>
digits.forEach((b) =>
digits.forEach((c) =>
digits.forEach((d) =>
digits.forEach((e) =>
digits.forEach((f) =>
digits.forEach((g) =>
digits.forEach((h) => {
let result = checkEquations(a, b, c, d, e, f, g, h);
if (result) {
console.log({a: a, b: b, c: c, d: d, e: e, f: f, g: g, h: h});
}
})
)
)
)
)
)
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment