Created
January 9, 2016 02:41
-
-
Save travist/a00bc7448fa00262f2a2 to your computer and use it in GitHub Desktop.
Self Descriptive number solution
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
for (var i = 0; i < 9999999999; i++) { | |
var num = ("0000000000" + i).substr(-10,10); | |
var counts = [0,0,0,0,0,0,0,0,0,0]; | |
for (var j = 0; j < 10; j++) { | |
counts[num[j]]++; | |
} | |
if (counts.join('') === num) { | |
console.log('Winner!' + num); | |
break; | |
} | |
if (i % 100000 === 0) { | |
console.log('Checking' + num); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've also made a program which computes these numbers:
https://yaireo.github.io/self-descriptive-numbers