Skip to main content
Commonmark migration
Source Link

#Java 10, 62 59 58 bytes

Java 10, 62 59 58 bytes

n->{var r=n;for(;!(r+"").matches("[01]+");)r+=n;return r;} 

Try it online.

Explanation:

n->{ // Method with long as both parameter and return-type var r=n; // Result-long, starting at the input for(;!(r+"").matches("[01]+");) // Loop as long as `r` does NOT consists of only 0s and 1s r+=n; // Increase `r` by the input return r;} // After the loop is done, return `r` as result 

This method above only works for binary outputs \$\leq1111111111111111111\$. For arbitrary large outputs - given enough time and resources - the following can be used instead (99 70 64 bytes):

n->{var r=n;for(;!(r+"").matches("[01]+");)r=r.add(n);return r;} 

Try it online.

#Java 10, 62 59 58 bytes

n->{var r=n;for(;!(r+"").matches("[01]+");)r+=n;return r;} 

Try it online.

Explanation:

n->{ // Method with long as both parameter and return-type var r=n; // Result-long, starting at the input for(;!(r+"").matches("[01]+");) // Loop as long as `r` does NOT consists of only 0s and 1s r+=n; // Increase `r` by the input return r;} // After the loop is done, return `r` as result 

This method above only works for binary outputs \$\leq1111111111111111111\$. For arbitrary large outputs - given enough time and resources - the following can be used instead (99 70 64 bytes):

n->{var r=n;for(;!(r+"").matches("[01]+");)r=r.add(n);return r;} 

Try it online.

Java 10, 62 59 58 bytes

n->{var r=n;for(;!(r+"").matches("[01]+");)r+=n;return r;} 

Try it online.

Explanation:

n->{ // Method with long as both parameter and return-type var r=n; // Result-long, starting at the input for(;!(r+"").matches("[01]+");) // Loop as long as `r` does NOT consists of only 0s and 1s r+=n; // Increase `r` by the input return r;} // After the loop is done, return `r` as result 

This method above only works for binary outputs \$\leq1111111111111111111\$. For arbitrary large outputs - given enough time and resources - the following can be used instead (99 70 64 bytes):

n->{var r=n;for(;!(r+"").matches("[01]+");)r=r.add(n);return r;} 

Try it online.

deleted 76 characters in body
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394

#Java 10, 62 5959 58 bytes

n->{intvar r=0;forr=n;for(;!((r+=n)+""r+"").matches("[01]+"););returnr+=n;return r;} 

Try it online.Try it online.

Explanation:

n->{ // Method with integerlong as both parameter and return-type intvar r=0;r=n; // Result-integerlong, starting at 0the input for(; // Continue!(r+"").matches("[01]+");)  looping as long as the following is true:  !((r+=n) // Increase `r` byLoop theas inputlong first as `r` does NOT consists of only 0s and +"").matches("[01]+"););1s   r+=n; //  And check thatIncrease `r` does then NOT consists of only 0sby andthe 1sinput return r;} // After the loop is done, return `r` as result 

This method above only works for binary outputs \$\leq1111111111\$. The int r=0; can be changed to var r=0L; (+1 byte) to increase this to a maximum of \$\leq1111111111111111111\$. Alternatively, it can be changed to the following forFor arbitrary large outputs - given enough time and resources - the following can be used instead (99 7070 64 bytes) - given enough time and resources:

n->{var r=n.ZERO;forr=n;for(;!((r=r.add(n))+""r+"").matches("[01]+");)r=r.add(n);return r;} 

Try it online.Try it online.

#Java 10, 62 59 bytes

n->{int r=0;for(;!((r+=n)+"").matches("[01]+"););return r;} 

Try it online.

Explanation:

n->{ // Method with integer as both parameter and return-type int r=0; // Result-integer, starting at 0 for(; // Continue looping as long as the following is true:  !((r+=n) // Increase `r` by the input first  +"").matches("[01]+"););   //  And check that `r` does then NOT consists of only 0s and 1s return r;} // After the loop is done, return `r` as result 

This method above only works for binary outputs \$\leq1111111111\$. The int r=0; can be changed to var r=0L; (+1 byte) to increase this to a maximum of \$\leq1111111111111111111\$. Alternatively, it can be changed to the following for arbitrary large outputs (99 70 bytes) - given enough time and resources:

n->{var r=n.ZERO;for(;!((r=r.add(n))+"").matches("[01]+"););return r;} 

Try it online.

#Java 10, 62 59 58 bytes

n->{var r=n;for(;!(r+"").matches("[01]+");)r+=n;return r;} 

Try it online.

Explanation:

n->{ // Method with long as both parameter and return-type var r=n; // Result-long, starting at the input for(;!(r+"").matches("[01]+");)  // Loop as long as `r` does NOT consists of only 0s and 1s r+=n; // Increase `r` by the input return r;} // After the loop is done, return `r` as result 

This method above only works for binary outputs \$\leq1111111111111111111\$. For arbitrary large outputs - given enough time and resources - the following can be used instead (99 70 64 bytes):

n->{var r=n;for(;!(r+"").matches("[01]+");)r=r.add(n);return r;} 

Try it online.

deleted 185 characters in body
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394

#Java 10, 6262 59 bytes

n->{int r=0;for(;++r%n>0|;!(r+""(r+=n)+"").matches("[01]+"););return r;} 

Try it online. (Skips test cases n=9 and n=18, since they take too long.)Try it online.

Explanation:

n->{ // Method with integer as both parameter and return-type int r=0; // Result-integer, starting at 0 for(; // Continue looping as long as the following is true:   ++r  !((r+=n) // Increase `r` by 1 first  %n>0 // Check that the input does NOT evenlyfirst  divide it  |!(r+""+"").matches("[01]+");); // OrAnd check that `r` does then NOT consists of only 0s and 1s return r;} // After the loop is done, return `r` as result 

This method above only works for binary outputs \$\leq1111111111\$. The int r=0; can be changed to var r=0L; (+1 byte) to increase this to a maximum of \$\leq1111111111111111111\$. Alternatively, it can be changed to the following for arbitrary large outputs (9999 70 bytes) - given enough time and resources:

n->{var r=n.ZERO;for(;!((r=r.add(n.ONE)).mod(n).equals(n.ZERO)|!(r+""+"").matches("[01]+"););return r;} 

Try it online.Try it online.

#Java 10, 62 bytes

n->{int r=0;for(;++r%n>0|!(r+"").matches("[01]+"););return r;} 

Try it online. (Skips test cases n=9 and n=18, since they take too long.)

Explanation:

n->{ // Method with integer as both parameter and return-type int r=0; // Result-integer, starting at 0 for(; // Continue looping as long as the following is true:   ++r  // Increase `r` by 1 first  %n>0 // Check that the input does NOT evenly divide it  |!(r+"").matches("[01]+");); // Or that `r` does NOT consists of only 0s and 1s return r;} // After the loop is done, return `r` as result 

This method above only works for binary outputs \$\leq1111111111\$. The int r=0; can be changed to var r=0L; (+1 byte) to increase this to a maximum of \$\leq1111111111111111111\$. Alternatively, it can be changed to the following for arbitrary large outputs (99 bytes) - given enough time and resources:

n->{var r=n.ZERO;for(;!(r=r.add(n.ONE)).mod(n).equals(n.ZERO)|!(r+"").matches("[01]+"););return r;} 

Try it online.

#Java 10, 62 59 bytes

n->{int r=0;for(;!((r+=n)+"").matches("[01]+"););return r;} 

Try it online.

Explanation:

n->{ // Method with integer as both parameter and return-type int r=0; // Result-integer, starting at 0 for(; // Continue looping as long as the following is true: !((r+=n) // Increase `r` by the input first  +"").matches("[01]+");); // And check that `r` does then NOT consists of only 0s and 1s return r;} // After the loop is done, return `r` as result 

This method above only works for binary outputs \$\leq1111111111\$. The int r=0; can be changed to var r=0L; (+1 byte) to increase this to a maximum of \$\leq1111111111111111111\$. Alternatively, it can be changed to the following for arbitrary large outputs (99 70 bytes) - given enough time and resources:

n->{var r=n.ZERO;for(;!((r=r.add(n))+"").matches("[01]+"););return r;} 

Try it online.

Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394
Loading