Skip to main content
deleted 38 characters in body
Source Link
user2390246
  • 1.5k
  • 7
  • 13

R, 121 106 90 bytes

function(s,a=strsplit)cat(rep(el(a(gsub("\\d","",s),"")),pmax(el(a(s,"\\D")),"1")),sep="") 

Try it online!

Saved 15 bytes by realising that rep() will coerce to numeric. Saved another 16 thanks to Giuseppe, mainly from the use of pmax to replace empty strings with 1

function(s) { x <- el(strsplit(s,"\\D")) # Split the string on anything that is not a digit... x <- pmax(x, "1")  # ... and replace any empty strings with 1. This gets us the numbers of repeats y <- gsub("\\d","",s)  # Remove all digits from the original string... y <- el(strsplit(y))  # ... and split into individual units. This gets us the symbols to repeat z <- rep(y, x)  # Carry outImplement the required numbers of repeats. x is coerced to numeric cat(z, sep = "")  # Print without separators } 

R, 121 106 90 bytes

function(s,a=strsplit)cat(rep(el(a(gsub("\\d","",s),"")),pmax(el(a(s,"\\D")),"1")),sep="") 

Try it online!

Saved 15 bytes by realising that rep() will coerce to numeric. Saved another 16 thanks to Giuseppe, mainly from the use of pmax to replace empty strings with 1

function(s) { x <- el(strsplit(s,"\\D")) # Split the string on anything that is not a digit... x <- pmax(x, "1")  # ... and replace any empty strings with 1. This gets us the numbers of repeats y <- gsub("\\d","",s)  # Remove all digits from the original string... y <- el(strsplit(y))  # ... and split into individual units. This gets us the symbols to repeat z <- rep(y, x)  # Carry out the required numbers of repeats. x is coerced to numeric cat(z, sep = "")  # Print without separators } 

R, 121 106 90 bytes

function(s,a=strsplit)cat(rep(el(a(gsub("\\d","",s),"")),pmax(el(a(s,"\\D")),"1")),sep="") 

Try it online!

Saved 15 bytes by realising that rep() will coerce to numeric. Saved another 16 thanks to Giuseppe, mainly from the use of pmax to replace empty strings with 1

function(s) { x <- el(strsplit(s,"\\D")) # Split the string on anything that is not a digit... x <- pmax(x, "1") # ... and replace any empty strings with 1. This gets us the numbers of repeats y <- gsub("\\d","",s) # Remove all digits from the original string... y <- el(strsplit(y)) # ... and split into individual units. This gets us the symbols to repeat z <- rep(y, x) # Implement the repeats. x is coerced to numeric cat(z, sep = "") # Print without separators } 
added 84 characters in body
Source Link
user2390246
  • 1.5k
  • 7
  • 13

R, 121 106106 90 bytes

function(s,a=strsplit,x=el(a(s,"[^\\d]",,T)))cat(rep(el(a(gsub("\\d","",s),"")),ifelsepmax(x==""el(a(s,1"\\D")),x"1")),sep="") 

Try it online!Try it online!

Saved 15 bytes by realising that rep() will coerce to numeric. Saved another 16 thanks to Giuseppe, mainly from the use of pmax to replace empty strings with 1

function(s) { x <- el(strsplit(s,"[^\\d]""\\D")) # Split the string on anything that is not a digit... x <- ifelsepmax(x=="", 1x, x"1")  # ... and replace any empty strings with 1. This gets us the numbers of repeats y <- gsub("\\d","",s) # Remove all digits from the original string... y <- el(strsplit(y)) # ... and split into individual units. This gets us the symbols to repeat z <- rep(y, x) # Carry out the required numbers of repeats. x is coerced to numeric cat(z, sep = "") # Print without separators } 

R, 121 106 bytes

function(s,a=strsplit,x=el(a(s,"[^\\d]",,T)))cat(rep(el(a(gsub("\\d","",s),"")),ifelse(x=="",1,x)),sep="") 

Try it online!

Saved 15 bytes by realising that rep() will coerce to numeric

function(s) { x <- el(strsplit(s,"[^\\d]")) # Split the string on anything that is not a digit... x <- ifelse(x=="", 1, x) # ... and replace any empty strings with 1. This gets us the numbers of repeats y <- gsub("\\d","",s) # Remove all digits from the original string... y <- el(strsplit(y)) # ... and split into individual units. This gets us the symbols to repeat z <- rep(y, x) # Carry out the required numbers of repeats. x is coerced to numeric cat(z, sep = "") # Print without separators } 

R, 121 106 90 bytes

function(s,a=strsplit)cat(rep(el(a(gsub("\\d","",s),"")),pmax(el(a(s,"\\D")),"1")),sep="") 

Try it online!

Saved 15 bytes by realising that rep() will coerce to numeric. Saved another 16 thanks to Giuseppe, mainly from the use of pmax to replace empty strings with 1

function(s) { x <- el(strsplit(s,"\\D")) # Split the string on anything that is not a digit... x <- pmax(x, "1")  # ... and replace any empty strings with 1. This gets us the numbers of repeats y <- gsub("\\d","",s) # Remove all digits from the original string... y <- el(strsplit(y)) # ... and split into individual units. This gets us the symbols to repeat z <- rep(y, x) # Carry out the required numbers of repeats. x is coerced to numeric cat(z, sep = "") # Print without separators } 
deleted 42 characters in body
Source Link
user2390246
  • 1.5k
  • 7
  • 13

R, 121121 106 bytes

function(s,a=strsplit,x=as.numeric(elx=el(a(s,"[^\\d]",,T))))cat(rep(el(a(gsub("\\d","",s),"")),ifelse(is.na(x)x=="",1,x)),sep="") 

Try it online!Try it online!

Saved 15 bytes by realising that rep() will coerce to numeric

function(s) { x <- el(strsplit(s,"[^\\d]") ) # Split the string on anything that is not a digit... x <- as.numeric(el(x)) # ...convert to numeric... x <- ifelse(is.na(x)x=="", 1, x)  # ... and replace NAany empty strings with 1. This gets us the numbers of repeats y <- gsub("\\d","",s) # Remove all digits from the original string... y <- el(strsplit(y)) # ... and split into individual units. This gets us the symbols to repeat z <- rep(y, x) # Carry out the required numbers of repeats. x is coerced to numeric cat(z, sep = "") # Print without separators } 

R, 121 bytes

function(s,a=strsplit,x=as.numeric(el(a(s,"[^\\d]",,T))))cat(rep(el(a(gsub("\\d","",s),"")),ifelse(is.na(x),1,x)),sep="") 

Try it online!

function(s) { x <- strsplit(s,"[^\\d]")  # Split the string on anything that is not a digit... x <- as.numeric(el(x)) # ...convert to numeric... x <- ifelse(is.na(x), 1, x) # ... and replace NA with 1. This gets us the numbers of repeats y <- gsub("\\d","",s) # Remove all digits from the original string... y <- el(strsplit(y)) # ... and split into individual units. This gets us the symbols to repeat z <- rep(y, x) # Carry out the required numbers of repeats cat(z, sep = "") # Print without separators } 

R, 121 106 bytes

function(s,a=strsplit,x=el(a(s,"[^\\d]",,T)))cat(rep(el(a(gsub("\\d","",s),"")),ifelse(x=="",1,x)),sep="") 

Try it online!

Saved 15 bytes by realising that rep() will coerce to numeric

function(s) { x <- el(strsplit(s,"[^\\d]")) # Split the string on anything that is not a digit... x <- ifelse(x=="", 1, x)  # ... and replace any empty strings with 1. This gets us the numbers of repeats y <- gsub("\\d","",s) # Remove all digits from the original string... y <- el(strsplit(y)) # ... and split into individual units. This gets us the symbols to repeat z <- rep(y, x) # Carry out the required numbers of repeats. x is coerced to numeric cat(z, sep = "") # Print without separators } 
Source Link
user2390246
  • 1.5k
  • 7
  • 13
Loading