# [R], <s>270</s> <s>265</s> <s>252</s> <s>243</s> 234 bytes *Edit: -9 bytes thanks to Giuseppe* <!-- language-all: lang-r --> function(s,`~`=cbind,m=matrix){n=nchar(s) p=m(0,n^2,2) while(T<=n){a=4*F p[T+0:a,]=c(F:-F,(-F:F)[-1])~0:a-2*F F=F+1 p[T+a+-2:a+3,]=F~(b=2*F-1):-b T=T+2*a+4} p=p[1:n,]-min(p)+1 m=m(" ",n,n) m[p]=el(strsplit(s,'')) n=apply(m,1,cat," ")} [Try it online!][TIO-kelzn796] [R]: https://www.r-project.org/ [TIO-kelzn796]: https://tio.run/##PY/BboMwEETv/oqKS7zBrgLNCXWv/gJuiCrGIcEpXlwDTdIo/Dq1euj5vdHMhHUKVtO5b3E9zWQmOxAfxWE5oGksHYVDp6NygwchmU4HPgLz6PhO0EcucmDXzvYtL9@R4KFxv1XMV2W6K7So0XBVSCW4VIWCSmY1LBHIPEoKVZr9qTqVeaHTt@irhTcYqcygkA0rsUzzrU73z1jpq6wgUUtniXuI2TiNJy@JIEHAXOVrbHs@TmH0vZ3iic0GgBFq7/s7dyITRk8iYQk8/0/zZOrar9mazyYMVzoNt8vs/Dh8tyGCXv/cj8P5NYH1Fw "R – Try It Online" Works by constructing the coordinates for each letter, then using this to put the letters into an empty matrix. Commented: ``` triangle= function(s){n=nchar(s) # n is the number of letters s=el(strsplit(s,'')) # first split the string into individual letters p=matrix(,2,n^2) # initialize p as a 2-row matrix to hold the coordinates # (with plenty of columns so that we've enough to go all # the way round the outermost triangle) # now, F is the current loop, starting at 0 while(T<=n){ # T is the current letter index a=4*F+1 # a=the size of the 'arch' (number of letters going up & over) p[,T+1:a-1]= # set the coordinates for the arch letters... rbind( # ...(rbind combines rows for y & x coordinates)... c(F:-F,(-F:F)[-1]), # ...to y = F..-F, and then -F+1..F (so: up & then down again) 1:a-2*F-1) # ...and x = across the arch from -2*F to +2*F a=a+2 # a=now the width of the base = size of arch + 2 p[,T+a+1:a-3]= # now set the coordinates of the base letters... rbind( # F+1, # ... base y = row F+1 (b=2*F+1):-b) # ... and x = goes (backwards) from 2*F+1..-2*F-1 T=T+2*a-2 # update the current letter index F=F+1} # increment the loop p=p[,1:n] # delete any excess coordinates p=p-min(p)+1 # re-zero the coordinates to remove negatives m=matrix(" ",b<-max(p),b) # create a new matrix filled with " " m[t(p)]=s # and fill it with the letters at the right positions n=apply(m,1,cat," # finally, print each row ")} ```