Last active
September 27, 2020 15:52
-
-
Save rauschma/4abb988b0c5b513fc4aa5fba71753650 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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