Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 375 characters in body
Source Link
Giuseppe
  • 29.4k
  • 3
  • 33
  • 106

R, (削除) 82 (削除ここまで) 76(削除) 76 (削除ここまで) 75 bytes

function(s,n)cat(unlist(Map(rep,(S<-el(strsplit(s,""'')),c(n,rep(1,n-1))+!seq(S)),sep=""sep='')

Try it online! Try it online!

A function; takes a string s and an integer n, and prints the repeated version to stdout.

Explanation:

function(s,n){
 charsS <- el(strsplit(s,"")) # characters
 r <- c(n,rep(1,n-1)) # [n, 1, 1,...,1], length n
 repeatedrepeats <- Map(rep, chars, r) # Map computes repr+!seq(chars,rS) # recyclingextends theR shorterto aslength needed.of S
 cat(unlistrep(repeatedS, repeats),sep="") # print out
}

R , 55 bytes

function(S,n)cat(rep(S,c(n,rep(1,n-1))+!seq(S)),sep="")

Try it online!

Same algorithm as above, but with S taken as a list of individual characters.

R, (削除) 82 (削除ここまで) 76 bytes

function(s,n)cat(unlist(Map(rep,el(strsplit(s,"")),c(n,rep(1,n-1)))),sep="")

Try it online!

A function; takes a string s and an integer n, and prints the repeated version to stdout.

Explanation:

function(s,n){
 chars <- el(strsplit(s,"")) # characters
 r <- c(n,rep(1,n-1)) # [n, 1, 1,...,1], length n
 repeated <- Map(rep, chars, r) # Map computes rep(chars,r) # recycling the shorter as needed.
 cat(unlist(repeated),sep="") # print out
}

R, (削除) 82 (削除ここまで) (削除) 76 (削除ここまで) 75 bytes

function(s,n)cat(rep(S<-el(strsplit(s,'')),c(n,rep(1,n-1))+!seq(S)),sep='')

Try it online!

A function; takes a string s and an integer n, and prints the repeated version to stdout.

Explanation:

function(s,n){
 S <- el(strsplit(s,"")) # characters
 r <- c(n,rep(1,n-1)) # [n, 1, 1,...,1], length n
 repeats <- r+!seq(S) # extends R to length of S
 cat(rep(S, repeats),sep="") # print out
}

R , 55 bytes

function(S,n)cat(rep(S,c(n,rep(1,n-1))+!seq(S)),sep="")

Try it online!

Same algorithm as above, but with S taken as a list of individual characters.

added 405 characters in body
Source Link
Giuseppe
  • 29.4k
  • 3
  • 33
  • 106

R, 82(削除) 82 (削除ここまで) 76 bytes

function(s,n)cat(unlist(mapplyMap(rep,el(strsplit(scan(,"")s,"")),c(n<-scan()n,rep(1,n-1)))),sep="")

Try it online! Try it online!

Takes theA function; takes a strings and an integer n from stdin, and prints the repeated version to stdout.

Explanation:

function(s,n){
 chars <- el(strsplit(s,"")) # characters
 r <- c(n,rep(1,n-1)) # [n, 1, 1,...,1], length n
 repeated <- Map(rep, chars, r) # Map computes rep(chars,r)
 # recycling the shorter as needed.
 cat(unlist(repeated),sep="") # print out
}

R, 82 bytes

cat(unlist(mapply(rep,el(strsplit(scan(,""),"")),c(n<-scan(),rep(1,n-1)))),sep="")

Try it online!

Takes the string and n from stdin and prints the repeated version to stdout.

R, (削除) 82 (削除ここまで) 76 bytes

function(s,n)cat(unlist(Map(rep,el(strsplit(s,"")),c(n,rep(1,n-1)))),sep="")

Try it online!

A function; takes a strings and an integer n, and prints the repeated version to stdout.

Explanation:

function(s,n){
 chars <- el(strsplit(s,"")) # characters
 r <- c(n,rep(1,n-1)) # [n, 1, 1,...,1], length n
 repeated <- Map(rep, chars, r) # Map computes rep(chars,r)
 # recycling the shorter as needed.
 cat(unlist(repeated),sep="") # print out
}
Source Link
Giuseppe
  • 29.4k
  • 3
  • 33
  • 106

R, 82 bytes

cat(unlist(mapply(rep,el(strsplit(scan(,""),"")),c(n<-scan(),rep(1,n-1)))),sep="")

Try it online!

Takes the string and n from stdin and prints the repeated version to stdout.

AltStyle によって変換されたページ (->オリジナル) /