# A self-referential number

## 3 posts in this topic

Posted · Report post

Can you find a seven digit number which describes itself. The first digit is the number of zeros in the number. The second digit is the number of ones in the number, etc. For example, in the number 21200, there are 2 zeros, 1 one, 2 twos, 0 threes and 0 fours.

0

##### Share on other sites

Posted · Report post

3211000

0

##### Share on other sites

Posted · Report post

There is only one such number and kukupai found it.

```public class Class1 {

public static void main(String[] args) {
int[] digits;
for(int i=0;i<10000000;i++){
digits = getDigits(i);
if(isSelfReferential(digits)){
System.out.printf("%07d\n",i);
}
}
}
private static int[] getDigits(int num) {
int[] d = new int[7];
for(int i=0;i<d.length;i++){
d[i] = num % 10;
num = num / 10;
}
return d;
}
private static boolean isSelfReferential(int[] d) {
for(int i=0;i<d.length;i++){
int count = 0;
for(int d1:d){
if(d1==i){
count++;
}
}
if(d[d.length-1-i] != count){
return false;
}
}
return true;
}
}
```

0

## Create an account

Register a new account