| Bytes | Lang | Time | Link |
|---|---|---|---|
| 192 | Haskell | 241003T175243Z | Antonio |
| 152 | Perl 5 | 241002T151123Z | Kjetil S |
| 025 | Charcoal | 240929T211400Z | Neil |
| 105 | JavaScript Node.js | 240930T063843Z | l4m2 |
| 027 | Jelly | 240929T210108Z | Unrelate |
| 142 | Python 3.8 prerelease | 240929T212142Z | squarero |
Haskell, 210,196,193,192 bytes
unlines.g
g s|l<-div(length s)2,k<-div l 2=1&s>>i[s!!l](2*l+1)l:zipWith((.(' ':)).(++))(k&map(i"/"l.(l-))[1..]++g(l&s))(k&map(i"\\"l)[0..]++g(drop(l+1)s))
(&)=take
i[c]n p=n&(p&w++c:w)
w=' ':w
-3 bytes thanks to Unrelated String
Perl 5, 152 bytes
sub{map$p=$_||$p=~s| /|/ |gr=~s|\\ ?| \\|gr=~s| \w ?|/ \\|gr,map{$"x($n/2).join($"x$n,@_[grep$_+1==($_^$n),0..$#_]),(0)x(($n>>=1)/2)}0..1.44*log($n=@_)}
Charcoal, 25 bytes
F²FLθ«Jκ⁻¹&⊕κ±⊕κ¿ι§θκP^±ⅉ
Try it online! Link is to verbose version of code. Explanation:
F²
Loop twice.
FLθ«
Loop over each input character index.
Jκ⁻¹&⊕κ±⊕κ
Jump to that character's position.
¿ι
On the second pass, ...
§θκ
... output the character.
P^⁻¹ⅉ
On the first pass, draw / and \ diagonals down to the bottom line.
Due to a bug in Charcoal, replacing ⁻¹ with ± results in an extra trailing line of spaces. This bug also then prevents me from drawing the entire diagram one column to the right, otherwise for 17 bytes:
→FS«Jⅈ±&ⅈ±ⅈP^±⊘ⅉι
Try it online! Link is to verbose version of code. Explanation:
→
Start with the first character in column 1.
FS«
Loop over each input character.
Jⅈ±&ⅈ±ⅈ
Jump to that character's position.
P^±⊘ⅉ
Draw / and \ diagonals halfway to the bottom (without moving the cursor).
ι
Output the current character.
(I do have an experimental branch where this version should print correctly with no padding.)
JavaScript (Node.js), 105 bytes
s=>(g=i=>s[i++*2]?g(i)+s.map(c=>(++j&-j)^i?(x=j&g-1)-i?x+i^g?' ':'\\':'/':(g=2*i,c),j=0).join``+`
`:'')``
Actually I don't understand ...
Jelly, 31 28 27 bytes
Jm2BỊḄJ=&ɗⱮJḤṚ|Ɗị"Ø^;;⁶Ʋ€UZ
Yikes... Still feels a little golfable, but it might just be the wrong approach entirely. It seems tantalizingly simple with certain praclang tools, but with so much to juggle, it comes out suprisingly clunky in Jelly!
Returns a list of lines.
Jm2BỊḄJ=&ɗⱮJḤṚ|Ɗ Build the tree:
Jm2 For every [1, 3 .. length],
B take its arbitrary-length binary representation
Ḅ and convert back from binary
Ị with all bits set to 1.
Jm2BỊḄ This creates a bitmask for the period of that column.
ɗⱮJ For each [1 .. length],
=& is its bitwise AND with each mask equal to
J the 1-index of that mask?
ḤṚ Double and reverse the comparisons
|Ɗ and bitwise OR with the original comparisons.
ị"Ø^;;⁶Ʋ€UZ Format the tree:
ị Modular 1-index each row into
" Ʋ€ the corresponding character
Ø^; appended to "/\"
;⁶ with a space appended.
U Reverse each row
Z and transpose.
Python 3.8 (pre-release), 158 144 143 142 bytes
-14 bytes by Unrelated String.
-2 bytes by emanresu A.
t=lambda s:(r:=len(s)//2)and[l.center(r-~r)for l in[s[r]]+[f'/{" "*i}\\'for i in range(1,r,2)]]+[*map(' '.join,zip(t(s[:r]),t(s[r+1:])))]or[s]