Skip to content

Instantly share code, notes, and snippets.

@gggauravgandhi
Last active August 28, 2016 14:15
Show Gist options
  • Select an option

  • Save gggauravgandhi/ec2c71fbe7c3885ef96d88949bed78d8 to your computer and use it in GitHub Desktop.

Select an option

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/)
// 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
}
}
}
}
}
}
}())
@gggauravgandhi

Copy link
Copy Markdown
Author

@gggauravgandhi

Copy link
Copy Markdown
Author

Pure mathematical solution on reddit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment