Skip to main content
added 690 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

R, 270 265 252 243 232 227227 225 bytes

Edit:I finally managed to remove 2 more characters to bring the total to a number that can be represented in triangular form -9 bytes thanks(as shown here). Code should be formatted conventionally to Giuseppebe run (as in the example on TIO); the '•' represents a newline (\n) character.

function              f
             unc
            tion(
           s,`~`=cbind`~`=c
          bind,m=matrixm=ma
         trix){n=ncharn=nch
        ar(s)+1
p=m+1;p=m(,
       n^2,2)
while;while(T<nT<
      n){a=4*F
p[T+0a=4*F;p[T+0:a,
     ]=c(F:-F,(-F:F)[-1]
    )~0:a-2*F
p[T+a+2*F;p[T+a+-2:a+3a+
   3,]=(F=F+1)~(b=2*F-1):-b
T=T+2*a+4  b;T=T+2*a+4}
m=m;m=m(" ",n,n)
m[p[2 ;m[p[2:n-1,]+b+1]=el(strsplitstrspl
it(s,''))
n=apply;apply(m,1,cat,"
""•")}

Try it online!Try it online!

Note that this approach has been comprehensively outgolfed by att's approach, although as consolation neither that nor any of the other current answers can be represented as a triangle...

R, 270 265 252 243 232 227 bytes

Edit: -9 bytes thanks to Giuseppe

function(s,`~`=cbind,m=matrix){n=nchar(s)+1
p=m(,n^2,2)
while(T<n){a=4*F
p[T+0:a,]=c(F:-F,(-F:F)[-1])~0:a-2*F
p[T+a+-2:a+3,]=(F=F+1)~(b=2*F-1):-b
T=T+2*a+4}
m=m(" ",n,n)
m[p[2:n-1,]+b+1]=el(strsplit(s,''))
n=apply(m,1,cat,"
")}

Try it online!

R, 270 265 252 243 232 227 225 bytes

I finally managed to remove 2 more characters to bring the total to a number that can be represented in triangular form (as shown here). Code should be formatted conventionally to be run (as in the example on TIO); the '•' represents a newline (\n) character.

              f
             unc
            tion(
           s,`~`=c
          bind,m=ma
         trix){n=nch
        ar(s)+1;p=m(,
       n^2,2);while(T<
      n){a=4*F;p[T+0:a,
     ]=c(F:-F,(-F:F)[-1]
    )~0:a-2*F;p[T+a+-2:a+
   3,]=(F=F+1)~(b=2*F-1):-
  b;T=T+2*a+4};m=m(" ",n,n)
 ;m[p[2:n-1,]+b+1]=el(strspl
it(s,''));apply(m,1,cat,"•")}

Try it online!

Note that this approach has been comprehensively outgolfed by att's approach, although as consolation neither that nor any of the other current answers can be represented as a triangle...

deleted 10 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

R, 270 265 252 243 232232 227 bytes

function(s,`~`=cbind,m=matrix){n=nchar(s)+1
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~]=(F=F+1)~(b=2*F-1):-b
T=T+2*a+4}
p=p[2:n-1,]+b+1
m=m(" ",n,n)
m[p]=elm[p[2:n-1,]+b+1]=el(strsplit(s,''))
n=apply(m,1,cat,"
")}

Try it online!Try it online!

R, 270 265 252 243 232 bytes

function(s,`~`=cbind,m=matrix){n=nchar(s)+1
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[2:n-1,]+b+1
m=m(" ",n,n)
m[p]=el(strsplit(s,''))
n=apply(m,1,cat,"
")}

Try it online!

R, 270 265 252 243 232 227 bytes

function(s,`~`=cbind,m=matrix){n=nchar(s)+1
p=m(,n^2,2)
while(T<n){a=4*F
p[T+0:a,]=c(F:-F,(-F:F)[-1])~0:a-2*F
p[T+a+-2:a+3,]=(F=F+1)~(b=2*F-1):-b
T=T+2*a+4}
m=m(" ",n,n)
m[p[2:n-1,]+b+1]=el(strsplit(s,''))
n=apply(m,1,cat,"
")}

Try it online!

edited body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

R, 270 265 252 243 234232 bytes

function(s,`~`=cbind,m=matrix){n=nchar(s)+1
p=m(0,n^2,2)
while(T<=nT<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[1p=p[2:n,]-min(p)+11,]+b+1
m=m(" ",n,n)
m[p]=el(strsplit(s,''))
n=apply(m,1,cat,"
")}

Try it online!Try it online!

R, 270 265 252 243 234 bytes

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!

R, 270 265 252 243 232 bytes

function(s,`~`=cbind,m=matrix){n=nchar(s)+1
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[2:n-1,]+b+1
m=m(" ",n,n)
m[p]=el(strsplit(s,''))
n=apply(m,1,cat,"
")}

Try it online!

deleted 7 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60
Loading
added 3 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60
Loading
added 34 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60
Loading
deleted 25 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60
Loading
added 3 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60
Loading
added 12 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60
Loading
added 10 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60
Loading
added 1577 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60
Loading
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60
Loading