Skip to content

Instantly share code, notes, and snippets.

@travist
Created January 9, 2016 02:41
Show Gist options
  • Save travist/a00bc7448fa00262f2a2 to your computer and use it in GitHub Desktop.
Save travist/a00bc7448fa00262f2a2 to your computer and use it in GitHub Desktop.
Self Descriptive number solution
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);
}
}
@yairEO
Copy link

yairEO commented Aug 29, 2018

I've also made a program which computes these numbers:

https://yaireo.github.io/self-descriptive-numbers

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