Skip to content

Instantly share code, notes, and snippets.

@rauschma
Last active September 27, 2020 15:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rauschma/4abb988b0c5b513fc4aa5fba71753650 to your computer and use it in GitHub Desktop.
Save rauschma/4abb988b0c5b513fc4aa5fba71753650 to your computer and use it in GitHub Desktop.
// Problem: ABCDE × A = EEEEEE. Each letter is a different digit.
// Source: https://twitter.com/preshtalwalkar/status/1309643691506761728?s=20
// Equation to solve: EEEEEE / A = ABCDE
// You have to try 9 digits E and 8 digits A per E (with A neither zero nor E)
for (let E=1; E <= 9; E++) {
for (let A=1; A <= 9; A++) {
if (A === E) continue;
const solutionNumber = (E * 111111) / A;
if (!Number.isInteger(solutionNumber)) continue;
const solutionString = String(solutionNumber);
if (solutionString.length === 5
&& solutionString.startsWith(String(A))
&& solutionString.endsWith(String(E))) {
const digitSet = new Set([...solutionString]);
// Is each digit unique?
if (digitSet.size === 5) {
console.log(solutionNumber);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment