Skip to main content
6 of 7
added 11 characters in body
Zgarb
  • 43.2k
  • 4
  • 84
  • 265

Husk, 44 43 41 40 bytes

|s0Ψf¤|□ṁ`:'+f¹zμ+↓s²_&ε²¹↑□¹+"x^"s)¹m←ṡ 

Try it online!

This feels a bit clunky; Husk is not optimized for string manipulation. I'll try to golf it down. I borrowed some ideas from the Stax answer.

Zgarb
  • 43.2k
  • 4
  • 84
  • 265