Skip to main content
added 334 characters in body
Source Link
Robin Ryder
  • 15.8k
  • 2
  • 25
  • 71

R, 50 4038 bytes

-4 bytes thanks to Giuseppe.

k=scangrep();while"^[01]+$",(greplk=scan("[2-9]",F<-F+k))0;F*1:10^k)[1]*k 

Try it online!Try it online!

TheIt follows from while statement goes through all multiplesthis blog post (linked in the question) that the smallest binary multiple of k and searches for any digits greater\$k\$ is smaller than 1\$2\cdot10^{k-1}\$; this answer uses the larger bound \$k\cdot10^k\$ instead. The advantage

Creates a vector of usingall multiples of grepl\$k\$ between (over\$k\$ and utf8ToInt or\$k\cdot10^k\$. The regexp gives the indices of those made only of 0s and 1s; select the first index and multiply by strsplit) is that it accepts integer\$k\$ to get the answer.

Will time out on TIO for input and convertsgreater than 8, but with infinite memory it to stringwould work for any input.

R, 50 40 bytes

-4 bytes thanks to Giuseppe.

k=scan();while(grepl("[2-9]",F<-F+k))0;F 

Try it online!

The while statement goes through all multiples of k and searches for any digits greater than 1. The advantage of using grepl (over utf8ToInt or strsplit) is that it accepts integer input and converts it to string.

R, 50 38 bytes

-4 bytes thanks to Giuseppe.

grep("^[01]+$",(k=scan())*1:10^k)[1]*k 

Try it online!

It follows from this blog post (linked in the question) that the smallest binary multiple of \$k\$ is smaller than \$2\cdot10^{k-1}\$; this answer uses the larger bound \$k\cdot10^k\$ instead.

Creates a vector of all multiples of \$k\$ between \$k\$ and \$k\cdot10^k\$. The regexp gives the indices of those made only of 0s and 1s; select the first index and multiply by \$k\$ to get the answer.

Will time out on TIO for input greater than 8, but with infinite memory it would work for any input.

added 20 characters in body
Source Link
Robin Ryder
  • 15.8k
  • 2
  • 25
  • 71

R, 50 4440 bytes

-4 bytes thanks to Giuseppe.

k=scan();while(sum(grepgrepl("[2-9]",F<-F+k)))0;F 

Try it online!Try it online!

The while statement goes through all multiples of k and searches for any digits greater than 1. The sum is necessary as when there is no match, grep outputs an empty vector; sum transforms this to 0. The advantage of using grepgrepl (over utf8ToInt or strsplit) is that it accepts integer input and converts it to string.

R, 50 44 bytes

k=scan();while(sum(grep("[2-9]",F<-F+k)))0;F 

Try it online!

The while statement goes through all multiples of k and searches for any digits greater than 1. The sum is necessary as when there is no match, grep outputs an empty vector; sum transforms this to 0. The advantage of using grep (over utf8ToInt or strsplit) is that it accepts integer input and converts it to string.

R, 50 40 bytes

-4 bytes thanks to Giuseppe.

k=scan();while(grepl("[2-9]",F<-F+k))0;F 

Try it online!

The while statement goes through all multiples of k and searches for any digits greater than 1. The advantage of using grepl (over utf8ToInt or strsplit) is that it accepts integer input and converts it to string.

deleted 58 characters in body
Source Link
Robin Ryder
  • 15.8k
  • 2
  • 25
  • 71

R, 5050 44 bytes

k=scan();while(any(utf8ToIntsum(cgrep("[2-9]",F<-F+k,""))>49))0;F 

Try it online!

Recall that the ASCII codepoints of 0 and 1 are 48 and 49.Try it online!

The while statement goes through all multiples of k, converting each to character with c(…,"") and checking whether any codepoints are greater than 49, i.e. whether theresearches for any digits greater than 1. The sum is necessary as when there is no match, grep outputs an empty vector; sum transforms this to 0. The advantage of using grep (over utf8ToInt or strsplit) is that it accepts integer input and converts it to string.

R, 50 bytes

k=scan();while(any(utf8ToInt(c(F<-F+k,""))>49))0;F 

Try it online!

Recall that the ASCII codepoints of 0 and 1 are 48 and 49.

The while statement goes through all multiples of k, converting each to character with c(…,"") and checking whether any codepoints are greater than 49, i.e. whether there any digits greater than 1.

R, 50 44 bytes

k=scan();while(sum(grep("[2-9]",F<-F+k)))0;F 

Try it online!

The while statement goes through all multiples of k and searches for any digits greater than 1. The sum is necessary as when there is no match, grep outputs an empty vector; sum transforms this to 0. The advantage of using grep (over utf8ToInt or strsplit) is that it accepts integer input and converts it to string.

use same notation as question
Source Link
Robin Ryder
  • 15.8k
  • 2
  • 25
  • 71
Loading
added 58 characters in body
Source Link
Robin Ryder
  • 15.8k
  • 2
  • 25
  • 71
Loading
Source Link
Robin Ryder
  • 15.8k
  • 2
  • 25
  • 71
Loading