Created
March 28, 2019 18:47
-
-
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)
This file contains 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
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