# [J], 60 bytes 4 :'x(<"1(#x)++/\(3|4|>.2*%:i.#x){<:3 3#:3 2 8)}y',~' '"0/,~ [Try it online!][TIO-kemg0feg] [J]: http://jsoftware.com/ [TIO-kemg0feg]: https://tio.run/##ndJbT8IwFADg9/2K4zbTDUq3bqi4AAmgiIqoeMFbQhQ2Lk6GyIQJ7q/PKmQmMhKwD01z2n4956TdQAUDVE4F27SGHIVBp9UegtvntPmy6Yx6nMzxBJAFGQMQhp8rkCBQqJaLQRIMNJbSPJWEsRyPKw@SPk1Os0SLbRodwmKTtKGDLrBJg5T86SHsI0C8qmA/gEqeAKczwpsRXgTh/SUkTdBiLCxOiCp6iPufglgW32n42A@N9Yu5N2bFMGXBSPA0TRR5FQbmyjqGCnWK6xQoNtgUofx2ZJniLSphWyIauy4j@pooLDrghvs0niWKmyGr04j9RrPRdsACVDJt24GaM7CbG2gWRQk2UHji8anRNK1Wu9N9tl96Tv918DZ030dj7yOXL@ztFw9Kh0fH5ZPK6dl59eLy6rp2c3unUk1Pbm3vpHYjTYxy0W/l8sviBRR8AQ "J – Try It Online" Obligatory J answer because it's Jonah's challenge. Because "replace a certain position inside an array with a value" is not a verb but an adverb, it can't be used in a train as-is, so it is wrapped inside an explicit inline verb. ### How it works ``` NB. input: a string (character vector) of length n ,~' '"0/,~ NB. create a large enough canvas (blank matrix of size 2n*2n) ,~ NB. concatenate two copies of self / NB. outer product by... ' '"0 NB. a constant function that returns blank per character ,~ NB. concatenate two copies of self 4 :'...' NB. a dyadic explicit verb, where x is the input string and NB. y is the canvas generated above x(...)}y NB. replace some places of y by contents of x... 3|4|>.2*%:i.#x NB. formula by att (gives 0, 1, or 2 per index) (...){ NB. select the directions based on the above... <:3 3#:3 2 8 NB. the matrix (0 -1)(-1 1)(1 1) i.e. L/RU/RD (#x)++/\ NB. take cumulative sum (giving coords to place each char) NB. and add n to all elements <"1 NB. enclose each row to satisfy the input format of } ```