Skip to main content
3 of 8
added 159 characters in body
barteks2x
  • 281
  • 1
  • 4

Java ( 132 60)

60 characters:

boolean u(int n){return !(n+"").matches("^.*(.).*\\1.*$");}

132 characters:

boolean u(int n){int[] p=new int[]{2,3,5,7,11,13,17,19,32,29};double a=9001312320D;while(n>0){a/=p[n%10];n/=10;}return (long)a==a;}

with comments:

boolean unique(int n){
    int[] p=new int[]{2,3,5,7,11,13,17,19,32,29};//list of 10 first primes
    double a=9001312320D;//10 first primes multiplied
    while(n>0){
        a/=p[n%10];//divide by (n%10+1)th prime
        n/=10;//divide n by 10, next digit
    }
    return (long)a==a;//if a is integer then n has all digits unique
}
barteks2x
  • 281
  • 1
  • 4