Skip to main content
added 43 characters in body
Source Link
Dominic van Essen
  • 37.2k
  • 2
  • 24
  • 61

R, 22 bytes

\(x)rep(1,strtoi(x,2)) 

Attempt This Online!

Convert from binary and repeat 1 that many times.

Unfortunately shorter than the more-interesting (I think):

R, 3636 34 bytes

Edit: -2 bytes thanks to pajonk

\(x)Reduce(\(a,b)c(a,a,b[b]),x,NULL{}) 

Attempt This Online!Attempt This Online!

Input is a vector of binary digits; fold over (Reduce) this from the left, starting with an empty vector (NULL), at each step duplicating whatever we've got so far, and appending the new digit if it's a 1.

R, 22 bytes

\(x)rep(1,strtoi(x,2)) 

Attempt This Online!

Convert from binary and repeat 1 that many times.

Unfortunately shorter than the more-interesting (I think):

R, 36 bytes

\(x)Reduce(\(a,b)c(a,a,b[b]),x,NULL) 

Attempt This Online!

Input is a vector of binary digits; fold over (Reduce) this from the left, starting with an empty vector (NULL), at each step duplicating whatever we've got so far, and appending the new digit if it's a 1.

R, 22 bytes

\(x)rep(1,strtoi(x,2)) 

Attempt This Online!

Convert from binary and repeat 1 that many times.

Unfortunately shorter than the more-interesting (I think):

R, 36 34 bytes

Edit: -2 bytes thanks to pajonk

\(x)Reduce(\(a,b)c(a,a,b[b]),x,{}) 

Attempt This Online!

Input is a vector of binary digits; fold over (Reduce) this from the left, starting with an empty vector (NULL), at each step duplicating whatever we've got so far, and appending the new digit if it's a 1.

deleted 25 characters in body
Source Link
Dominic van Essen
  • 37.2k
  • 2
  • 24
  • 61

R, 3122 bytes

\(x)rep(1,x%*%2^(sumstrtoi(x|1):1-1x,2)) 

Attempt This Online!Attempt This Online!

Convert from binary and repeat 1 that many times.

Unfortunately shorter than the more-interesting (I think):

R, 36 bytes

\(x)Reduce(\(a,b)c(a,a,b[b]),x,NULL) 

Attempt This Online!

Input is a vector of binary digits; fold over (Reduce) this from the left, starting with an empty vector (NULL), at each step duplicating whatever we've got so far, and appending the new digit if it's a 1.

R, 31 bytes

\(x)rep(1,x%*%2^(sum(x|1):1-1)) 

Attempt This Online!

Convert from binary and repeat 1 that many times.

Unfortunately shorter than the more-interesting (I think):

R, 36 bytes

\(x)Reduce(\(a,b)c(a,a,b[b]),x,NULL) 

Attempt This Online!

Input is a vector of binary digits; fold over (Reduce) this from the left, starting with an empty vector (NULL), at each step duplicating whatever we've got so far, and appending the new digit if it's a 1.

R, 22 bytes

\(x)rep(1,strtoi(x,2)) 

Attempt This Online!

Convert from binary and repeat 1 that many times.

Unfortunately shorter than the more-interesting (I think):

R, 36 bytes

\(x)Reduce(\(a,b)c(a,a,b[b]),x,NULL) 

Attempt This Online!

Input is a vector of binary digits; fold over (Reduce) this from the left, starting with an empty vector (NULL), at each step duplicating whatever we've got so far, and appending the new digit if it's a 1.

added 381 characters in body
Source Link
Dominic van Essen
  • 37.2k
  • 2
  • 24
  • 61

R, 31 bytes

\(x)rep(1,x%*%2^(sum(x|1):1-1)) 

Attempt This Online!

Convert from binary and repeat 1 that many times.

Unfortunately shorter than the more-interesting (I think):

R, 36 bytes

\(x)Reduce(\(a,b)c(a,a,b[b]),x,NULL) 

Attempt This Online!

Input is a vector of binary digits; fold over (Reduce) this from the left, starting with an empty vector (NULL), at each step duplicating whatever we've got so far, and appending the new digit if it's a 1.

R, 36 bytes

\(x)Reduce(\(a,b)c(a,a,b[b]),x,NULL) 

Attempt This Online!

Input is a vector of binary digits; fold over (Reduce) this from the left, starting with an empty vector (NULL), at each step duplicating whatever we've got so far, and appending the new digit if it's a 1.

R, 31 bytes

\(x)rep(1,x%*%2^(sum(x|1):1-1)) 

Attempt This Online!

Convert from binary and repeat 1 that many times.

Unfortunately shorter than the more-interesting (I think):

R, 36 bytes

\(x)Reduce(\(a,b)c(a,a,b[b]),x,NULL) 

Attempt This Online!

Input is a vector of binary digits; fold over (Reduce) this from the left, starting with an empty vector (NULL), at each step duplicating whatever we've got so far, and appending the new digit if it's a 1.

Source Link
Dominic van Essen
  • 37.2k
  • 2
  • 24
  • 61
Loading