Skip to main content
Commonmark migration
Source Link

#Java 8, 192 183 181 171 bytes (full program)

Java 8, 192 183 181 171 bytes (full program)

#Java 8, 105 bytes (lambda function)

Java 8, 105 bytes (lambda function)

#Java 8, 192 183 181 171 bytes (full program)

#Java 8, 105 bytes (lambda function)

Java 8, 192 183 181 171 bytes (full program)

Java 8, 105 bytes (lambda function)

added 1828 characters in body
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

#Java 78, 192 183 181181 171 bytes (full program)

interface M{static void main(String[]a){long n=new Long(a[0]),c=0,r=1,m,i;for(;c<n;c+=m>1&(r+"").contains(a[0])?1:0)for(m=++r,i=2;i<m;m=m%i++<1?0:m);System.out.print(r);}}
class M{public static void main(String[]a){int i=1,c=0;while(!(c+"").equals(a[0]))if(!new String(new char[++i]).matches("(..+)\\1+")&(i+"").contains(a[0]))c++;System.out.print(i);}}

Try it online.

UngolfedExplanation:

class M
{
    public static void main(String[] a)
    {
        int i = 1,
            c = 0;
        while(!(c+"").equals(a[0]))
        {
            if(!new String(new char[++i]).matches("(..+)\\1+") &
                (i+"").contains(a[0]))
            {
                c++;
            }
        }
        System.out.print(i);
    }
}
interface M{                    // Class
  static void main(String[]a){  //  Mandatory main-method
    long n=new Long(a[0]),      //   Input argument as number
         c=0,                   //   Counter, starting at 0
         r=1,                   //   Result-number, starting at 1
         m,i;                   //   Temp number
    for(;c<n;                   //   Loop as long as `c` does not equals `n`
        c+=                     //     After every iteration: increase `c` by:
           m>1                  //      If the current `r` is a prime,
           &(r+"").contains(a[0])?
                                //      and this prime contains the input `n`
            1                   //       Increase `c` by 1
           :                    //      Else:
            0)                  //       Leave `c` the same
      for(m=++r,                //    Increase `r` by 1 first with `++r`, and set `m` to it
          i=2;i<m;              //    Inner loop `i` in the range [2, `m`)
        m=m%i++<1?              //     If `m` is divisible by `i`
           0                    //      Change `m` to 0 (so it's not a prime)
          :                     //     Else:
           m);                  //      Leave `m` unchanged
    System.out.print(r);}}      //    Print `r` as result

Usage: #Java 8, 105 bytes (lambda function)

java -jar M.jar 10
n->{int c=0,r=1,m,i;for(;c<n;c+=m>1&(r+"").contains(n+"")?1:0)for(m=++r,i=2;i<m;m=m%i++<1?0:m);return r;}

Output:Try it online.

1033

Same as above, but with n as integer input and without the verbose class stuff.

#Java 7, 192 183 181 bytes

class M{public static void main(String[]a){int i=1,c=0;while(!(c+"").equals(a[0]))if(!new String(new char[++i]).matches("(..+)\\1+")&(i+"").contains(a[0]))c++;System.out.print(i);}}

Ungolfed:

class M
{
    public static void main(String[] a)
    {
        int i = 1,
            c = 0;
        while(!(c+"").equals(a[0]))
        {
            if(!new String(new char[++i]).matches("(..+)\\1+") &
                (i+"").contains(a[0]))
            {
                c++;
            }
        }
        System.out.print(i);
    }
}

Usage:

java -jar M.jar 10

Output:

1033

#Java 8, 192 183 181 171 bytes (full program)

interface M{static void main(String[]a){long n=new Long(a[0]),c=0,r=1,m,i;for(;c<n;c+=m>1&(r+"").contains(a[0])?1:0)for(m=++r,i=2;i<m;m=m%i++<1?0:m);System.out.print(r);}}

Try it online.

Explanation:

interface M{                    // Class
  static void main(String[]a){  //  Mandatory main-method
    long n=new Long(a[0]),      //   Input argument as number
         c=0,                   //   Counter, starting at 0
         r=1,                   //   Result-number, starting at 1
         m,i;                   //   Temp number
    for(;c<n;                   //   Loop as long as `c` does not equals `n`
        c+=                     //     After every iteration: increase `c` by:
           m>1                  //      If the current `r` is a prime,
           &(r+"").contains(a[0])?
                                //      and this prime contains the input `n`
            1                   //       Increase `c` by 1
           :                    //      Else:
            0)                  //       Leave `c` the same
      for(m=++r,                //    Increase `r` by 1 first with `++r`, and set `m` to it
          i=2;i<m;              //    Inner loop `i` in the range [2, `m`)
        m=m%i++<1?              //     If `m` is divisible by `i`
           0                    //      Change `m` to 0 (so it's not a prime)
          :                     //     Else:
           m);                  //      Leave `m` unchanged
    System.out.print(r);}}      //    Print `r` as result

#Java 8, 105 bytes (lambda function)

n->{int c=0,r=1,m,i;for(;c<n;c+=m>1&(r+"").contains(n+"")?1:0)for(m=++r,i=2;i<m;m=m%i++<1?0:m);return r;}

Try it online.

Same as above, but with n as integer input and without the verbose class stuff.

Saved 2 bytes thanks to @cliffroot's comment
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

#Java 7, 192 183183 181 bytes

class M{public static void main(String[]a){int i=1,c=0;while(!(c+"").equals(a[0]))if(!new String(new char[++i]).matches("(..+?)\\1+")&&&(i+"").contains(a[0]))c++;System.out.print(i);}}

Ungolfed:

class M
{
    public static void main(String[] a)
    {
        int i = 1,
            c = 0;
        while(!(c+"").equals(a[0]))
        {
            if(!new String(new char[++i]).matches("(..+?)\\1+") &&&
                (i+"").contains(a[0]))
            {
                c++;
            }
        }
        System.out.print(i);
    }
}

Usage:

java -jar M.jar 10

Output:

1033

#Java 7, 192 183 bytes

class M{public static void main(String[]a){int i=1,c=0;while(!(c+"").equals(a[0]))if(!new String(new char[++i]).matches("(..+?)\\1+")&&(i+"").contains(a[0]))c++;System.out.print(i);}}

Ungolfed:

class M
{
    public static void main(String[] a)
    {
        int i = 1,
            c = 0;
        while(!(c+"").equals(a[0]))
        {
            if(!new String(new char[++i]).matches("(..+?)\\1+") &&
                (i+"").contains(a[0]))
            {
                c++;
            }
        }
        System.out.print(i);
    }
}

Usage:

java -jar M.jar 10

Output:

1033

#Java 7, 192 183 181 bytes

class M{public static void main(String[]a){int i=1,c=0;while(!(c+"").equals(a[0]))if(!new String(new char[++i]).matches("(..+)\\1+")&(i+"").contains(a[0]))c++;System.out.print(i);}}

Ungolfed:

class M
{
    public static void main(String[] a)
    {
        int i = 1,
            c = 0;
        while(!(c+"").equals(a[0]))
        {
            if(!new String(new char[++i]).matches("(..+)\\1+") &
                (i+"").contains(a[0]))
            {
                c++;
            }
        }
        System.out.print(i);
    }
}

Usage:

java -jar M.jar 10

Output:

1033
Saved 9 bytes: I never use the input as int, so I remove the parseInt and used String#equals in the while-loop instead
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384
Loading
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384
Loading