Lay out the Carpet

R, 118 95 92 bytes

function(a,d,n=length(a),I=c(n:1,1:n)[-n])for(i in I-1)write(c(a,d)[pmin(I+i,n+1)],1,n*2,,d)

Try it online!

Thanks to:

  • Giuseppe for fixing an error and a golf
  • Aaron Hayman for 22 bytes worth of golf

J, 59 56 bytes

,{~[:((0-2*#)}.\[:,0,:"0({:>:t)*t=:]+/<:)[:(|[email protected]}.,])#\@]

Try it online!

Too long solution for J ... (entirely my fault)

R, an ugly 118 bytes version

By letting the input be a vector of single characters, and outputting a matrix instead of printing nice ascii art.


Try it online!

R, 161 157 bytes

saved 4 bytes by using ifelse instead of conditionally modifying y


Try it online!

ungolfed and commented

    y=abs(rep(1:L,k)-k)/2+abs(rep(1:k,e=L)-l)+1 # distance from centre
    y[!!y%%1]=l+1  # set non integers to one more than length of string
    y[y>l]=l+1     # set number beyond length of string to one more than length of string
    M = rbind(matrix(c(s,C)[y],L),'\n') # build matrix and add line returns
    cat(M,sep='') # print the matrix as a string

hmmm, seems like the longest answer so far!