Last active
August 28, 2016 14:15
-
-
Save gggauravgandhi/ec2c71fbe7c3885ef96d88949bed78d8 to your computer and use it in GitHub Desktop.
Brute Force solution to AA + BB + CC = ABC (Puzzle link : http://mindyourdecisions.com/blog/2016/05/22/aa-bb-cc-abc-sunday-puzzle/)
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
| // Link to jsfiddle : https://jsfiddle.net/gggauravgandhi/eb72685k/ | |
| // Gist : https://jsfiddle.net/gggauravgandhi/eb72685k/ | |
| (function() { | |
| for (var a = 0; a <= 9; a++) { | |
| for (var b = 0; b <= 9; b++) { | |
| if (b != a) { | |
| for (var c = 0; c <= 9; c++) { | |
| if (c != a && c != b) { | |
| var actualTotal = (a * 11) + (b * 11) + (c * 11); | |
| var targetTotal = (a * 100) + (b * 10) + (c * 1); | |
| if (actualTotal == targetTotal) { | |
| console.log("A is " + a + "\nB is " + b + "\nC is " + c + "\nTotal: " + actualTotal); | |
| document.body.innerHTML = "A is " + a + "<br>B is " + b + "<br>C is " + c + "<br>Total: " + actualTotal; // for non console user | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| }()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jsFiddle