Skip to main content
added 10 characters in body
Source Link
J.Doe
  • 2.6k
  • 11
  • 15

R, 83/7572 bytes

Alt approach using regexps

If we're allowed a trailing newline, 7572 bytes:

function(s,n)cat(gsub("([^\n]*\n[^
]*
)",r,gsub("([^\n][^
])",r<-strrep("\\1",n),s)))

Try it online!Try it online!

Otherwise, 83 bytes:

function(s,n)write(rep(el(strsplit(gsub("([^\n])",strrep("\\1",n),s),"\n")),e=n),1)

Try it online!

R, 83/75 bytes

Alt approach using regexps

If we're allowed a trailing newline, 75 bytes:

function(s,n)cat(gsub("([^\n]*\n)",r,gsub("([^\n])",r<-strrep("\\1",n),s)))

Try it online!

Otherwise, 83 bytes:

function(s,n)write(rep(el(strsplit(gsub("([^\n])",strrep("\\1",n),s),"\n")),e=n),1)

Try it online!

R, 83/72 bytes

Alt approach using regexps

If we're allowed a trailing newline, 72 bytes:

function(s,n)cat(gsub("([^
]*
)",r,gsub("([^
])",r<-strrep("\\1",n),s)))

Try it online!

Otherwise, 83 bytes:

function(s,n)write(rep(el(strsplit(gsub("([^\n])",strrep("\\1",n),s),"\n")),e=n),1)

Try it online!

deleted 7 characters in body
Source Link
J.Doe
  • 2.6k
  • 11
  • 15

R, 83 7583/75 bytes

Alt approach using regexps

If we're allowed a trailing newline, 75 bytes:

function(s,n)cat(gsub("([^\n]*\n)",r,gsub("([^\n])",r<-strrep("\\1",n),s)))

Try it online!

Otherwise, 83 bytes:

function(s,n)write(rep(el(strsplit(gsub("([^\n])",strrep("\\1",n),s),"\n")),e=n),1)

Try it online!

R, 83 75 bytes

Alt approach using regexps

If we're allowed a trailing newline, 75 bytes:

function(s,n)cat(gsub("([^\n]*\n)",r,gsub("([^\n])",r<-strrep("\\1",n),s)))

Try it online!

Otherwise, 83 bytes:

function(s,n)write(rep(el(strsplit(gsub("([^\n])",strrep("\\1",n),s),"\n")),e=n),1)

Try it online!

R, 83/75 bytes

Alt approach using regexps

If we're allowed a trailing newline, 75 bytes:

function(s,n)cat(gsub("([^\n]*\n)",r,gsub("([^\n])",r<-strrep("\\1",n),s)))

Try it online!

Otherwise, 83 bytes:

function(s,n)write(rep(el(strsplit(gsub("([^\n])",strrep("\\1",n),s),"\n")),e=n),1)

Try it online!

added 436 characters in body
Source Link
J.Doe
  • 2.6k
  • 11
  • 15

R, 8383 75 bytes

Alt approach using regexps

If we're allowed a trailing newline, 75 bytes:

function(s,n)cat(gsub("([^\n]*\n)",r,gsub("([^\n])",r<-strrep("\\1",n),s)))

Try it online!

Otherwise, 83 bytes:

function(s,n)write(rep(el(strsplit(gsub("([^\n])",strrep("\\1",n),s),"\n")),e=n),1)

Try it online!

R, 83 bytes

Alt approach using regexps

function(s,n)write(rep(el(strsplit(gsub("([^\n])",strrep("\\1",n),s),"\n")),e=n),1)

Try it online!

R, 83 75 bytes

Alt approach using regexps

If we're allowed a trailing newline, 75 bytes:

function(s,n)cat(gsub("([^\n]*\n)",r,gsub("([^\n])",r<-strrep("\\1",n),s)))

Try it online!

Otherwise, 83 bytes:

function(s,n)write(rep(el(strsplit(gsub("([^\n])",strrep("\\1",n),s),"\n")),e=n),1)

Try it online!

Source Link
J.Doe
  • 2.6k
  • 11
  • 15
Loading