Skip to content

Instantly share code, notes, and snippets.

@MrOnlineCoder
Created March 28, 2019 18: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 MrOnlineCoder/f8f4d882dc266013cc578dfebd4331d4 to your computer and use it in GitHub Desktop.
Save MrOnlineCoder/f8f4d882dc266013cc578dfebd4331d4 to your computer and use it in GitHub Desktop.
Count all 3-digit numbers, that are divisable by 3, that can be formed by using digits {1,2,3,4,5,6} (the digits can repeat)
let div = document.getElementById('result');
let nmap = {};
function append(str) {
if (nmap[str]) return;
div.innerHTML += str;
nmap[str] = true;
}
function test(a,b,c) {
if ((a + b + c) % 3 == 0 ) {
append(a+''+b+''+c+', ');
}
}
for (let a = 1; a < 7; a++) {
for (let b = 1; b < 7; b++) {
for (let c = 1; c < 7; c++) {
test(a,b,c);
test(a,c,b);
test(b,a,c);
test(b,c,a);
test(c,a,b);
test(c,b,a);
}
}
}
append("total: "+Object.keys(nmap).length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment