[Question]
      [
## The Challenge
The challenge is simple: given an input list `a` and another list `b`, repeat `a` until it is longer than `b`.
As an example, call the repeated list `ra`. Then the following condition must hold true: `len(b) < len(ra) <= len(b) + len(a)`. That is, `a` must not be repeated more than is required.
## Sample Python Implementation
```
def repeat(a, b):
    ra = a.copy()
    while len(b) >= len(ra):
        ra += a
    return ra
```
[Try it online!](https://tio.run/##LcxLCoNAEIThtZ6il9OkCCSaJ5iLiIvWdFCQcWgmBE8/UXFXi6/@MMd@8kVKb/2QaVCJTkAtP/PMhCqSYzeF2XGe/fphVBrVu5bpVW3LZIWrPCx0uWj8mieTFGzw0e3F@oQzigZUl7jgihvueDTM6Q8 "Python 3 – Try It Online")
## Examples
```
[1,2,3], [2,4] -> [1,2,3]
[1,2,3], [2,3,4] -> [1,2,3,1,2,3]
[1,2,3], [18,26,43,86] -> [1,2,3,1,2,3]
[2,3,5], [1,2,3,4,5,6,7] -> [2,3,5,2,3,5,2,3,5]
[1,123], [1,12,123,1234] -> [1,123,1,123,1,123]
```
## Scoring
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), shortest answer in bytes wins. Have fun!

[Answer]
# [Python 3](https://docs.python.org/3/), 29 bytes
```
lambda x,y:len(y)//len(x)*x+x
```
[Try it online!](https://tio.run/##K6gsycjPM/7/PycxNyklUaFCp9IqJzVPo1JTXx9EV2hqVWhX/P8PAA "Python 3 – Try It Online")
[Answer]
# [Husk](https://github.com/barbuz/Husk), 6 bytes
```
*¹→¤÷L
```
[Try it online!](https://tio.run/##yygtzv7/X@vQzkdtkw4tObzd5////9GGOoZGxrEQGsQEYZNYAA "Husk – Try It Online")
```
   ¤     # combin: ¤ f g x y = f (g x) (g y)
     L   #    where g = length
    ÷    #    and f = integer divide
         # so ¤÷L calculates the (integer) ratio of input lengths;
   →     # then increment the result,
 *¹      # and repeat input 1 that many times
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal) `r`, 7 bytes
```
₅?Lḭ›ẋf
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyJyIiwiIiwi4oKFP0zhuK3igLrhuotmIiwiIiwiWzIsMyw1XVxuWzEsMiwzLDQsNSw2LDddIl0=)
**How it works:**
```
₅?Lḭ›ẋf
₅        # Push first list and its length
 ?Lḭ     # Integer-divide by length of second list
    ›    # Increment ^
     ẋ   # Repeat first list that many times
      f  # Flatten into a single list
```
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), ~~20~~ 18 bytes
```
{(A×⌈(⍴⍵,1)÷A←⍴⍺)⍴⍺}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///P@lR24RqDcfD0x/1dGg86t3yqHerjqHm4e2OQHEwd5cmhKr9/99QwUjBWCFJwRBImiiYKphxGQLZID4YcsHlLRSMzBRMjBUszLhAIqZgNSAWmATpMoKYY2gEZgKxCQA "APL (Dyalog Unicode) – Try It Online")
Thanks to [Adám](https://codegolf.stackexchange.com/users/43319/ad%c3%a1m) for golfing some bytes and helping me to fix errors in chat.
`⎕←,⍣2⍨'thanks'`
-2 thanks to [AZTECCO](https://codegolf.stackexchange.com/users/84844/aztecco) `⎕←'thanks'`
[Answer]
# [J](http://jsoftware.com/), ~~15~~ 14 bytes
*-1 byte thanks to [Jonah](https://codegolf.stackexchange.com/users/15469/jonah)'s very clever idea!*
```
];@;<.@%&##<@]
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/Y60drG30HFTVlJVtHGL/a3L5OekpxKrUKTvEahkCJbSBMmAxINvOCqTO2kEFqJIrNTkjX8FIwUQhTcEQSBvDBIyxC5miChrChc0UzIFSIJ7pfwA "J – Try It Online")
Takes input as `b f a`, if `f` is the name you assign the verb to.
## Explanation
```
];@;<.@%&##<@]
       %          divide
        &#        the lengths of the lists by each other
    <.@           and floor it;
           <@]    box b
          #       and repeat it that many times
]  ;              prepend b to this boxed array
 ;@               and raze the result, collapsing it into a single list
```
Instead of incrementing the division result, as I did in the first version below, we simply prepend the input list to the resulting tiled box list, which is equivalent.
## Old Answer
```
]$~#@]*1<.@+%&#
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6zkE6Pm7/Y1XqlB1itQxt9By0VdWU/2typSZn5CsYKZgo4ABpQGwIVGAMU2mMSy2aSkMLBSMzBRNjBQszQiqhppoqmCmYY6oESZrCVBoaAZExCJtgMxMojk0liDAlQSWYNEOo/A8A "J – Try It Online")
### Explanation
```
]$~#@]*1<.@+%&#
            %      divide
             &#    the lengths of the lists by each other
       1   +       increment
        <.@        and floor
      *            multiplied by
   #@]             length of a
]$~                and reshape a to be that length
```
Unfortunately, `#` doesn't work here, as it doesn't preserve the order. (`1 1 1 2 2 2 3 3 3 -: 3 # 1 2 3`.)
[Answer]
# Curry, ~~57~~ 42 bytes
This being my first Curry answer, I'm pretty certain its not quite optimal, but as it is our current lang of the month, I figured I'd give at least a half-hearted try at it.
```
l=length
a!b|l a>l b=a|1>0=a++a!drop(l a)b
```
Edit: [Try it online!](https://tio.run/##Sy4tKqrULUjMTi7@/z/HNic1L70kgytRMakmRyHRLkchyTaxxtDOwDZRWztRMaUov0ADKK6Z9D83MTNPwVYh2kjHWMc0VkFRIdpQB8Q20THVMdMx17GI/Q8A)
A bit longer than I'd like, my first idea involved the recursive return being `r(a++a)b`, but I realized that didn't work unless the correct number of repetitions was a power of two.
Edit -15 bytes from some good tips by [WheatWizard](https://codegolf.stackexchange.com/users/56656/wheat-wizard)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 6 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
gIg÷>и
```
Takes the input-lists in the order \$b,a\$.
[Try it online](https://tio.run/##yy9OTMpM/f8/3TP98Ha7Czv@/4820jHWMYnlijbUAbJiAQ) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfWWCS9H/9OL0w9vtLuz4r/M/OjraSMc4VifaUAdEx@oogAV0TFCFDC10jMx0TIx1LMzQJHTAqnVMdcx0zIFSIJ4pTMrQCIiMQRhiHJARGxsLAA).
**Explanation:**
```
g       # Push the length of the first (implicit) input-list `b`
 Ig     # Push the length of the second input-list `a`
   ÷    # Integer-divide the length by `b` by that of `a`
    >   # Increase it by 1
     и  # Repeat the second (implicit) input-list `a` that many times
        # (after which the result is output implicitly)
```
[Answer]
# Haskell + [hgl](https://gitlab.com/WheatWizard/haskell-golfing-library), 18 bytes
```
m**frt$P1<<fdv.*l
```
Divide the lengths, add 1 and then repeat that many times.
# Reflection
This is kind of long, but also pretty compact. Part of the issue is that variable reuse is always going to be a bit long. We also have to use both `frt` and `fdv` which are unfortunately 3 bytes each. It's totally possible to do this without flipping via `rt` and `dv`
```
m jn$rt<<P1<<dv.*l
```
But that ends up being a byte longer.
It seems mostly like a quirk of the specific problem that flipping is required.
The only real improvement I can see here is to combine some of the glue used to make things more compact.
* `m jn` used in the 19 byte solution could be 1 function. It has a useful type. If it were 3 bytes it would save 1 byte overall
```
mjn$rt<<P1<<dv.*l
```
* `l2 m` is a little more niche but could be added. As a 3 byte prefix it would actually have *costed* a byte here
```
l2m frt$P1<<fdv.*l
```
It could also be an infix, but that also costs a byte.
```
frt**<(P1<<fdv.*l)
```
However in better circumstances it could potentially save a byte.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 7 bytes
```
ẋɓL:L}‘
```
[Try it online!](https://tio.run/##y0rNyan8///hru6Tk32sfGofNcz4f3i5/tFJD3fO0Iz8/z862lDHSMc4Vkch2kjHJBZEI4sYY4gZWugYmemYGOtYmEFkQIpMwTI6YPU6pjpmOuYwXYZGEF1ABogNwkATAQ "Jelly – Try It Online")
Nothing all too original.
```
ẋ          Repeat a by
 ɓL        the length of b
   :L}     floor divided by the length of a
      ‘    plus 1.
```
[Answer]
# [Perl 5](https://www.perl.org/), 29 bytes
```
sub{(@{$a=shift})x(1+@_/@$a)}
```
[Try it online!](https://tio.run/##fZBNS8MwGMfP5lM8hGgbfET66liJ5i64y261jEaTOtS1thUmpZ@9Jt0ERVgO4f/2uzyNbt@SiRkxdZ9q8OXAStG9bE0/8r0fXMrNtWQlH6eMmLr1SQ725QGGGBUIeYhxAeL2J7Fdgf830Z8VntgGCwxTjCNcpKcJlyYzMQ9iTDDFmwMzd/jrP5J8II59//JZiUwh01xItsmOqazEBTOuk0zxQ9q0211v6PlV2llXLsEewwrlhLJC7xv91Otn57X1Vd1bWT3uKJIzajMK@gOorCjcgVe/erAE72G1htW9l5Fx@gY "Perl 5 – Try It Online")
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), ~~10~~ 9 bytes
```
*h/l.).Ql
```
[Try it online!](https://tio.run/##K6gsyfj/XytDP0dPUy8w5///aCMdYx3TWK5oQx0Qy0THVMdMxzwWAA "Pyth – Try It Online")
```
*h/l.).Ql
   l.).Q    # get the length of the second list
  /     l   # integer divide it by the length of the first list
 h          # increment the result of the division
*           # multiply by the first list (like int * list in Python)
```
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 18 bytes
```
{(~(#y)<#:)(x,)/x}
```
[Try it online!](https://ngn.codeberg.page/k#eJxtT0FugzAQvPsVK6UHLBksbONQXPUVuSFLQRQSFAopOBIoSt5e7NKEJj3seHZmNCuXydm7eqsRv60S7A0E0+GC0CY5v6TjtUtKCGBQ2/agvG2ZVbUa1Kg6rC9ok3ohMOCKgcDKUb0U+U2GRzOMgUkQHGL5HLFbNKsCIpCwxq4uggXObSGb2ia0xI476fgdNUIU7Y059gmleftR7Nq6DHqT5YdiyPdZsyuCvP2kX6eiN1Xb9JQJ/hrFtCuORWb8uuqNf2pMVft1O4U7hNKQMMI1pIwIDf47zMLS4H8s8hgIY8IkEZzE8r+Y5ZH+VQWJiCTrn6CzyAJdq/0ouNdSO7fzbr+jRt+7lHTR)
Appends copies of `x` until the length is greater than the length of `y`.
* `(cond)(code)/x` set up a while-reduce, beginning with `x`, the input. the "code" part is repeated until the "cond" part returns a non-truthy value
	+ `(~(#y)<#:)` check whether or not the current list is longer than `y`
	+ `(x,)` prepend a copy to the current list
An alternative version, with the same byte count, instead uses the do-reduce overload, swapping `(~(#y)<#:)` for `((-#x)!#y)`.
[Answer]
# [Desmos](https://desmos.com/calculator), ~~55~~ 49 bytes
```
f(a,b)=[lforl=a,i=[0...floor(b.length/a.length)]]
```
[Try It On Desmos!](https://www.desmos.com/calculator/b8wdtegkqi)
[Try It On Desmos! - Prettified](https://www.desmos.com/calculator/bemfawamsu)
~~I had to write `l=a[1...]` instead of just `l=a` because apparently Desmos defaults to recognizing function arguments as numbers, which the list comprehension doesn't like. The workaround is to force Desmos to recognize it as a list by slicing it in such a way that it just returns the entire list, resulting in +6 bytes.~~
Apparently the workaround wasn't even necessary because I *think* `a.length` forces Desmos to recognize `a` as a list, rather than a number. Thanks [@att](https://codegolf.stackexchange.com/users/81203/att) for helping me realize this.
[Answer]
# [Factor](https://factorcode.org/) + `sequences.repeating`, ~~45~~ 42 bytes
```
[ length over length tuck /i 1 + * cycle ]
```
[![enter image description here](https://i.stack.imgur.com/eODfW.gif)](https://i.stack.imgur.com/eODfW.gif)
## Explanation
```
          ! { 2 3 5 } { 1 2 3 4 5 6 7 }
length    ! { 2 3 5 } 7
over      ! { 2 3 5 } 7 { 2 3 5 }
length    ! { 2 3 5 } 7 3
tuck      ! { 2 3 5 } 3 7 3
/i        ! { 2 3 5 } 3 2
1         ! { 2 3 5 } 3 2 1
+         ! { 2 3 5 } 3 3
*         ! { 2 3 5 } 9
cycle     ! { 2 3 5 2 3 5 2 3 5 }
```
[Answer]
# [R](https://www.r-project.org), ~~33~~ 31 bytes
```
\(a,b,`-`=length)rep(a,1+-b/-a)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72waMGSNAUb3aWlJWm6FvtjNBJ1knQSdBNsc1Lz0ksyNItSC4BChtq6Sfq6iZoQVTfj0zSSNQx1jHSMNXWSNYx0TDQ1udCEjDEFDS10jMx0TIx1LMygUiBlpmApHbAOHVMdMx1zTag1CxZAaAA)
-2 bytes thanks to pajonk.
[Answer]
# JavaScript (ES6), 43 bytes
Expects `(a)(b)`. This code assumes that both lists are filled with positive integers (as allowed by the OP).
```
a=>g=(b,...c)=>c[b.length]?c:g(b,...c,...a)
```
[Try it online!](https://tio.run/##hctNDsIgEIbhvafoEpKRpoViY0I9CGFBkaINKcY2Xh8DNv4sTGfxbd55Rv3Qs7lfb8t@CmcbBxG16JxAPRBCDBadkT3xdnLLRZ3M0a0hjcbRhGkO3hIfHBqQrKAGqjCSNTCFcfG5sizWuvtv6K96G9iQVQs1B0ah5S@/JVNpssxPDBrgcEg2yVzha1V8Ag "JavaScript (Node.js) – Try It Online")
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), ~~11~~ 10 bytes
*-1 byte thanks to [Unrelated String](https://codegolf.stackexchange.com/users/85334/unrelated-string) in chat*
```
lᵐ÷<;?tᵗj₍
```
Takes input as a single list containing the two input lists in reverse order. [Try it online!](https://tio.run/##SypKTM6ozMlPN/r/P@fh1gmHt9tY25c83Do961FT7///0dGGOkY6xjomOqY6ZrE6ChBubOx/HwA "Brachylog – Try It Online")
### Explanation
Ports the common strategy of using int-division to calculate the rep-count:
```
lᵐ÷<;?tᵗj₍
lᵐ          Length of each list in the input
  ÷         Int-divide
   <        Next greater integer
    ;?      Pair with input
      tᵗ    Replace the last element with its tail (i.e. the second input list)
        j₍  Repeat the last element a number of times equal to the first element
```
For example, with input `[[1, 2, 3, 4, 5], [8, 9]]`:
```
lᵐ          [5, 2]
  ÷         2
   <        3
    ;?      [3, [[1, 2, 3, 4, 5], [8, 9]]]
      tᵗ    [3, [8, 9]]
        j₍  [8, 9, 8, 9, 8, 9]
```
### Old solution, 11 bytes
Implements the spec pretty directly, using Brachylog's backtracking:
```
hj↙İ.&tl<~l
h            The first of the inputs
 j           Concatenated to itself
  ↙İ         an unspecified number of times
    .        is the output
     &       And
      t      The second of the inputs
       l     Length of ^
        <    is less than a number
         ~l  which is the length of
             the output (implicit)
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 33 bytes
```
Table[##&@@#,Tr[1^#2]/Tr[1^#]+1]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b7PyQxKSc1WllZzcFBWSekKNowTtkoVh/CiNU2jFX7H1CUmVcSraxrlwZUEqtWF5ycmFdXzVVtqGOkY1xbU22kY1Krg8w1RhUwtNAxMtMxMdaxMAMJg@RNQcI6YJU6pjpmOuYQ9YZGYPVAGsQEYZNartr/AA "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [Mathematica/Wolfram Language](https://wolfram.com/language), (44) 41 Bytes
`PadLeft[#,Ceiling[Tr[1^#2]+1,Tr[1^#]],#]&`
*-3 bytes from alephalpha on something I really should have caught*
I feel like this could still be shorter, but it works as-is. Uses Tr[1^x] as a way of getting Length for cheap, and takes advantage of Ceiling having a two-argument mode. Other than that, it would probably take a full rewrite to improve, since I can't use [LeftCeiling] to shave bytes with the two-argument mode.
[Try It Online!](https://tio.run/##y00syUjNTSzJTE78n2b7PyAxxSc1rSRaWcc5NTMnMy89OqQo2jBO2ShW21AHwoyN1VGOVfufX1pimxZdbahjpGNcq1MNJHVMamO5Aooy80qigZKx/wE)
[Answer]
# [Exceptionally](https://github.com/dloscutoff/Esolangs/tree/master/Exceptionally), ~~25~~ 18 bytes
```
GV}lL}nGVL/nIU*lP/
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m702tSI5taAkMz8vMSencsGCpaUlaboWm9zDanN8avPcw3z08zxDtXIC9CESUPkF26MNdQyNjGO5wDSICcImsRBpAA)
### Explanation
```
' Get an input
G
' Eval it
V
' Store that in ls
} ls
' Get its length
L
' Store that in num
} num
' Get an input
G
' Eval it
V
' Get the length
L
' Divide by num
/ num
' Truncate to integer
I
' Increment
U
' Repeat ls that many times
* ls
' Print
P
' Attempt to divide the list by itself, ending the program
/
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~9~~ 8 bytes
```
Ｗ¬›ⅉＬηＩθ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/788IzMnVUHDL79Ew70oNbEktUgjUkNTR8EnNS@9JEMjQxMIFAKKMvNKNJwTi0s0CjU1rf//j4421DE0Mo7VAdMgJgibxMb@1y3LAQA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
Ｗ¬›ⅉＬη
```
Until the number of output lines exceeds the length of the second input...
```
Ｉθ
```
... output each element of the first input on its own line.
[Answer]
# [Ruby](https://www.ruby-lang.org/), 26 bytes
```
->x,y{x*(y.size/x.size+1)}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=bVBLToRAEI3bPkVlNg1MgeEzIzHDuHK2useOQQOxExRCwwQETuKGGL2ER_E0Ng2Oo3HR9arqvapKv5e3orprhtckeK_KxPQ_zG2NTVsbWmMJ_hyf1gqWtt5Pgs-TfRmLUkAAm83l1c4SecpLbXHztNCtxyhvu7oLazTqmaBgboHqrJ_IAjlmXSjhwNNpLt5HKdzaPY6JlskJEtrooMsgdNBj4565cUy4vyj8K7B9dNboueiv_5ON-Yp9dz1c4RrPJqGi8Ciqrbajtkoc0_Edzqv6JzIi3SFEmWXF0f0DtCC_Dxwh6whAXkkTtSQ0OIMggAwugF5HQlA4B7qLeEp1WAKVhYSCzPYPw4Rf)
[Answer]
# TI-Basic, 26 bytes
```
Prompt A,B
ʟA
While dim(Ans)≤dim(ʟB
augment(Ans,ʟA
End
Ans
```
Output is stored in `Ans` and displayed.
[Answer]
# [Julia 1.0](http://julialang.org/), 31 bytes
```
~=length
A%B=repeat(A,~B÷~A+1)
```
[Try it online!](https://tio.run/##yyrNyUw0rPj/v842JzUvvSSDy1HVybYotSA1sUTDUafO6fD2OkdtQ83/XA7FGfnlCtGGOkY6xrEKqgrRRjomsQq2tjAhbAqMUZTo4FJoaKFjZKZjYqxjYYZbOUjEFKIcLGuiY6pjpmMO0QCW1EEikWwxNILaAmSBOCAMdxaYjyBj/wMA "Julia 1.0 – Try It Online")
[Answer]
# APL+WIN, 18 bytes
Prompts for a nested vector comprising of list b followed by list a
```
∊(∊1+⌊÷/⍴¨v)⍴1↓v←⎕
```
[Try it online! Thanks to Dyalog APL Classic](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v@ob6qvz6O2CcZcQJanP5BlyPWooz3t/6OOLg0gNtR@1NN1eLv@o94th1aUaQIpw0dtk8uA6oDqgYrauf6ncWkYKZhoKmgYKhgpGGtygfnGaCKGFgpGZgomxgoWZqjiCmC1CqYKZgrmQBkQzxQqY2gERMYgDDELyNAEAA "APL (Dyalog Classic) – Try It Online")
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 61 bytes
```
(a,b)=>Array(~~(b.length/a.length)+1).fill``.map(_=>a).flat()
```
[Try it online!](https://tio.run/##hY3NCoJAEIDvPUXHWZo2dv1JiBV6DpEcTc3YdkUl6OKrb2odpQ4DHzMf39zpSX3RNe2wN/Zauko5IMyZis9dRy8YR8i5Lk093A70BbYTjFeN1lnGH9TCRcU0LTQNwNxpU1jTW11ybWuoIBEo0Utxm0j0U8Z@3b0/hohQhuh7GIVr3hwIFg@XFgYY4nG9KOSnOMHM8yy/3Rs "JavaScript (Node.js) – Try It Online")
Way longer than the other answers but who cares. Should work in the browser too but TIO only supports `Array.flat()` in Node.
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 34 bytes
```
{|@^a xx 1+@^b.elems div@^a.elems}
```
[Try it online!](https://tio.run/##bU7dCoIwFL73Kc5VKJ2CbbqEKHwPmWA0IVCIhFCqZ1/bUWnGLnZ2zvfHd9ePVppuhE0DJ/N6F1UNwwBsW1SXvW5118P19rTodHzMMerrEZo4ZshRJBhzTJMkgIogznLkElOBufRYp84ci@TDDCUeVm7GyW1/t7pH6aYki4LS1lCwO8MMRB4hVhT@C7xKIRl1Uws6d5uERKE3KdV2I7lXdcml@zfVFw "Perl 6 – Try It Online")
[Answer]
# [C (clang)](http://clang.llvm.org/), ~~62~~ 61 bytes
*-1 thanks to @ceilingcat*
```
f(*a,b,c,d){for(;b=++d%c;);for(;d--;)printf("%d ",a[b++%c]);}
```
[Try it online!](https://tio.run/##dY/LCoMwEEX3/YoiCEm9LvLSQvBLbBeZiKXQ2lK6E7/dRlPdiItZ3BPumYnP/cN1t3Fs2cmB4NHwvn19mKUqy5rUW27n2OS55e/Pvfu2LEmbYwJXU5al/srtMD7dvWO8P4TnoxP1teoFJNRgZ0IzkdAht8wJkICC5PawCC9dElKsy01dxrpaBBI0JbUjUBtBJGfIAlrhXESNAqlJuqPRy1azaPQqhoZBgTKKNEgHVu6ITKwJud6zkglO8/@YAZmg3140jD8 "C (clang) – Try It Online") Inputs are list `a`, list `b`, and their respective lengths in that order (as C doesn't store length information in arrays); outputs are sent to stdout.
[Answer]
# [BQN](https://mlochbaum.github.io/BQN/), 17 bytes
```
⊑⥊˜≠∘⊑×1+·⌊∘÷˜´≠¨
```
Anonymous tacit function that takes a single argument, a list containing the two input lists. [Try it at BQN online](https://mlochbaum.github.io/BQN/try.html#code=RyDihpAg4oqR4qWKy5ziiaDiiJjiipHDlzErwrfijIriiJjDt8ucwrTiiaDCqAoKRyDin6gy4oC/MywgMeKAvzLigL8z4oC/NOKAvzXin6kKCg==)
### Explanation
```
⊑⥊˜≠∘⊑×1+·⌊∘÷˜´≠¨
                ≠¨  Length of each list
               ´    Fold that two-integer list on
              ˜     Reversed-order
           ⌊∘÷      Division-and-floor
          ·         Then
        1+          Add 1
       ×            Multiply by
    ≠∘⊑             Length of the first list
 ⥊˜                Reshape to that length
⊑                  The first list
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 12 bytes
```
Ty#>b{Yy.a}y
```
[Try It Online!](https://dso.surge.sh/#@WyJwaXAiLCIiLCJUeSM+YntZeS5hfXkiLCIiLCIiLCJcIjFcIlwiMlwiXCIzXCIgXCIxXCJcIjJcIlwiM1wiXCI0XCIiXQ==)
How?
```
Ty#>b{Yy.a}y
T    {    }  - Till
 y#>b        - Length of y greater than length of b(2nd input)
      Y        - Yank (equivalent to (y:a))
       y.a     - y concatenated with a
           y - Return y
```
]


[Question]
      [
Your challenge is to write a program that constantly prompts for input, and when input is given, output that five seconds\* later. However, your program must continue prompting for input during that time.
Since this is a bit confusing, here's a demo.
```
<pre id=x></pre><input id=h onchange='var k=this;(()=>{let a=k.value;setTimeout(_=>document.getElementById("x").innerText+=a+"\n", 5000)})();this.value="";' >
```
(Try typing multiple things into the box and pressing enter.)
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), shortest wins!
\*Anywhere between four and six seconds is fine.
## Definition of "prompting for input"
I'm not really sure how to define "prompting for input" in a way that works across most languages, so here's a couple of ways you can do this:
* Prompt for input in a terminal, recieving it on pressing enter
* Open a dialog box that asks for input
* Record every keypress and output those delayed - see [this fiddle](https://jsfiddle.net/6zegdjfq/) thanks to tsh
If you're not sure, ask. Note that for the first two options, the operation must not block further output.

[Answer]
# JavaScript, ~~53~~ ~~51~~ 44 bytes
Now 44 bytes thanks to @DomHasting's suggestion to omit `window.`.
(Records every keypress; keyboard events won't register unless you focus on the opened iframe when you click run)
```
onkeyup=e=>setTimeout(console.log,5e3,e.key)
```
[Answer]
# Minecraft Command Blocks, ~895 bytes
[![enter image description here](https://i.stack.imgur.com/zBY3J.png)](https://i.stack.imgur.com/zBY3J.png)
[![enter image description here](https://i.stack.imgur.com/gZc3s.jpg)](https://i.stack.imgur.com/gZc3s.jpg)
My Java answer I already have on this question is pretty good, but as I do also have some skill with Minecraft redstone, I wondered if there was a decent way to do this in Minecraft, and it turns out there is. Because inputting data into Minecraft programs is never quite easy, but I was able to figure out a decent method for this: input is provided by placing a named Creeper mob in a specific location; output is much simpler, as it is simply read out to the game chat.
## Explanation
This "program" consists of two chains of command blocks, as follows:
```
chain 1:
Repeat block, Always active: data modify entity @e[type=minecraft:creeper,dx=2,dy=1,dz=0,limit=1,sort=nearest] PersistenceRequired set value 1
Chain block, Conditional: tp @e[type=minecraft:creeper,dx=3,dy=1,dz=0,limit=1,sort=nearest] ~1 ~222 ~-1
chain 2:
Impulse block, Needs Redstone: say @e[type=creeper,limit=1,sort=nearest]
Chain block, Unconditional: kill @e[type=creeper,limit=1,sort=nearest]
Chain block, Unconditional: kill @e[type=item]
```
Minecraft command block programs are mainly formed by chaining command blocks, where a start block (of either Impulse or Repeat type) can activate a Chain block its pointing at, and those Chain blocks can activate more Chain blocks, etc.
Chains can be started by either an Impulse or Repeat block, where Impulse blocks trigger once when activated, and then do not trigger again until they are de- and then re-activated, while Repeat blocks trigger every in-game tick while they are activated. both of these blocks can be in either "Always active" or "Needs Redstone" mode, where they are either, respectively, active all the time, or only active when powered by a Redstone signal. Chain blocks also have a conditional feature, where they can be set to only activate if the command of the block that triggered them executed successfully.
The first chain queues up the signal Creeper, with the Repeat block looking continuously for a nearby Creeper and trying to set its PersistenceRequired property to 1 (true). If it succeeds at this, the Conditional Chain block is triggered, which teleports the Creeper up 222 blocks, a distance which I calculated takes almost exactly 5 seconds for it to fall. The first command block is necessary as that property prevents it from despawning, as normally all mobs despawn instantly if they are more than 128 blocks from the player.
This teleport also lines it up so it falls into a tripwire, which provides the Redstone signal that triggers the start of the second chain, which writes the name of the Creeper to chat, kills the Creeper, and then destroys all the items the creeper dropped, as otherwise these would clog up the tripwire and prevent further messages from functioning. There is a pool of water placed under the tripwire to prevent the fall from killing the Creeper, as it needs to stay there long enough for the command block to read its name.
The sign indicates where the Creeper should go, although this positioning is not precise, and is mainly there to fulfill my interpretation of the "prompt for input" requirement.
## Byte Count Calculation and Golfing
Per [consensus](https://codegolf.meta.stackexchange.com/a/9529/111305), MC "program" bytecounts are calculated using the size of the structure block .nbt file needed to contain them, which I have uploaded to dropbox [here](https://www.dropbox.com/s/0fct2gsc6af837d/laggytext.nbt?dl=0), so that you can test it in your own world if you want.
Golfing with structure block files is irritating, as its often not clear what increases or decreases bytecount except through trial and error, and bytecount even seems to vary by a few bytes for identical structures. I have tried a few variations of commands, but the ones here seem to have the lowest bytecount. I have tried to fit the "program" into the smallest possible bounding box, and all air blocks in the program are replaced with structure void blocks. I had the sandstone floor as voids too, but that somehow seemed to be larger, so I returned it to sandstone, although it is possible some other block may reduce the file size. The iron block the tripwire is on can also be any block, as long as it supports the tripwire. The sign also seems to be contributing almost 100 bytes, so if it is judged to be unnecessary for the "prompting user" requirement, it would certainly shave off a good deal.
[Answer]
# [Bash](https://www.gnu.org/software/bash/), 37 bytes
Doesn't work online for obvious reasons!
[@Digital Trauma](https://codegolf.stackexchange.com/users/11259/digital-trauma) correctly pointed out an unnecessary spaces for -1, thanks!
```
while read a;do sleep 5&&echo $a&done
```
[Try it online!](https://tio.run/##S0oszvj/vzwjMydVoSg1MUUh0TolX6E4JzW1QMFUTS01OSNfQSVRLSU/L/X//5LU4hJDLhBpBCaNAQ "Bash – Try It Online")
[Answer]
# [Factor](https://factorcode.org/), 46 bytes
```
[ readln '[ _ print ] 5 seconds later t ] loop
```
Factor has a nice timer vocabulary. `later` Takes a quotation to perform and a duration and calls the quotation after the duration has passed. Since TIO is unsuited for displaying the functionality, here's an animated GIF of running this code in Factor's REPL:
[![enter image description here](https://i.stack.imgur.com/TEW1e.gif)](https://i.stack.imgur.com/TEW1e.gif)
[Answer]
# Java 8, 447 437 404 380 374 278 272 259 219 210 bytes
This is my first code golf, and I'm certain both that I could golf this down more, and that Java is a horrible language for this problem and for golfing in, but for my first try I think this isn't too bad. I tried to golf this in Python, which I'm more familiar with, first, but I simply couldn't get around the non-blocking input restriction in Python.
Edit: Screwing around a lot more I found a much shorter version using threads and waiting instead of my list+timestamp idea for the old one:
```
import java.util.*;class B{static void main(String[]a){Scanner s=new Scanner(System.in);for(;;){String t=s.nextLine();new Thread(()->{try{Thread.sleep(5000);}finally{System.out.println(t);return;}}).start();}}}
```
Edit: -6 bytes, I think I'm solidly addicted to code golfing now.
Edit 2: -13 bytes, realized I could put the whole thing in one class and it'd still work.
Edit 3: -41 bytes from @Clashsoft's excellent idea to use a lambda for the thread class instead.
Edit 4: Apparently the lambda actually means I don't need to extend `Thread` anymore, although I do now need `Thread.sleep()` instead of just `sleep()`
### Old Solution
```
import java.util.*;class A{long t;String s;A(long T,String S){t=T;s=S;}public static void main(String[]a)throws java.io.IOException{List<A>L=new ArrayList<>();Scanner s=new Scanner(System.in);for(;;){if(System.in.available()>0&&s.hasNext()){L.add(new A(System.nanoTime(),s.nextLine()));}if(L.size()>0&&L.get(0).t+5e9<System.nanoTime()){System.out.println(L.remove(0).s);}}}}
```
Edit: -10 bytes from trimming the "public" off Main class declaration and a bit of whitespace.
Edit 2: -33 bytes with a bit more trimming and a better import.
Edit 3: -18 bytes by using System.nanoTime() instead of System.currentTimeMillis(), and -6 by Seggan's suggestion to switch to an interface to drop the public modifier, for total of -24.
Edit 3.5: Pasted the wrong code for edit 3, now showing the correct code (I think, I don't have the actual code or an IDE on hand at the moment) with those changes.
Edit 4: @Neil's suggestion to put it all in one class let me save another six bytes, I think I'm getting close to how far this approach can be golfed in Java, but there could be something more I'm not seeing yet.
[Answer]
# [Rust](https://rust-lang.org), ~~180~~ 127 bytes
```
use std::{io::*,thread::*};fn main(){for s in stdin().lock().lines(){spawn(move||{sleep_ms(5000);println!("{}",s.unwrap())});}}
```
Runs an infinite loop, reads the string and spawns a new thread. After 5s of blocking that thread, it prints it back to the console.
```
use std::{io::*, thread::*};
fn main() {
    for s in stdin().lock().lines() {
        spawn(move || {
            sleep_ms(5000);
            println!("{}", s.unwrap())
        });
    }
}
```
Thanks to Xiretza and the community in #rust matrix server :)
## Old answer
```
use std::*;fn main(){let s=io::stdin();loop{let mut b=String::new();s.read_line(&mut b).unwrap();thread::spawn(move||{thread::sleep(time::Duration::from_secs(5));print!("{b}")});}}
```
Runs an infinite loop, reads the string and spawns a new thread. After 5s of blocking that thread, it prints it back to the console.
```
use std::*;
fn main() {
    let s = io::stdin();
    loop {
        let mut b = String::new();
        s.read_line(&mut b).unwrap();
        thread::spawn(move || {
            thread::sleep(time::Duration::from_secs(5));
            print!("{b}")
        });
    }
}
```
Sadly it's not possible to run such programs in [rust playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&code=use%20std%3A%3A*%3B%0Afn%20main()%20%7B%0A%20%20%20%20let%20s%20%3D%20io%3A%3Astdin()%3B%0A%20%20%20%20loop%20%7B%0A%20%20%20%20%20%20%20%20let%20mut%20b%20%3D%20String%3A%3Anew()%3B%0A%20%20%20%20%20%20%20%20s.read_line(%26mut%20b).unwrap()%3B%0A%20%20%20%20%20%20%20%20thread%3A%3Aspawn(move%20%7C%7C%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20thread%3A%3Asleep(time%3A%3ADuration%3A%3Afrom_secs(5))%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20print!(%22%7Bb%7D%22)%0A%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%7D%0A%7D%0A).
Not the best language for code-golf, I know, but just wanted to give it a shot. :)
[Answer]
# Python 63 bytes
```
from threading import*
while 1:Timer(5,print,[input()]).start()
```
Thanks AnttiP for showing me that [Timer](https://docs.python.org/3/library/threading.html#threading.Timer) can directly pass arguments to the callback itself, which cut the solution by 20 bytes.
Thomas Baruchel pointed out a valid criticism of the original recursive solution: that the program would crash after 1000 inputs because of Python's recursion limit. Luckily AnttiP's new design is even shorter without recursion.
[Answer]
## Batch, 63 bytes
```
@set/ps=
@start /b cmd /c"ping -n 6 0.0.0.0>nul&echo %s%"
@%0
```
Explanation: `start /b` runs a command in the background in the same console. `ping` is used for the five second delay between the first and last pings. Note that the string is echoed unquoted so that some shell metacharacters may cause the echo to fail.
[Answer]
# [QBasic](https://en.wikipedia.org/wiki/QBasic), 167 bytes
```
DIM d(999),o$(999)
DO
c$=INKEY$
IF""<>c$THEN o$(j)=c$:d(j)=TIMER+5+86400*(TIMER>=86395):j=(j+1)MOD 1E3
IF(INT(TIMER-d(i))=0)*d(i)THEN?o$(i);:d(i)=0:i=(i+1)MOD 1E3
LOOP
```
Runs as an infinite loop; outputs character-by-character. Don't run this unless you have a good way to kill the program. Here's a nicer version that quits when you press Escape:
```
DIM d(999),o$(999)
CLS
DO
c$=INKEY$
IF c$=CHR$(27)THEN END
IF""<>c$THEN o$(j)=c$:d(j)=TIMER+5+86400*(TIMER>=86395):j=(j+1)MOD 1E3
IF(INT(TIMER-d(i))=0)*d(i)THEN?o$(i);:d(i)=0:i=(i+1)MOD 1E3
LOOP
```
You can try it at [Archive.org](https://archive.org/details/msdos_qbasic_megapack).
### Approach
QBasic doesn't have any non-blocking sleep command or multithreading capabilities that I'm aware of, so we're going to go low-tech on this and use `TIMER`, which provides the (floating-point) number of seconds since midnight. When a key is pressed, we store it in the `o$` array, and we also store `TIMER + 5` at the same index in the `d` array. Then we check the first time in `d` to see if it has arrived yet; if so, we output the corresponding character.
Some complexity is added because:
* QBasic has fixed-size arrays rather than lists, so there aren't any pop or push operations. We have to track the index of the next insertion and the index of the next removal, and we have to wrap both around when they reach the size of the array.
* `TIMER` resets at midnight, which breaks the math unless we correct for it.
### Ungolfed
```
CONST ARRAYSIZE = 999
CONST TIMERMAX = 86400  ' Number of seconds in a day
DIM d(ARRAYSIZE)        ' Times at which to output characters
DIM o$(ARRAYSIZE)       ' Characters to output
i = 0                   ' Index of first meaningful entry in d and o$
j = 0                   ' Index just past last meaningful entry in d and o$
' Clear screen
CLS
' Loop forever
DO
  ' If a key is being pressed, store it in c$
  c$ = INKEY$
  ' If it is Esc, quit the program
  IF c$ = CHR$(27) THEN END
  ' For any other key...
  IF c$ <> "" THEN
    ' Store it in o$
    o$(j) = c$
    ' Store 5-seconds-in-the-future time in d
    d(j) = TIMER + 5
    ' Correct for midnight wraparound
    IF d(j) >= TIMERMAX THEN d(j) = d(j) - TIMERMAX
    ' Increment next-entry index
    j = j + 1
    ' Wrap index around if necessary
    IF j > ARRAYSIZE THEN j = 0
  END IF
  ' If we've reached the time for the first character in the array...
  IF d(i) > 0 AND TIMER - d(i) > 0 AND TIMER - d(i) < 1 THEN
    ' Print it without a newline
    PRINT o$(i);
    ' Zero out the time for that character
    d(i) = 0
    ' Increment first-entry index
    i = i + 1
    ' Wrap index around if necessary
    IF i > ARRAYSIZE THEN i = 0
  END IF
LOOP
```
[Answer]
# [Julia](https://julialang.org/), ~~53~~ 42 bytes
```
~_=(r=readline();~@async sleep(5)print(r))
```
[![Demonstration of laggy text editor in Julia](https://i.stack.imgur.com/T5FRx.gif)](https://i.stack.imgur.com/T5FRx.gif)
*-11 bytes thanks to @MarcMush*
Previous version that's perhaps easier to understand at a glance:
```
while 1>0
r=readline()
@async (sleep(5);print(r))
end
```
[Answer]
# C, ~~63~~ ~~62~~ 57 bytes
```
main(b){for(;;){gets(&b);if(fork()){sleep(5);puts(&b);}}}
```
[Try online!](https://tio.run/##LYq7DsMgDAB3f4Wnyh46NI@Jr0mQQ6xQiAJtBsS3U4ZOJ92dfTprW3svGmjlssWLjOHiJCd6rGx0o@4OYi7Ji5w0szk//1hrbe0FA4wwwQwiAnefE8pXAt6ad1zQx@Aw5Us7vB6CedeEMcgP)
Similar to [Amir reza Riahi's answer](https://codegolf.stackexchange.com/a/243654/111351) managed to remove `i` variable and used an 8 byte int buffer.
Shaved off a byte by declaring b as `int b`(instead of `int b[8]`) and by using `&` operator
-5 bytes: `b` is passed in to the main function instead of being declared.
[Answer]
# C, ~~83~~ ~~73~~ 69 bytes
```
main(){for(int i=0;;){char*b;gets(b);if(fork()){sleep(5);puts(b);}}}
```
[Try online!](https://tio.run/##JcpLCoAgEADQ/Zyi5UwQ9HM1dJiU0aQvWivx7Ba0fs80zphS9tkfSMmeAf1xV35qmSmZZQ61Zid3RE3sLX5hRaIUN5ELFfH1/JZzhlI66GGAERSICMAL)
The only problem is that the program should break by ctrl-c and is not terminated by the ctrl-d.
Thanks to Neil, I removed 10 bytes.
[Answer]
# HTML/CSS, 73 72 bytes
I wanted to try solving this without JavaScript, so I came up with this solution. To use it, open it in a browser, press tab, then enter, then start typing and submit a line by pressing enter again. Up to you to decide whether or not this user interaction disqualifies the answer.
```
<p contenteditable><style>p>:last-child{font:0 a}*{transition:5s steps(1
```
## Demo
Note that this demo has to close off the CSS for it to work as a code snippet - this is not necessary when opening the HTML by itself in a browser.
```
<p contenteditable><style>p>:last-child{font:0 a}*{transition:5s steps(1)}
```
## Explanation
The `contenteditable` tag makes it possible for the user to edit the DOM text directly. If you've never heard of it before, run `document.body.setAttribute("contenteditable", true)` on random sites and have fun! Since in this case a `<p>` tag is being edited, adding a newline creates a new `<div>` element for each line, which we can use to our advantage in the CSS.
A simplified version of the CSS is pretty self-explanatory:
```
div {
 font: initial; /* implied */
 transition: font 5s steps(1);
}
div:last-child {
 font: 0px Arial;
}
```
The only uncommon part here is the `steps(1)` setting for the transition, which makes the transition go straight from one state to another (instead of fading smoothly).
[Answer]
# TI-Basic (TI-84), ~~76~~ ~~128~~ ~~121~~ 120 [bytes](https://codegolf.meta.stackexchange.com/a/4764/98541)
```
1→X
1→Y
{0→A
Ans→B
While 1
startTmr→ʟB(X
getKey→ʟA(X
X+tanh(Ans→X
If 5≤checkTmr(ʟB(Y
Then
ʟA(Y
Disp sub("ABC.HDEFGMIJKLRNOPQWTSUV.XYZ",5int(Ans/10-4)+5fPart(Ans/5),1
IS>(Y,X
End
End
```
`ʟA` stores the pressed [keycodes](http://tibasicdev.wikidot.com/userinput#toc4), `ʟB` the time at which they were pressed, `X` is the length of the lists, and `Y` the index of the next letter to print. The precision is one second (precision of `startTmr`) so it should be between 4 and 6 seconds delay. `tanh` serves as a `sign` function since `getKey` is big enough (> 41 for letters)
there's no built-in to translate numbers to characters, hence the long line with all the letters (strange ordering to use mod 5 instead of mod 10). I'm pretty sure this can be further goffed by being clever. Outputing the keycodes instead would save 52 bytes (previous solution)
-1 byte: I believe this is the first time I successfully use [`IS>(`](http://tibasicdev.wikidot.com/is) in code golf, which only works because X is always greater than Y
[![Demo with laggy characters](https://i.stack.imgur.com/MgrzS.gif)](https://i.stack.imgur.com/MgrzS.gif)
[Answer]
# **Kotlin, 122 bytes**
```
import kotlinx.coroutines.*;suspend fun main()=coroutineScope{while(true){readLine()?.let{launch{delay(5000);print(it)}}}}
```
Also my first code-golf. Looking forward for tips and advices.
Explanation: main function is suspendable for non-blocking print. Infinite loop is running under CoroutineScope created with [coroutineScope()](https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/coroutine-scope.html) function. In infinite loop program constantly reads the prompt with standard function readLine(). Result of readLine() is used under scope function let() in newly created coroutine created with launch() builder, which delays printing for 5 seconds without blocking the next propmt
[Answer]
# [Bash](https://www.gnu.org/software/bash/), 34 bytes
```
f(){ read c;sleep 5&&echo $c&f;};f
```
[Try it online!](https://tio.run/##S0oszvj/P01Ds1qhKDUxRSHZujgnNbVAwVRNLTU5I19BJVktzbrWOu3//0SuJK5krhQA "Bash – Try It Online")
Pretty similar to [Dom Hasting's answer](https://codegolf.stackexchange.com/a/243625/17152), but managed to save 4 bytes by using a function instead of a loop.
Does *not* work correctly on TIO.
[Answer]
# [Seal](https://seallang.netlify.app/), 25 bytes
```
w(1){i=h#l;t{z(5);p(i);}}
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 32 bytes
```
loop{a=gets;fork{sleep 5;$><<a}}
```
Spawns child processes for each timer. They aren't terminated since the program is non-terminating anyways, so if this is ever run it should be followed with a `Process.waitall`.
No TIO link since TIO has static input.
`fork` is not supported on all OSes (most notably Windows), but [it is listed in Ruby documentation](https://ruby-doc.org/core-2.6.2/Process.html#method-c-fork). An alternative solution that works on all OSes is:
```
loop{a=gets;Thread.new(a){sleep 5;$><<_1}}
```
which is 42 characters instead.
[Answer]
# [Scratch](https://scratch.mit.edu/), 168 bytes
[Try it online!](https://scratch.mit.edu/projects/709395019/)
This takes advantage of a clone storing a variable's value at the time of the clone's creation. Alternatively, 11 blocks.
```
when gf clicked
delete all of[O v
forever
ask()and wait
set[t v]to(answer
create clone of[myself v
when I start as a clone
wait(5)seconds
add(t)to[O v
delete this clone
```
```
when gf clicked            Syntax
delete all of[O v          Clears the output
forever                    Loops code forever
ask()and wait              Prompts user input
set[t v]to(answer          Sets variable 't' to the input
create clone of[myself v   Creates clone
when I start as a clone    Syntax, also ends 'forever' loop
wait(5)seconds             Waits 5 seconds
add(t)to[O v               Adds to the output the value of 't' at the time of the clone's creation
delete this clone          Deletes itself to avoid the 300 clone limit
```
[Answer]
# TI-Basic (TI-89), 117 [bytes](https://codegolf.meta.stackexchange.com/a/4764/98541)
```
Prgm
 {}→g
 g→t
 xscl→x
 x→y
 Loop
  startTmr()→t[x]
  getKey()→g[x]
  x+min(xscl,g[x])→x
  If checkTmr(t[y])≥5 Then
   Disp char(g[y])
   y+xscl→y
  EndIf
 EndLoop
EndPrgm
```
Port of [my answer for the TI-84](https://codegolf.stackexchange.com/a/243743/98541). The TI-Basic of the TI-89 is much more advanced (it has the `char` command and much much more) but the [tokens](http://tibasicdev.wikidot.com/68k:tokenization) are often longer (a literal `1` is stored as 3 bytes, that's why we use `xscl` [2 bytes] instead)
[![demo](https://i.stack.imgur.com/JF3v5.gif)](https://i.stack.imgur.com/JF3v5.gif)
]


[Question]
      [
Given the signal level `L` in the range `0-4`. Your program should draw the following ASCII art.
When `L=0`:
```
               ....
               ....
          .... ....
          .... ....
     .... .... ....
     .... .... ....
.... .... .... ....
.... .... .... ....
.... .... .... ....
```
When `L=1`:
```
               ....
               ....
          .... ....
          .... ....
     .... .... ....
     .... .... ....
oooo .... .... ....
oooo .... .... ....
oooo .... .... ....
```
When `L=2`:
```
               ....
               ....
          .... ....
          .... ....
     oooo .... ....
     oooo .... ....
oooo oooo .... ....
oooo oooo .... ....
oooo oooo .... ....
```
And etc. You can change the characters `o` and `.` to others, it's up to you. Trailing spaces are allowed.
This is a code-golf challenge so the shortest solution wins.

[Answer]
# [J](http://jsoftware.com/), 47 46 bytes
```
' .o'{~[:|.@|:[:,/(4,&0@#"+3+2*i.4)#"+1+4{.$&1
```
[Try it online!](https://tio.run/##ldDBCsIwDAbg@57ip461XWu2bt3BgiAKnsSD1x3FoV72AB179VqEgogoBgKB8CUk98CID1g7cGjUcDGXhN3psA8cNHI/926izeR6pythdVFvFky1qilvZGUsjbKe8sIEmR23hBcUBVUi9WUpOk1zkp5WsLlx7@i5Sei60DLafLaaEinTqI9GV50n1vxpvl2EDL8ju5yvIwam4uMMGrSw4QE "J – Try It Online")
[Answer]
# APL+WIN, 48 bytes
Prompts for n
```
⊖⍉⊃((n↑m)⍴¨⊂⊂4⍴'0'),((-4-n←⎕)↑m←1+2×⍳4)⍴¨⊂⊂4⍴','
```
[Try it online! Thanks to Dyalog Classic](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v@ob6qvz6O2CcZcQJanP5BlyPWooz3t/6OuaY96Ox91NWto5D1qm5ir@ah3y6EVj7qagMgEyFY3UNfU0dDQNdEFSk8AatYEqQLp1zY6PP1R72YTDB066v@BRnP9T@My4FJXUOdK4zKE0kZQ2hhKm3ABAA "APL (Dyalog Classic) – Try It Online")
[Answer]
# [Python](https://www.python.org), 75 bytes
```
def f(n,j=4):print(*(" .o"[(i>=j)*~(n<i)]*4for i in b""));1/j;f(n,j-.5)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vwYKlpSVpuhY3vVNS0xTSNPJ0smxNNK0KijLzSjS0NJQU9PKVojUy7WyzNLXqNPJsMjVjtUzS8osUMhUy8xSSlBiZmFmUNDWtDfWzrMG6dfVMNaFG6oDU5YHUFSXmpadqmGpacSmUFFVaARVqcimkViSnFpRArYLqgTkHAA)
Finishes with an exception. The `b""` string contains the literal bytes `0x01` `0x02` `0x03` `0x04`, but they're invisible here.
Could probably be improved with some more tweaking.
## 76 bytes
```
def f(n,j=4):print(*(" .o"[(i>=j)*~(n<i)]*4for i in b""));j>0!=f(n,j-.5)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vwYKlpSVpuhY3fVJS0xTSNPJ0smxNNK0KijLzSjS0NJQU9PKVojUy7WyzNLXqNPJsMjVjtUzS8osUMhUy8xSSlBiZmFmUNDWts-wMFG3B2nX1TDUhZu4DqcsDqStKzEtP1TDVtAKq0LSGGA5VBHMAAA)
No error.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 17 bytes
```
4ɾ≥vS4ɾd›*¶+4*⁋↵§
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCI0yb7iiaV2UzTJvmTigLoqwrYrNCrigYvihrXCpyIsIiIsIjMiXQ==)
-3 thanks to Seggan.
```
4ɾ≥               # Create a map of ones and zeroes corresponding to the bar characters.
   vS             # Stringify those
     4ɾd›         # Create the range [3, 5, 7, 9]
         *        # And repeat each char of those
          ¶+      # Append a newline to each
            4*    # Repeat each four times
              ⁋↵  # Turn into a list of lines
                § # Rotate 90°
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 17 bytes
```
↑Ｅ⁴Ｅ⁴×§.o›Ｉθι⁺³⊗ι
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMMqtEBHwTexQMMEToVk5qYWaziWeOalpFZoKOnlK@kouBelJpakFmk4JxaXaBRq6ihkagKJgJzSYg1jHQWX/NKknNQUDaAgCFj//2/0X7csBwA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
  ⁴                 Literal integer `4`
 Ｅ                  Map over implicit range
    ⁴               Literal integer `4`
   Ｅ                Map over implicit range
       .o           Literal string `.o`
      §             Indexed by
           θ        Input `L`
          Ｉ         Cast to integer
         ›          Is greater than
            ι       Outer value
     ×              Repeated by
              ³     Literal integer `3`
             ⁺      Plus
                ι   Outer value
               ⊗    Doubled
↑                   Print rotated 90° anticlockwise
```
Charcoal prints each array element in its own row (or column, if rotated as it is here) and automatically double-spaces nested arrays when printing them.
14 bytes by using the custom characters `1` and `0` instead of `o` and `.`:
```
↑Ｅ⁴Ｅ⁴⭆⁺³⊗ι›Ｉθι
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMMqtEBHwTexQMMETgWXAGXSQZyAnNJiDWMdBZf80qSc1BSNTE1NHQX3otTEktQiDefE4hKNQqAAUBQIrP//N/qvW5YDAA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
  ⁴             Literal integer `4`
 Ｅ              Map over implicit range
    ⁴           Literal integer `4`
   Ｅ            Map over implicit range
        ³       Literal integer `3`
       ⁺        Plus
          ι     Outer value
         ⊗      Doubled
     ⭆          Map over implicit range and join
            θ   Input `L`
           Ｉ    Cast to integer
          ›     Is greater than
             ι  Outer value
↑               Print rotated 90° anticlockwise
```
[Answer]
# [Python 3](https://docs.python.org/3/), 76 bytes
```
f=lambda L,i=0:i<36and". o"[i%4+i/8<3or-(i%4<L)]*4+" \n"[i%4>2]+f(L,i+1)or""
```
[Try it online!](https://tio.run/##HctNCsIwEEDhqwwDwozxP1WkpJ6gN9AuIjU60E7K0I2nj8Xl4@NN3/mT1ZeSmiGOzz5Cu5HmUEvwl6g97iDjXVaVk/01@GxbWiK03K0rh/DQP95OnUu0jO7I2RBLygYComBR3y86cw2Tic6USJjLDw "Python 3 – Try It Online")
-2 bytes by [dingledooper](https://codegolf.stackexchange.com/users/88546/dingledooper)
---
# [Python 3](https://docs.python.org/3/), 91 bytes
```
f=lambda L:L<45and" ".join(4*" o."[j+j+L//5>5and~(j<L%5)]for j in[0,1,2,3])+"\n"+f(L+5)or""
```
[Try it online!](https://tio.run/##FcpBDoIwEADAr2w2Mdm1DajQC0Fe0B8ghxqsttEtabh44etVzjPLd30laUrx17f73GcHtrN9a5zMCFjFFITaI0KqcIwqKlvXZth1o9jbg@HJpwwRgownfdYX3Uys8CaoPFllOGXEspfwL5CdPB9kuIMlB1nJU2AuPw "Python 3 – Try It Online")
[Answer]
# [05AB1E (legacy)](https://github.com/Adriandmen/05AB1E/tree/fb4a2ce2bce6660e1a680a74dd61b72c945e6c3b), 18 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
4L‹ā·>×ε4иø}ζR€.B»
```
Uses `01` instead of `o.` respectively.
[Try it online](https://tio.run/##ASkA1v8wNWFiMWX//zRM4oC5xIHCtz7Dl861NNC4w7h9zrZS4oKsLkLCu///Mg) or [verify all test cases](https://tio.run/##MzBNTDJM/W9ybJKSZ15BaYmVgpK9nw6Xkn9pCYSn4/ffxOdRw84jjYe22x2efm6ryYUdh3fUntsW9KhpjZ7Tod3/dQ5ts/8PAA).
**Explanation:**
Uses the legacy version of 05AB1E because it can zip/transpose on a list of strings, where the new version would require a character-matrix.
```
4L      # Push list [1,2,3,4]
  ‹     # Check for each whether it's larger than the (implicit) input
   ā    # Push a list in the range [1,length] (without popping): [1,2,3,4]
    ·   # Double each: [2,4,6,8]
     >  # Increase each by 1: [3,5,7,9]
      × # Repeat the earlier checks that many times as strings
        #  (e.g. input=2 → [0,0,1,1] → ["000","00000","1111111","111111111"])
ε       # Map over each string:
 4и     #  Repeat it 4 times as list
   ø    #  Zip/transpose; swapping rows/columns
}ζ      # After the map: zip/transpose again, with implicit " " as filler
  R     # Reverse this list of lists
   €    # Map over each inner list:
    .B  #  Box: expand the single filler space to length 4 by adding trailing
        #  spaces based on the string with the longest length in the list
      » # Join each inner list by spaces; and then each string by newlines
        # (after which the result is output implicitly)
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 65 bytes
```
->n{(0..8).map{|x|(0..3).map{|y|(y<3-x/2?" ":y<n ??o:?.)*3}*' '}}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6vWsNAT89CUy83saC6pqIGxDOG8iprNCptjHUr9I3slRSUrCpt8hTs7fOt7PU0tYxrtdQV1Gtr/xeUlhQrpEUbxf4HAA "Ruby – Try It Online")
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 26 [bytes](https://github.com/abrudz/SBCS)
Uses `1/0` instead of `o/.`.
```
3 5 7 9,.{¯9 5↑⍺4⍴⍕⍵}4↑⍴∘1
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///31jBVMFcwVJHr/rQeksF00dtEx/17jJ51LvlUe/UR71ba03AIlsedcww/J/2qG3Co96@R31TPf0fdTUfWm8MkuybGhzkDCRDPDyD/0Pk2iYYcFUDmSD1Xc1pQHMedbdA@OrqtYdWPOrdbAoA "APL (Dyalog Unicode) – Try It Online")
`⍴∘1`: Reshape of 1. Creates a vector of `L` 1's.
`4↑`: Take 4. Extend to length 4 by appending 0's.
`,.{...}`: Inner product. Pair elements from the computed boolean vector and `3 5 7 9` and call the inner dfn on it. Reduce the resulting list by concatenating character matrices horizontally.
`⍕⍵`: Format. Convert the 1 or 0 to a string.
`⍺4⍴`: Reshape into a `⍺×4` character matrix by replicating the digit.
`¯9 5↑`: Extend to a `9×5` matrix by padding with spaces to the top and right.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 78 bytes
```
j,i;f(x){for(i=180;--i;putchar(j?i%5&&i/35+j/5<5?j/5+x>3?79:46:32:10))j=i%20;}
```
[Try it online!](https://tio.run/##FY3LCoMwEEX3@QoRlAlpMGrTR0brj3QjAdsJNC3WgiD59jRuDpezuMfKh7UxugPhBCvfpvcM1NcXhVISfn6LfY4zuIEKXZZUtVq4Snd6SBTrrR3OV3M8mbYxteLc9VQ0CkMkv2SvkTzwjaXHDHZBvULqNApBuwbiyFLgC/nd52kHFuIf "C (gcc) – Try It Online")
Pretty straightforward approach:
often times in C is convenient to iterate backwards the entire volume so we start with *i=lines x width*.
Each time we print the proper character based on div modulus values.
Luckily I found that I could save some Bytes by using i%35 instead of i%40 which would require some extra operations to fit the right shape of each bar.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 15 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
4RðḤ‘ṁ"@>z⁶Ṛx4Y
```
Prints with `o` as `0` and `.` as `1`.
**[Try it online!](https://tio.run/##ASUA2v9qZWxsef//NFLDsOG4pOKAmOG5gSJAPnrigbbhuZp4NFn///8x "Jelly – Try It Online")**
### How?
```
4RðḤ‘x"@>z⁶Ṛx4Y - Main Link: integer, L
4               - four
 R              - range -> [1,2,3,4]
  ð             - new dyadic chain - f(X=[1,2,3,4], L)
   Ḥ            - double X          -> [2,4,6,8]
    ‘           - increment         -> [3,5,7,9]
        >       - X greater than L? -> [1>L,2>L,3>L,4>L]
       @        - with swapped arguments - f([1>L,2>L,3>L,4>L], [3,5,7,9]):
      "         -   zip with:
     x          -     times -> [[1>L,1>L,1>L],[2>L,2>L,2>L,2>L,2>L],[3>L,...],[4>L...]]
         z⁶     - transpose with filler of space characters
           Ṛ    - reverse
            x4  - times four (vectorises)
              Y - join with newline characters
                - implicit, smashing print
```
[Answer]
## Javascript, 99 bytes
```
x=>"0004003402341234"[r="replace"](/\d{4}/g,"$&\n$&\n")[r](/\d/g,y=>+y?x<y?".... ":"oooo ":"     ")
```
(Didn't it use to be `$0` for this and not `$&`?)
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 73 bytes
```
L=>(g=i=>i--?` .
 o`[i%20?i%5&&i/20+2*(x=i/5&3)<9|x+L&4:3]+g(i):'')(180)
```
[Try it online!](https://tio.run/##DctBDoIwEADAu6/YC6W1KdQCiQILH@AHxgSCtFlDqAFjOPj3ymlO8xq@wzau9P6oxT@nYDF02HCHhA0p1faQwAl8f6fI6JaigjFKjZbmzHektGCZqG@/XXYsL7OHdJxEGceCX65aBOtX4AQIugKCGiE/lFLA6JfNz1Mye8ftUUQV/g "JavaScript (Node.js) – Try It Online")
-1 byte by [Arnauld](https://codegolf.stackexchange.com/users/58563/arnauld)
---
# [JavaScript (Node.js)](https://nodejs.org), 90 bytes
```
L=>(g=i=>i>8?'':[1,2,3,4].map(j=>' o.'[j+j+i<8?0:j>L?2:1].repeat(4)).join` `+`
`+g(++i))``
```
[Try it online!](https://tio.run/##DcpBCoMwEADAe1@xt2xYG9R6KGriB/yBCAk2ygZrRKXfTz3NZYL7uXM6eL@eW/z4NOvUa4OLZm3YvDsh6qHIyuyVVaP6uh2DNgKiEkOgQNy@u7wOpu/KuhjV4XfvLqykVCHyZsGSfVhakIiltDbN8QBk0JA3wNBqqG6JJExxO@Pq1RoXnPHOTfoD "JavaScript (Node.js) – Try It Online")
[Answer]
# [Python 3.8 (pre-release)](https://docs.python.org/3.8/), ~~104~~ ~~100~~ 93 bytes
```
lambda n:[f'{"oooo "*(b:=n-4+(k:=min(i,7)//2+1))+".... "*(k-max(0,b)):>20}'for i in range(9)]
```
[Try it online!](https://tio.run/##RYpBDsIgEAC/Qrh0t6W2Vo1Kgh9RDxBFSWUhpAeN8e1IvTi3mUx8TfdAq11M2apTfmhvLpqRPNrqzUOB8RqMVNSuGxil8o7AiS123dAsERu@KMzP2Hr9hF4YRHkY@k9lQ2KOOWJJ0@0KezznOdE/bVDG5GgCQlF7HeFnwhbH/AU "Python 3.8 (pre-release) – Try It Online")
Returns a list of strings, allowed [here](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods/17095#17095).
Thanks everyone for all the tips on my previous python answer. I used some of those tips here!
[Answer]
# [Python 3](https://docs.python.org/3/), 76 bytes
```
lambda n:"".join(". o"[i<~i%4*8or-(i%4<n)]*4+"   \n"[i%4]for i in range(36))
```
[Try it online!](https://tio.run/##XclBCsIwEEbhq/wMFCYtdtMoUtKT2C4iGh2xMyV048arx6zdPd63ffan6VDSNJd3XK@3CB2J@peJMvUwukj4SuPbs@UD1wjqltZ3BGDWqo1fkmUIRJGjPu48nJwrf@/oRmxZdOfEUvkH "Python 3 – Try It Online")
[Answer]
# [brainfuck](https://github.com/TryItOnline/brainfuck), 544 bytes
```
+[-->---[-<]>]>[<<+>>>+<-]<-[>--<-------]>+[<+>-]>[<+>-]+++++++[<++>-]>+++++[<++>-]>-[>+<-----]>---<,>[<->-]<[>>+<<-[>>>>+<<<<-[>>>>>>+<<<<<<-[>>>>>>>>+<<<<<<<<-]]]]++[<+++++[<<<<...>>>>-]>->>>>>>>>[<]<<<<<<<<<<<....[>]<.>>]++[<+++++[<<<<..>>>>-]>->>>>>>[<]<<<<<<<<<....[<]>.[>]>>>>>>>>>[<]<<<<<<<<<<<....[>]<.>>]++[<<<<<.....>>>>>->>>>[<]<<<<<<<....[<]>.[>]>>>>>>>[<]<<<<<<<<<....[<]>.[>]>>>>>>>>>[<]<<<<<<<<<<<....[>]<.>>]+++[->>[<]<<<<<....[<]>.[>]>>>>>[<]<<<<<<<....[<]>.[>]>>>>>>>[<]<<<<<<<<<....[<]>.[>]>>>>>>>>>[<]<<<<<<<<<<<....[>]<.>>]
```
[Try it online!](https://tio.run/##tZHBCgIxDEQ/KKYXr0N@JOSggiCCB8Hvr5N2a13WgyDOYbdJ583A7vF@uNzOj9O1VnFVU1VXhIU5IGYm0IA6L6BdYeK80rTkS7o4tOVqIChYKD6wI8OSgGdy5rYKjOMyzPG14CqoHt0aqFJKWjJ82B2BKRqKW4C2Dbom37lG8SMkat8Fj11L7ZkT@JD3Ux3/1DRs6H/11rp/Ag "brainfuck – Try It Online")
Builds each line in segments. Ungolfed:
```
memory layout
0    1    2    3    4    5    6    7    8    9    10   11   12   13
' '  dot  'o'  \n   cnt  inp  0    Nge1 0    Nge2 0    Nge3 0    Nge4
constants
space = 32
+[-->---[-<]>]>
[<<+>>>+<-]<
o = 111
-[>--<-------]>+
[<+>-]
dot = 46
>[<+>-]
+++++++[<++>-]
\n = 10
>+++++[<++>-]>
get input
-[>+<-----]>---<,>[<->-]<#
check 0
[
  >>+<<
  check 1
  -[
    >>>>+<<<<
    check 2
    -[
     >>>>>>+<<<<<<
     check 3
      -[
        >>>>>>>>+<<<<<<<<
        check 4
        -
      ]
    ]
  ]
]#
first 2 lines
++[
  15 spaces
  <+++++[<<<<...>>>>-]>-
  4 bar segment
  >>>>>>>>[<]<<<<<<<<<<<....
  [>]<.>>
]
next 2 lines
++[
  10 spaces
  <+++++[<<<<..>>>>-]>-
  3 bar segment
  >>>>>>[<]<<<<<<<<<....
  space
  [<]>.[>]>
  4 bar segment
  >>>>>>>>[<]<<<<<<<<<<<....
  [>]<.>>
]
next 2 lines
++[
  5 spaces
  <<<<<.....>>>>>-
  2 bar segment
  >>>>[<]<<<<<<<....
  space
  [<]>.[>]>
  3 bar segment
  >>>>>>[<]<<<<<<<<<....
  space
  [<]>.[>]>
  4 bar segment
  >>>>>>>>[<]<<<<<<<<<<<....
  [>]<.>>
]
last 3 lines
+++[
  -
  1 bar segment
  >>[<]<<<<<....
  space
  [<]>.[>]>
  2 bar segment
  >>>>[<]<<<<<<<....
  space
  [<]>.[>]>
  3 bar segment
  >>>>>>[<]<<<<<<<<<....
  space
  [<]>.[>]>
  4 bar segment
  >>>>>>>>[<]<<<<<<<<<<<....
  [>]<.>>
]
```
It could probably be shorter with a complex loop to handle generating each line but I couldn't get something like that to work.
[Answer]
# Java 11, ~~105~~ 102 bytes
```
n->{for(int i=36;i-->0;)System.out.print((i/4>8-i%4*2?" ":n<i%4?".":"o").repeat(4)+(i%4<1?"\n":" "));}
```
Could probably be golfed slightly more by removing the `.repeat(4)` and looping `144` times instead, but I don't have the time to figure it out for now.
[Try it online.](https://tio.run/##fZBPS8QwEMXv@ymGASGxJK5aRJr@OXtwPexRPcRuVrJ2p6VNF2TpZ6@z3aIg6GVI3nvh/TI7e7Bqt/kYy8p2HTxaT8cFgKfg2q0tHaxOV4BD7TdQCtaBpGFpWPDogg2@hBUQZDCSyo/bup1CPru9M16pfGnk@rMLbq/rPuimZVMIfxXn98pfxJc3BQImlPK5QI0J1ih16xpng4hlJFhPrwt8IbYApTTDaE7NTf9WcfMMMNHtmV2sAze8P79aeeb@4Vka8GkW84yi2QT4jVaRwAdq@pAARn766F@xpz6cc98p0ryg/97M3jCtbxi/AA)
**Explanation:**
```
n->{                   // Method with integer parameter and no return-type
  for(int i=36;i-->0;) //  Loop `i` in the range (36,0]:
    System.out.print(  //   Print:
       (i/4            //    If `i` integer-divided by 4
        >              //    is larger than
        8-i%4*2?       //    8 minus `i` modulo-4 times 2
         " "           //     Use a space
        :n<i%4?        //    Else-if the input is smaller than `i` modulo-4:
         "."           //     Use a dot
        :              //    Else:
         "o"           //     Use an O
       ).repeat(4)     //    Repeat this character 4 times
       +(i%4<1?        //    Once every four iterations:
         "\n"          //     Append a newline
        :              //    Every other iteration:
         " "));        //     Append a space instead
```
]


[Question]
      [
The challenge is simple, find the matching parentheses for every one of the parentheses in a given string input
E.g.
```
()()() -> [1, 0, 3, 2, 5, 4]
```
Always start with the ending parentheses index before the starting parentheses, which is why `()` becomes `[1,0]`, not `[0,1]`, unless the parentheses is stacked e.g. `(())`, where the position of the parentheses must match the index so `(())` is `[3, 2, 1, 0]`
## Test Cases:
```
() -> [1, 0]
()(()) -> [1, 0, 5, 4, 3, 2]
()()() -> [1, 0, 3, 2, 5, 4]
((())) -> [5, 4, 3, 2, 1, 0]
(()(())) -> [7, 2, 1, 6, 5, 4, 3, 0]
```
You may output the indexes in the form of a list, or in the form of a string representation if so, but the output indexes must be distinguishable from each other e.g. `1 0`
You are allowed to use 0-index or 1-indexed lists/arrays.
**This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so shortest bytes wins!**

[Answer]
# x86-64 machine code, 21 bytes
```
5A 58 89 0A 8D 51 57 AB FF C1 45 31 C9 AC 84 C0 7B EE 75 F1 C3
```
[Try it online!](https://tio.run/##XVLPb9sgFD6bv@KNqSokTpR03TTFyy7ddZedJrk@OIBjJgIW4M5Z5H993qNJ27UHw3sf7/sBsui6xV6IaarDARj8oIws98btagMN8d0m61wHXg7kXNRYHNwDlAhVOSiB/XJ3jApWw@dvxCRCH1rw6eBcSU2yEF2QJNNWvKbcfiTNJhucT/BFzjgZdiSLKkSoTY4fyX51DnyHu/0DBnevIuEUeEHUEJW3QO8onB6cltAwbSPMvAq9iTkIZ1FHtLWHWeDFSMh7TGF6qeBLiFK7ZfuVkP@nkrGogwplBVs4UcZpjgtj/FLwM5IATseCJL9DrS3j5ESyBi/DXunBBp41OclwJkuUc8JyvaoKRBr2lDjy1HceZxpGrwJ9gh6VE1NjrlUBsdRVAXo@R9EXAlxpZFzEdXUW62PKwq7v7XUCRvI8fm@/16LVVuFLSbWh6Th5DMkjhyO20sHpRX118xP1j1vGehv03ir5eM8ZbxbrNS@H@Rw9R/jdaqOAHeEd6gx3H5LumxjjNP0Vjan3YVocPt3igv/gFn2U@Qc "C++ (gcc) ‚Äì Try It Online")
Following the standard calling convention for Unix-like systems (from the System V AMD64 ABI), this takes in RDI an address at which to place the result, as an array of 32-bit integers; and the address of the input, as a null-terminated byte string, in RSI.
In assembly:
```
.global f
rp: pop rdx           # (Right parenthesis) Pop the matching left parenthesis's
                      #   corresponding output address into RDX.
    pop rax           # Pop its index into RAX.
    mov [rdx], ecx    # Put the current index at the popped address.
    .byte 0x8D        # Subsumes the next two instructions into 'lea edx, [rcx+0x57]'.
lp: push rcx        # (Left parenthesis) Push the index onto the stack.
    push rdi        # Push the corresponding output address onto the stack.
    stosd             # Store EAX at [RDI] and advance the pointer.
    inc ecx           # Increment the index.
    .byte 0x45        # REX.RB prefix byte; changes the next instruction to 'xor r9, r9'.
f:  xor ecx, ecx    # (Start here.) Set ECX to 0 (index in string).
    lodsb             # Load a character of the string into AL, advancing the pointer.
    test al, al       # Set the flags based on that character.
    jpo rp            # Jump if it has an odd number if 1 bits (for a right parenthesis).
    jnz lp            # Jump if it is nonzero (for a left parenthesis).
    ret               # Return (for the null terminator).
```
[Answer]
# [BQN](https://mlochbaum.github.io/BQN/), 37 bytes[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)
```
{‚åΩÀò‚åæ(‚àò‚Äø2‚ä∏‚•ä)¬®‚åæ(((1‚ä∏‚â†++`)¬Ø1‚ãÜùï©-@)‚ä∏‚äî)‚äíÀúùï©}
```
[Run online!](https://mlochbaum.github.io/BQN/try.html#code=RiDihpB74oy9y5jijL4o4oiY4oC/MuKKuOKliinCqOKMvigoKDHiirjiiaArK2Apwq8x4ouG8J2VqS1AKeKKuOKKlCniipLLnPCdlal9CgpGICIoKSgoKSki)
`(1‚ä∏‚â†++`)¬Ø1‚ãÜùï©-@` generates a depth map for the brackets. Coupled with Under, we can group the indices by depths, and reverse the grouping to get back the original array shape.
`‚åΩÀò‚åæ(‚àò‚Äø2‚ä∏‚•ä)¬®` reverses each pair of bracket indices, putting them in the correct place.
-1 and -4 with ovs' help.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 51 bytes
```
a=>a.map((c,i)=>a[a[i]=a.lastIndexOf(c>'('&&-1)]=i)
```
[Try it online!](https://tio.run/##JYyxDoIwFEV3vqITfS@Bl7iZkLIx6CCDI2F4KRRrsCW0MRrjtyPIcu49d7h3fnLQs51i7nzXL0YtrEqmB08AOrO4SsONbRXTyCGeXNe/agO6lCDTND9gqywuErAA3AC4t3342yZbrERJYRptBFlIJOPnivUNolCl@CRCaO@CH3sa/QCRJu4q18ERMwEGWCjREFFsVz9f6wuFOFs3WPMGXp@L5IvF8gM "JavaScript (Node.js) ‚Äì Try It Online")
Input an array of characters. Output by modify the array in-place.
[Answer]
# [Haskell](https://www.haskell.org/), 112 bytes
```
g(a:x)|a>'('=1|w<-g x=1+w+g(drop w x)
a#b=succ<$>a!map(-1+)b
('(':x)!s=g x:x#(0:s)
(_:x)!(a:s)=a:x#s
_!w=w
(![])
```
[Try it online!](https://tio.run/##FczLCoMwEIXhfZ5iYgRnEKFuxfFFSpHRlij1hmlJFr57msJZHfj@Sdz7tSwxWpQm0CVdgQXXl28rC4Hr0pcWn@d@gIdASszA7juObd6JXuXAqi5pUJhQ0tpxQk0weGscKez/X@o64hQ3TvXas1cTo74/KK4yb8BwnPP2gRwmyBAJKS2LPw "Haskell ‚Äì Try It Online")
With some comments:
```
-- Get the 1-based index of the first unmatched ')'
g :: [Char] -> Int
g(a:x)|a>'('=1|w<-g x=1+w+g(drop w x)
-- Common part of the two cases in (!); updates the indices
(#) :: [Char] -> [Int] -> [Int]
a#b=succ<$>a!map(-1+)b
-- Main function, iterates through the string
(!) :: [Char] -> [Int] -> [Int]
-- '(' are replaced by the result of g on the remaining string
('(':x)!s=g x:x#(0:s)
-- ')' are replaced by the index of the matching '(' (stored in the right argument)
(_:x)!(a:s)=a:x#s
_!w=w
h :: [Char] -> [Int]
h=(![])
```
[Answer]
# [Haskell](https://www.haskell.org/), 94 bytes
```
snd.([]%).zip[0..]
z%((i,c):x)|c<')',(j:k,a)<-(i:z)%x=(k,j:a)|v:w<-z=([i],[v])<>w%x
z%e=mempty
```
[Try it online!](https://tio.run/##bc2xboMwFIXhnae4ioJyr2RbnS07SyulS6XulMECUxzAWOAGivLsdenadv3065zWzJ3t@@SGME4Rnkw04mX0o6sBUZ2JgHPwdoHL8yO0ZobYuhmch9fJ9h@1FVmj39Lsa4FFmZPYXCgehCizLUd0rCK50r1SJzoxvMqOGVIcndwoXzV27CoN3W9yUXzTWLiSFbeS1HnJ133A6sEOIX6mweyHGuoxAwiT8xGO0MAB6fAbEOkfpL/lT7hj@qqa3rzPiVchfAM "Haskell ‚Äì Try It Online")
[Answer]
# Python3, 75 bytes
```
def f(a,*s,i=-1):
 for c in a:
  i+=1;s+=i,
  if"("<c:*s,a[i],_=s;a[a[i]]=i
```
[Try it online!](https://tio.run/##NY4xDoMwDEX3nsLKZJcwoG5QnwShKqJEtVQFRLJw@tQWdLHf//K3vR3ls6ZHre8lQsTg79kLtx31N4jrDjNIgqACpOFuyA2LNxEduufc63QYZfIvzkMYDSeWasGy5GJZh@S8VUT6E12eWRfRyXYoAMNXckFbQWroW9a2XVJRrD8)
-2 thx to @KevinCruijessen
-6 thx to @ovs
-10 thx to @loopywalt
-6 thx to @ovs
-4 thx to @loopywalt
## Other solutions:
## Python3, 76 bytes
```
def f(a,s=[]):
 for*s[:0],c in enumerate(a):
  if"("<c:i,v,*_=a[v],a[i],*s=s
```
[Try it online!](https://tio.run/##NY5BCgMhDEX3PUVwFSWLQjdF6klEikyVCq0zGGegp7cG2k3yeeGFv336c62X69bGeKQMGSOx80HbE@S1Gfb2HGiBUiHV/Z1a7AmjXKFkheq22EIHmbuL/ggUfQlk2PGYMvTEXUyFWpFMRP1P@scEaSX/Ijh4Fe4omp5gdpG1tVL7jOML)
[Answer]
# [Python](https://www.python.org), 93 bytes
```
def f(x):
 d=c=0
 for y in x:c-=y<')';x[d]=c;x[k:=x.index(c)]=d;x[d]=[c,k][k<d];c+=y>'(';d+=1
```
[Attempt This Online!](https://ato.pxeger.com/run?1=TY5BbsMgEEX3PsXsGBpsJW0jVXbIRSwWERgVGWPL0Mo-SzfetHfKbQqmUsoGzX_z_5-vn2kN76Pbtu-PoMu3u1CdBo0LrQtQXPJjAXqcYQXjYKllydcLoaRZWiW4jF9f86UyTnULSiq4yqSVrBdtf1GikQe-XgmSRh346a9kNsM0zgH86ouUblN6HCoflHHV3N2UNa7zmK6Iz7ARONjKT9YEJFBegdCdJL37vFkc8zzNxgWM-0zjUPP2yQgaCwaam7e7RJrs7YnBURRIEelDYHBm8MrghcHzDin-h0nOKxEmY4YPD4M9Nnf9Ag)
Takes a list of characters and modifies it in-place.
#### How?
Simply walks the list from left to right. Tracks the bracketing depth (uses negative numbers, so we can unambiguously overwrite them with indices later). Whenever we encounter a level for the second time swap indices with first occurrence.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~19~~ 17 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
'(QvyiN√´N‚ÄöÀÜ]¬Øvy√Ç«ù
```
Input as a list of characters.
[Try it online](https://tio.run/##yy9OTMpM/f@/rFJdIzDT7/Bqv0cNs063xR5aX1Z5uOn43P//o5U0lHTAWBNKw9gQHAsA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfaWLEpCrrhGY6Xd4td@jhlmn22IPrS@rPNx0fO5/Jb0wnUNb/kdHK2ko6ShpKsXqKMCYOmAaxsYihaDhUqg6MKQ0sSuJBQA).
**Explanation:**
```
v          # Loop over the characters `y` of the (implicit) input-list:
 y'(Qi    '#  If the current character is a ")":
      N    #   Push the current loop-index
     √´     #  Else:
      N‚Äö   #   Pair the top value on the stack with the current loop-index
        ÀÜ  #   Pop and add this index-pair to the global array
]          # Close both the if-statement and loop
 ¬Ø         # Push the global array of index-pairs
  v        # Loop over each pair of indices:
   y√Ç      #  Bifurcate the current pair; short for Duplicate & Reverse copy
     «ù     #  Insert the values at the indices in the list
           #  (which will use the implicit input-list the first iteration,
           #  and modifies it further every iteration)
           # (after which the list is output implicitly as result)
```
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 61 bytes
-1 byte thanks to [@DialFrost](https://codegolf.stackexchange.com/users/109916/dialfrost).
```
s->for(i=j=1,#a=s,if(")">s[i],s[j]=i;j++,a[a[i]=s[j--]]=i));a
```
[Try it online!](https://tio.run/##JchBCgIxDIXhq4S4SZh04XpIj@GmdBHESotombjx9J0WeZvv/d2OGp59FNDhIZbPQVWbXuVi6lILIWP0VLN4alnr3rZNLNksOksIeUbm3Yb1/vqRQ4jQj/r@TuI6CIVujzs5MwskJF5DgSXivxYYM48T "Pari/GP ‚Äì Try It Online")
[Answer]
# [Perl 5](https://www.perl.org/), 82 bytes
```
sub f{($_,$i)=(@_,0);/\((?R)*\)/?(reverse($i..$i-1+($l=length$&)),f($',$i+$l)):()}
```
[Try it online!](https://tio.run/##XY9NT8JAEIbv/Io3zeLOyPCpeIBUejeRhHgD0kTd1o211FKMhvDb67bUIOxp33mendnJTJ6My3K7e0a0JxWKsuxTEMqAp/0V0WzB1yvuzyg3XybfGlK211O2O@yQSvzEpHHxpq6YJSKl3eOOSpgnxIcy2uTUWgKaWKM6/j2WQ8FgDaylIUTs6B8RjAW3ghvB6MxiOrMqfnT/WVWrxjp1EVxMrOcd/3LJed8CPn7chqIM@4EKp3UhiH23nOUqZblNi8hrd@@2gPnOzEthXidod4cjV0C8KU7BptnORWVXqSfwAmU8mE93iT3MoDfvGhPox/kT5g@6EaTG09ah/AU "Perl 5 ‚Äì Try It Online")
[Answer]
# x86-16 machine code, 21 bytes
```
00000000: 33db ac3c 2974 0353 eb07 5888 0193 8801  3..<)t.S..X.....
00000010: 9343 e2ee c3                             .C...
```
Listing:
```
33 DB       XOR  BX, BX             ; start index counter at 0
        P_LOOP:
AC          LODSB                   ; AL = next char in input string
3C 29       CMP  AL, ')'            ; is it an end paren?
74 03       JZ   END_PAREN          ; if so, jump to handle
53          PUSH BX                 ; else, push index of left paren to stack
EB 07       JMP  NEXT_PAREN         ; continue loop
        END_PAREN:
58          POP  AX                 ; AL = index of last start paren
88 01       MOV  [DI+BX], AL        ; write to output at current index of input string
93          XCHG AX, BX             ; AL = current index of input string
88 01       MOV  [DI+BX], AL        ; write to output at index of last start paren
93          XCHG AX, BX             ; restore index counter to BX
        NEXT_PAREN:
43          INC  BX                 ; increment counter
E2 EE       LOOP P_LOOP             ; continue string loop
C3          RET
```
Custom calling convention - input string at `[SI]`, length in `CX`, output to buffer at `[DI]`.
Tests with DOS DEBUG:
[![enter image description here](https://i.stack.imgur.com/YqTVh.png)](https://i.stack.imgur.com/YqTVh.png)
[![enter image description here](https://i.stack.imgur.com/ecLn2.png)](https://i.stack.imgur.com/ecLn2.png)
[![enter image description here](https://i.stack.imgur.com/zNn6M.png)](https://i.stack.imgur.com/zNn6M.png)
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 67 bytes
```
\((?=((\()|(?<-2>.))*(?<=(.+)))|(?<=(.*).((\))|(?<-6>.))*).
$.3$.4
```
[Try it online!](https://tio.run/##JYohDoAwEAR9X4Go2C3pCSAo2n6kBoHAIAiSvx/toWZnM/fxnNeuWoGSgAq@KFucspChrQQZSTvbDJTW/BpXayjOy@xlGVRBBwI0sFuXDnv5AQ "Retina 0.8.2 ‚Äì Try It Online") Link includes test cases. Assumes input is a balanced string of `()`s. Explanation: The first alternation matches a `(`, skips over any balanced `()`s, then captures the resulting index, while the second alternation matches in reverse, skipping back over any balanced `()`s and an implied `(` before capturing the resulting index, then matching an implied `)`. Fortunately `$.` outputs an empty string if the group was not captured at all, so we can just output the length of whichever capture was successful followed by a separator.
[Answer]
# [SNOBOL4 (CSNOBOL4)](http://www.snobol4.org/csnobol4/), ~~144~~ 136 bytes
```
	I =INPUT
	M =BAL | ''
N	I POS(X) LEN(1) . B @X	:F(END)
	B ")"	:F(L)
	I @O '(' M B POS(X) 	:(O)
L	I POS(X) M @O ')'
O	OUTPUT =O	:(N)
END
```
[Try it online!](https://tio.run/##RY0xC8IwFITnvF9xdMl7iyA4FQI1WCGQ5BVsobOz2KGr/z0@RRBuueO7u/253bfHqTWXEFKdlplcQYjnjBe8p2r5pDdeBXmsfBQcEDGsrr/yWC9CLqKT7mOzmYRB4dmjGPXruZ5VKP@HyhcST@p0me0SQQ2qQrbYGrOYRN4 "SNOBOL4 (CSNOBOL4) ‚Äì Try It Online")
```
	I =INPUT			;* Read input
	M =BAL | ''			;* Alias: M is BAL (the shortest, non-null balanced string) or the empty string
N	I POS(X) LEN(1) . B @X	:F(END)	;* extract the next character of I as B, and store the position after B as X
	B ")"	:F(L)			;* If B matches ")", goto next line, else goto L
	I				;* In I, match:
	  @O				;* the position before the match as O
	     '(' M B			;* "(", a balanced string (or nothing), and ")"
		     POS(X) 	:(O)	;* ending at position X, then goto O
L	I POS(X) M @O ')'		;* In I, match, starting at position X, a balanced string, storing position as O, followed by ")"
O	OUTPUT =O	:(N)		;* Output O and goto N
END
```
[Answer]
# APL+WIN, 42 bytes
Prompts for input string. Index origin = 1
```
(,‚åΩ((.5√ó‚ç¥n),2)‚ç¥n)[‚çãn‚Üê‚çã+\(~n)-¬Ø1‚Üì0,n‚Üê')'=‚éï]
```
[Try it online! Thanks to Dyalog Classic](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v@ob6qvz6O2CcZcQJanP5BlyPWooz3tv4bOo569Ghp6poenP@rdkqepY6QJpqMf9XbnAZUBKe0Yjbo8Td1D6w0ftU020AGJqmuq2wINiv0PNIPrfxqXuoamOheY0tDQhDM1YaIgQU11AA "APL (Dyalog Classic) ‚Äì Try It Online")
[Answer]
# [Curry (PAKCS)](https://www.informatik.uni-kiel.de/%7Epakcs/), 55 bytes
```
g .zip[0..]
g[]=[]
g((i,'('):x++(j,')'):y)=j:g x++i:g y
```
[Try it online!](https://tio.run/##NYxNC4MwDIbv/RVZGZjgBzsX6n2HscOOIkNkljqUYivM/fkuOr3kfXiSN@08TUvumnfrY@y0geJrXXUpilqYqtYVB6LNEkxIfdIU@ywhxoV0rwywsRxLDC8fQCl4hMmOBvISrndAEpv3oMHNgXeMZXmwXM/kKtBxK8D5dIIOPAkxNHbk0tC42xO2H5VEkhnwRKSDaHer2on@XMcf "Curry (PAKCS) ‚Äì Try It Online")
[Answer]
# Python3, 124 bytes:
```
import re
def f(s):
 while'('in s:
  s=re.sub('\(\d*\)',lambda x:f'{(S:=x.span())[1]-1}{x.group()[1:-1]}{S[0]}',s)
 return s
```
[Try it online!](https://tio.run/##TVDJbsIwED3XXzHi4hnkRKTQRZHST@iFY4gqR3GKpSyWbVoqxLfTSVNajvO2mTfuK@7HYf3s/OViezf6CN6IxrTQYqBcwOfedkaitAMEHiEU3qThUKPc4a5Z7kiqTvd1o@GYt/KE27w4psHpAYnKrEqy8@mYvvvx4JDnPMmq82lbrqqzVIEEL4sHz9HX5TpEEYrFYoEEyQuUmYJVJZCQ4/4ABQ8KNgrWCu5/SMJbcoJnCZOTcSb/PQp@Y@fcmX66Eo838SziW0Q7erDAL2htF43H13EwCgL37GzkTwyS@Fd3WtVQgL3CU6wkhkMwXK1c9tqhHaJqURNVRTG1TVlqvO7ezIfusCbhPEtQRhNiADd5G0mXbw)
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 34 bytes
```
‚âî‚ü¶‚üßŒ∑Ôº¶Œ∏¬ø‚Åº(Œπ¬´‚äûœÖÔº¨Œ∑‚äûŒ∑‚Å∞¬ª¬´¬ß‚âîŒ∑‚åàœÖÔº¨Œ∑‚äûŒ∑‚äüœÖ¬ªÔº©Œ∑
```
[Try it online!](https://tio.run/##dYwxC8IwFIRn8ysend6DCO5ORRwEheziEGraBNKkbRIpiL89JnYWbrn77q7Tcum8tDm3IZjB4f3BQdOR9X4BnAlMD3iek7QBG2w4GCJ4s51IQWPicFVuiBo1lckWag6HYj6gbFC1uh238eKeaq34JlczphET/dkLPxVYT5hYjIt4kiH@OjkjUhFR3r/sFw "Charcoal ‚Äì Try It Online") Link is to verbose version of code. Explanation:
```
‚âî‚ü¶‚üßŒ∑
```
Start building up the output list. (I need a second list as I want to use the predefined empty list as a stack.)
```
Ôº¶Œ∏
```
Loop over the input characters.
```
¬ø‚Åº(Œπ¬´
```
If this is a `(`, then...
```
‚äûœÖÔº¨Œ∑
```
... save the current index to the stack, and...
```
‚äûŒ∑‚Å∞
```
... push a dummy value to the output list.
```
¬ª¬´
```
Otherwise, ...
```
¬ß‚âîŒ∑‚åàœÖÔº¨Œ∑
```
... replace the latest dummy value with the current index, and...
```
‚äûŒ∑‚äüœÖ
```
... push its index to the output list, removing it from the stack.
```
¬ªÔº©Œ∑
```
Output the final list of indices.
[Answer]
# [BQN](https://mlochbaum.github.io/BQN/), 24 [bytes](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)
```
(‚ä¢‚äî‚Åº‚ä¢(‚äî‚äíÀú¬®√ó‚ãà¬¨‚ä∏√ó)¬∑+`¬¨-¬ª)‚äê
```
[Try it here.](https://mlochbaum.github.io/BQN/try.html#code=RiDihpAgKOKKouKKlOKBvOKKoijiipTiipLLnMKow5fii4jCrOKKuMOXKcK3K2DCrC3CuyniipAKRsKoIOKfqCIoKSIsIigpKCgpKSIsIigpKCkoKSIsIigoKCkpKSIsIigoKSgoKSkpIuKfqQ==)
How it works [(with example)](https://mlochbaum.github.io/BQN/try.html#code=IyAo4oqi4oqU4oG84oqiKOKKlOKKksucwqjDl+KLiMKs4oq4w5cpwrcrYMKsLcK7KeKKkAoK4oCiU2hvdyAiSW5wdXQ6IiAgICDii4ggICBpIOKGkCAiKCgpKCgpKSkiCuKAolNob3cgIk1hc2s6IiAgIDziirjiiL4gICBtYXNrIOKGkCDiipBpCuKAolNob3cgIkRlcHRoOiIgIDziirjiiL4gICBkIOKGkCAoK2DCrC3CuyltYXNrCuKAolNob3cgIlNwbGl0OiIgIDziirjiiL7ijL0gICAgICBtYXNrKCAgICDDl+KLiMKs4oq4w5cpZArigKJTaG93ICJNYXRjaDoiICA84oq44oi+ICAgcCDihpAgbWFzayjiipTiipLLnMKow5fii4jCrOKKuMOXKWQK4oCiU2hvdyAiQ29tYmluZToiPOKKuOKIviAgIG1hc2sg4oqU4oG8IHAKQA==):
1. Calculate the parenthesis depths from a mask of the string.
2. Split the depths into one vector where the indices of open parens are replaced with 0, and one vector where the indices of close parens are 0, such that if you add them together you get back the original depths.
3. Match depths of the open parens in the close paren half of the depth vector, and close parens in the open paren half, [without repeats](https://mlochbaum.github.io/BQN/doc/search.html#progressive-index-of).
4. Use the original mask to combine the two lists of indices back together.
Detailed breakdown:
```
(‚ä¢‚äî‚Åº‚ä¢(‚äî‚äíÀú¬®√ó‚ãà¬¨‚ä∏√ó)¬∑+`¬¨-¬ª)‚äê  #
                       ‚äê  # Classify the string to get a mask
(               ¬∑+`¬¨-¬ª)   # Generate depths of parentheses
    ‚ä¢(    √ó‚ãà¬¨‚ä∏√ó)          # Pair mask and it's negation, multiplied by the depths
      ‚äî                   # Group depths according to the mask
       ‚äíÀú                 # Take the progressive index-of
         ¬®                #   between corresponding groups and depths
  ‚äî‚Åº                      # Inverse partition to combine results
 ‚ä¢                        #   according to the original mask
```
]


[Question]
      [
Given a multidimensional, rectangular array of nonnegative integers, sort it at every depth (lexicographically), starting from the innermost.
For example, with this array:
```
[ [ [5, 1, 4],
    [10, 7, 21] ],
  [ [9, 20, 2],
    [4, 2, 19] ] ]
```
You'd sort at the deepest first:
```
[ [ [1, 4, 5],
    [7, 10, 21] ],
  [ [2, 9, 20],
    [2, 4, 19] ] ]
```
Then sort at the next depth, lexicographically:
```
[ [ [1, 4, 5],
    [7, 10, 21] ],
  [ [2, 4, 19],
    [2, 9, 20] ] ]
```
lexicographic comparison of arrays means comparing the first element, and if they're equal comparing the second, and so on all the way down the line. Here we see that `[2, 4, 19]` is less than `[2, 9, 20]` because although the first elements are equal (2) the second aren't - 4 < 9.
Finally, sort at the top depth (lexicographically):
```
[ [ [1, 4, 5],
    [7, 10, 21] ],
  [ [2, 4, 19],
    [2, 9, 20] ] ]
```
The first one is less than the second, because `[1, 4, 5]` is less than `[2, 4, 19]` because 1 is less than 2.
You may take the lengths of dimensions and/or depth of the array as well.
## Testcases
```
[2, 1] -> [1, 2]
[[[10, 5, 9], [6, 4, 4]], [[2, 6, 3], [3, 3, 2]], [[3, 8, 6], [1, 5, 6]]] -> [[[1, 5, 6], [3, 6, 8]], [[2, 3, 3], [2, 3, 6]], [[4, 4, 6], [5, 9, 10]]]
[[[6, 9], [12, 17]], [[9, 6], [9, 8]]] -> [[[6, 9], [8, 9]], [[6, 9], [12, 17]]]
[[[9, 1], [2, 5]], [[8, 5], [3, 5]]] -> [[[1, 9], [2, 5]], [[3, 5], [5, 8]]]
```

[Answer]
# [Python 2](https://docs.python.org/2/), 30 bytes (@SurculoseSputum)
```
def f(L):L>f<map(f,L)<L.sort()
```
[Attempt This Online!](https://ato.pxeger.com/run?1=XZBBasMwEEXp1qcYsrJACZEdu3aIs-zKNxCiGGoRgWsLx0nIWbrxpvQWvUd7ms5ISiAFw3yN3_z50seXvU6HoU_m-fM06WXx_dZq0HHNtvVe794bG2tes129Og7jFDMP_dSXg-laENsIwPABKiCyPTcdH5vLq-ntCeHV0XZmihew3MOCMWR1bKjY0fQTDFVlOJjIe86_Ty8y4SAU4VJwSFQkpRRrDhmHUnGQOYcNfoo0sXhOSadYiXd9VAX-Ii3caK6U95T3hp_B8eLulQYvL3Pf37iFjqcMmG6NZhQrD5EERX72dBnQ0vnedt7Igqrj_s86QzIP-zOPFaR80uzhCuUjlwYu82vDe_4B)
#### Old [Python 2](https://docs.python.org/2/), 32 bytes (@ovs)
```
f=lambda s:s>f<s.sort(key=f)or s
```
[Attempt This Online!](https://ato.pxeger.com/run?1=XZDRaoMwFIbZbZ_i0KsIaWm0Oi21l2PvEMJwTGmYVTFpS59lN96MPdP2NDsnSQstCPlz_P7__Pr1M1zsvu_iafo-2maR_0JTttXh_aMCszG7ZmuWph8t-6wvZRP1I5jAvZ73uq1BbGYAmvdQwqEaWH2qWj5W5zfdDUfLoqUZWm3ZHBY7mEcRssOoO8vQUZYN0zjyedPf04uMOQhFqBQcYjWTUooVh5RDoTjIjMMaH0WaWLwnpBM8iXdzVDm-Ii2cNVPKZ8rbwHvQnt-ykpDlZebna7fQ8dQB260wjGploZKgys-eLgJauNzrziuZ0-m4R68LpPCwP_VYTso3Te8-objnksClfm34n_8)
#### Old [Python 2](https://docs.python.org/2/), 33 bytes (@ovs)
```
f=lambda s:s>[]<s.sort(key=f)or s
```
[Attempt This Online!](https://ato.pxeger.com/run?1=XZDRaoMwFIbZbZ_itFcR0tJodVpqL8feIYThmNIwq2LSlT7LbrwZe6btaXZOkhY6EPLn-P3_-fXze7jYQ9_F0_R1ss0y_5k3ZVsdX98qMFuzl2pnVqYfLXuvL2UT9SOYAD6fD7qtQWxnAJr3UMKxGlj9UbV8rM4vuhtOlkUrM7TasgUs97CIImSHUXeWoaMsG6Zx5POm34cnGXMQilApOMRqJqUUaw4ph0JxkBmHDT6KNLF4T0gneBLv5qhyfEVaOGumlM-Ut4H3oD2_ZSUhy8vMzzduoeOpA7ZbYxjVykIlQZUfPV0EtHC5151XMqfTcf-9LpDCw_7UYzkp3zS9-4TinksCl_q14X_-AQ)
#### Old [Python 2](https://docs.python.org/2/), 34 bytes
```
f=lambda s:s>=[]<s.sort(key=f)or s
```
[Attempt This Online!](https://ato.pxeger.com/run?1=XZDRaoMwFIbZbZ_i4FWEtDRaXSxLL8feIYThmNIwq2LSlT7LbrwZe6btaZaTpIUWhPw5fv9_fv36Gc92P_TZPH8fbbvkv0kruvrw9l6D2ZqdkOrJrMwwWfLRnEWbDhOYSL6c9rprgG0XAJoOIOBQj6T5rDs61adX3Y9HS9KVGTttSQLLHSRp6thx0r0lziFES7Qbhbz57-FZZhSYQlQyCplaSCnZmkJBoVIUZElh4x6FGll3z1Hn7kTez53i7hVq5q2lUiFTXgfB4-z8mpXHrCDLMN_4hZ7HDq7d2oVhrTJWYlj5MdBVRCufe9l5ITmenrv3-kAMj_uLgHFUoWlx8wnVLZdHrghr4__8Bw)
This works by side-effect (of in-place sort). It uses comparison to `[]` as a type check and chained comparison to short circuit (in-place sort returns `None`, so the chained comparison will always fail)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
√ü≈í·∏ä¬°‚Ç¨·π¢
```
[Try it online!](https://tio.run/##XZAxDsIwDEX3nsISa5CapgnJwj2QlZEF9QKsLEiMTGwIZg5AVyoOUi4S7DhUgBTJv87z9282667bpjScn8fxfnhcXrvb2F/TsCdBrf5EdZUSVtgo0FHBDOZLQK2giRUi6lqBVRDoBp2Clk5kzTh9G9aGKvO5T8rTFWudR12Mky1OPRkjBz/ZmWIn0km/zTszzzEoY01@nMyVVJqDL4QOBQ3Z92vtB/ZcM/o/nj2DvAFHsIJ5VhLW/v9I@EVNQa0sr@Ib "Jelly ‚Äì Try It Online")
## How it works
```
√ü≈í·∏ä¬°‚Ç¨·π¢ - Main link f(M). Takes a multidimensional array M on the left
    ‚Ç¨  - Over each inner element E of M:
 ≈í·∏ä    -   Get its depth, D
√ü  ¬°   -   Call f(E) D times
     ·π¢ - Sort the result
```
Essentially, as sorting is [idempotent](https://en.wikipedia.org/wiki/Idempotence), `f` is also idempotent, and so we can apply it as many times as we want with no extra side effects. Therefore, we iterate over each element of `M`, depth-wise, apply `f` to it, then sort the result.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 18 bytes
```
Sort//@#/.Sort->D&
```
[Try it online!](https://tio.run/##NY2/CoMwEMZ3XyPg9Fkbo2kyVBz6AAXH0iFIpQ5akGzhfPX0ktLpfnffn1udf79W55fJxfkax8/u63oQ9SlR1d/KeN@XzT9E1c@DeJbHOLntCEVoIAlFCEGe0cESgkaLlhhY01AMCgpNvigYaAbJXk30S@ock9x0ySabLRbmb7DpB7d1WTY8UydvVFD8Ag "Wolfram Language (Mathematica) ‚Äì Try It Online")
Essentially copied from [this earlier answer](https://codegolf.stackexchange.com/a/186798/81203). Relies on the array being rectangular; otherwise, `LexicographicSort` (introduced 12.3) is required instead
```
Sort//@#            sort all levels
        /.Sort->D   un-Sort atoms
```
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), ~~18~~ 12 bytes
Anonymous prefix lambda. Takes list of lists‚Ä¶ as argument.
```
{√ó‚â°‚çµ:‚àß‚àá¬®‚çµ‚ãÑ‚çµ}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/qG@qp/@jtgkG/6sPT3/UufBR71arRx3LH3W0H1oBZD/qbgGStf/TgEo0HvX2PepqftS75lHvlkPrjR@1TQTqDg5yBpIhHp7BmkDaK9jf73@aerSRjoJhrDqXrq4uF5AXHW1ooKNgqqNgGaujEG2mo2ACRLEgNkghkG8MYhsDaR0FI4g4kGUBlAKxDcFazWJjkQ00gxpmCLLJHKLHEqoBSFugqrYEOQcoA1RsClFrAWJBLDUFqQUA "APL (Dyalog Extended) ‚Äì Try It Online")
`{`‚Ä¶`}`‚ÄÉ"dfn"; argument is `‚çµ`:
‚ÄÉ`√ó`‚ÄÉ[if] signum of
‚ÄÇ`‚â°`‚ÄÉdepth of
‚ÄÉ`‚çµ`‚ÄÉargument
‚ÄÉ`:`‚ÄÉ(i.e. if the argument has depth) then:
‚ÄÉ‚ÄÉ`‚àß`‚ÄÉsort the
‚ÄÉ‚ÄÉ`‚àá`‚ÄÉrecursion on
‚ÄÉ‚ÄÉ`¬®`‚ÄÉeach of
‚ÄÉ‚ÄÉ`‚çµ`‚ÄÉ the argument
‚ÄÉ`‚ãÑ`‚ÄÉelse:
‚ÄÉ‚ÄÉ`‚çµ`‚ÄÉreturn the argument
[Answer]
# [SWI-Prolog](https://www.swi-prolog.org/), ~~72~~ ~~59~~ 49 bytes
```
f([H|T],S):-f(H,Q),f(T,R),msort([Q|R],S).
f(E,E).
```
[Try it online!](https://tio.run/##TY89C4MwEIb3/oqMCZzSaLWxSyfB1ZgtZGyKYGtRwcX/bu@MghC497177iO/oe/6dzTO7bp6bqvFOGjEI/K8glqA5wa0gM/YDxO39aKpGl88L6EU8fpEzibApAOGNOattfIKLANWYM7mwG74HGkC0aekU4zAkpBHpbBEWm6tuaOCPgbm@zBJm@6hp9gbMKqNbg66COfQtiywilRYmm2sQXYe2unF8ehvdxh9Ns3ZGPzrHw "Prolog (SWI) ‚Äì Try It Online")
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 6 bytes
```
Œª-[vxs
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLOuy1bdnhzIiwiIiwiW1tbMTAsIDUsIDldLCBbNiwgNCwgNF1dLCBbWzIsIDYsIDNdLCBbMywgMywgMl1dLCBbWzMsIDgsIDZdLCBbMSwgNSwgNl1dXSJd)
*-5 thanks to @emanresuA in vychat*
## Explained
```
Œª-[vxs
Œª      # a lambda that takes a single argument n and:
 -     #   subtracts n from itself (scalars return 0 which is falsey, lists return a list of 0s which is truthy) - borrowed from https://codegolf.stackexchange.com/a/241658/78850
  [    #  and if that item is a list
   vx  #    call this lambda on each item
     s #    and sort the result
```
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 34 bytes
```
f(a)=if(#a',vecsort(apply(f,a)),a)
```
[Try it online!](https://tio.run/##NU3bCgIhEP2VYXtIYRZyt734UD8i8yCRIUSJRdDX28xqoMy5ziSfY39LpQTl9SkGtfN7/Fwvr2d@K5/S/asCeq35l0o99GdIOT7Yh05IB1LWCM4NCIYEOHNAmBCssBnhyI@oRZiPgkeeCEPVGa1sCTZbdaZqSH1bY2T7UkXbojzXf8624xybqrQKqodYIdLlBw "Pari/GP ‚Äì Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 30 bytes
```
f=->b{b*0==0?b:b.map(&f).sort}
```
[Try it online!](https://tio.run/##KypNqvz/P81W1y6pOknLwNbWwD7JKkkvN7FAQy1NU684v6ik9n@BQlo0EBga6CiY6ihYxuooRJvpKJgAUSyIHW2kowDkG4PYxkBaR8EIIg5kWQClQGxDsFazWCD4DwA "Ruby ‚Äì Try It Online")
[Answer]
# JavaScript, ~~70~~ 64 bytes
```
f=x=>x.sort(g=(a,b)=>1/a?a-b:f(a).some((c,i)=>a=g(c,f(b)[i]))*a)
```
[Try it online!](https://tio.run/##jY/BDoIwDEDvfsWOnRnoQBA007sHPXhcdhiEkRkUA8To189OOBuSJX1b29fupl@6Lzv7HIJX5pwRb3F4h33bDVAL0Kyg4sBX@qiDYmdAU0zdK4CSWUxoUSMZKKi0itKlpq5sH33bVGHT1nC6Xs5hP3T2UVvzAQMyYoRjId0v/tdJydeMJIzkihGZMrLBozx7Bd5jzzFGRqLxHSnDlGf@a02VmjcqncZwv912tOWTCmM215P7z2EPapLRknkaF00mi/sC)
*Saved 6 bytes thanks to [tsh](https://codegolf.stackexchange.com/users/44718).*
[Answer]
# [Python 3](https://docs.python.org/3/), ~~¬†47¬†~~ 36 bytes
Saved 1 byte thanks to @Dialfrost, and 9 bytes thanks to @loopywalt
```
f=lambda l:l*0!=0==l.sort(key=f)or l
```
[Answer]
# [J](http://jsoftware.com/), 30 bytes
```
[:><@#\.@$(4 :'/:"x~y')&.>/@,<
```
[Try it online!](https://tio.run/##XY/NTsMwEITvfopRi0gibd04joNtlSgCiVPFgavxCbVCXLjChVcP658iFcmWx@tvZtcf60Y2Z9x7NCD08Lx3Eo8vx6c1@PmwbF/lctOO8M3eb75@vpvuVs77hQ5rJ54fJMTp7f0TZ7QOivwA05FvLQx5zVpwYi9CCKonrsFFQpgII6@YdBgIfNdJaz4JQ6mzsvyUtMrWKcaI3YwUVgvFw3b7l6VrVpFTqY@5YebTDATVc1gaa6ojKebVXaFdRV3OvfS8kDadmfvvzYEpvPY3BbNJlUnN1RfcNacrZ0pb0a2/ "J ‚Äì Try It Online")
Uses a single fold to explicitly sort each rank, in order. Requires an explicit verb since rank `"` is a conjunction.
*Note: Could save 1 byte with `{{ }}` but it fails on TIO's J version.*
# [J](http://jsoftware.com/), 23 17 bytes, port of Adam's recursive APL solution
```
[:/:~$:^:(#@$)"_1
```
[Try it online!](https://tio.run/##XY/BigIxEETv8xWFKzgDrU4mZkwaFGFhT3vaa4geZGXZi3/gr4/dSRQUElLpvKru/E@z1eKCHWMBQg@WvVzh8@f7a4q85tucj9x@HObd7GSmrvk9/11xQRtgiAe4jrj1cMRWdCP@vokxmp6khpAIcSRsZCXVcSDI3aq2chKGUhfl5Um1ydYxpYTlHhpWC8Ujdv/MsjWryLHUN7lh5nUGguklTMca60hGeLMtdKhoyLmPng/S65m5d28O1PDa3xXMqyqTupcvhFfOVs6Vtk033QE "J ‚Äì Try It Online")
*-6 thanks to ovs!*
[Answer]
# Haskell + [hgl](https://gitlab.com/WheatWizard/haskell-golfing-library), 15 bytes
```
x=Fe<sr<m x*~|p
```
Takes input as a free monad of lists.
## Explanation
In Haskell we use a free monad of lists. A very simplified definition would look like:
```
data Ragged a
  = Pur a
  | Fe [Ragged a]
```
It's either a terminal element (wrapped in `Pur`) or a list of more ragged lists (wrapped in `Fe`).
We could write the code then like:
```
x (Fe y)=
  Fe < sr < m x $ y
x (Pur y)=
  p y
```
In the `Fe` case we map `x` across the input to sort all lower levels, sort the result and wrap it back in a free.
In the pure case we just wrap it back in a pure using `p`.
Now hgl has a special operator to do this sort of case for us. We use the `*~|` operator which is the equivalent to a pattern match on the cases of a `Free`.
So now we rewrite both options as a function `Fe<sr<m x` and `p` and supply them as args to `*~|`.
We can't get rid of the `x=` this time because the definition is recursive.
## Reflections
Wow, I couldn't get this one in point free. That's probably an issue.
`hoF` for `hoistFree` *nearly* is useful here. If we just wanted to for example reverse every level `hoF rv` would work fine. But we can't just place `sr` in there instead of `rv`. `sr` needs the elements to be `Ord`. Instead we have to do this.
There should probably be a version of hoist which allows this sort of thing. Would save 9 bytes here.
```
maF ::
  ( Functor f
  , Functor g
  )
    => (f (Free g a) -> g (Free g a)) -> Free f a -> Free g a
```
[Answer]
# [BQN](https://mlochbaum.github.io/BQN/), 13 bytes[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)
```
‚ä¢{‚àß‚öáùï®ùï©}¬¥‚â°-‚Üï‚àò‚â°
```
[Run online!](https://mlochbaum.github.io/BQN/try.html#code=RiDihpAg4oqie+KIp+Kah/CdlajwnZWpfcK04omhLeKGleKImOKJoQo+KOKLiCDCtyBGIOKAokpzKcKo4p+oICJbIFsgWzUsIDEsIDRdLCAKICAgIFsxMCwgNywgMjFdIF0sIAogIFsgWzksIDIwLCAyXSwKICAgIFs0LCAyLCAxOV0gXSBdIgoiWzIsMV0iCiJbW1sxMCwgNSwgOV0sIFs2LCA0LCA0XV0sIFtbMiwgNiwgM10sIFszLCAzLCAyXV0sIFtbMywgOCwgNl0sIFsxLCA1LCA2XV1dIgoiW1tbNiwgOV0sIFsxMiwgMTddXSwgW1s5LCA2XSwgWzksIDhdXV0iCiJbW1s5LCAxXSwgWzIsIDVdXSwgW1s4LCA1XSwgWzMsIDVdXV0iCgrin6k=)
`{‚àßùïä‚çü‚â°¬®ùï©}` is a translation of J, `{√ó‚â°ùï©?‚àßùïä¬®ùï©;ùï©}` is a shorter direct translation of dyalog extended, but using the depth modifier is cooler.
-2 from Adam.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 15 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
"√êÀú√äi¬ÆŒ¥.V}{"¬©.V
```
[Try it online](https://tio.run/##yy9OTMpM/f9f6fCE03MOd2UeWndui15YbbXSoZV6Yf//R0dHm@koWMbqKEQbGukoGJrHgpjRljoKZiAGkLaIjY0FAA) or [verify all test cases](https://tio.run/##NY07DsIwEESvErkeRbEdO3GVW6SxXIBEkYoCCSlCtBRUiJoL0FBxgqRE4hBcxMzy2WZnd@fNrjeL5bDK27FTxetwLlQ3ZjWfHpf5OEy3573s9zs1Xcs@I0eWg0adEHWFBkYnyhhgKhiqGgY6JC6LSCUtitMh8OpRExXAwMNSWFhysrFo4SWWXv8NiAQE00xqfn/EEtD@DUF@MM19zi27ZHJK6Q0).
**Explanation:**
As mentioned in similar challenges, 05AB1E lacks recursive functions unfortunately, making it pretty long by mimicking the behavior with a string and 05AB1E-eval.
```
"..."       # Push the recursive string mentioned below
     ¬©      # Store it in variable `¬Æ` (without popping)
      .V    # Evaluate and execute it as 05AB1E code
            # (after which the result is output implicitly)
√êÀú√ä         # Check that this is the maximum depth of this (inner) list:
√ê           #  Triplicate the current list
 Àú          #  Flatten the top copy
  √ä         #  Check that the top two copies are NOT equal
   i    }   # If this is truthy, so we've reached the maximum depth:
     Œ¥      #  Map over each inner item:
    ¬Æ .V    #   Do a recursive call (by 05AB1E-evaluating string `¬Æ`)
         {  # Sort the list
```
[Answer]
# [Julia 1.0](http://julialang.org/), 22 bytes
```
!x::Int=x
!x=sort(.!x)
```
[Try it online!](https://tio.run/##XY/BjoMgEIbvPsXoCRNKSq2uNrH3PewTEA4kZRM3hBplN7y9ywBtosSEf4Zv/vn9@TWT4n7bSn@7fVo3@qL04/pcHGGlr7fv5wJmshomC4tWD9QrqQsIR1ENI@g/ZRj50k6xWS2rZmSdzeQIkhSq072q68TPy2SdsUTty/JQB9MRjs2KVXWh7WMTFwpcwukOglO4yEIIwc8UWgqDpCA6CtfwSdTIhrpB3YQb@dgPqg9PqHkc7aRMnuLdSDNhvH97NdkryS71r3Fh5DFDSHcOZhiry5E4Rv5I9JDRIfq@dr7IHu/IHWejIZrn/W3CelQpabv7hWHPNZlr09p/ "Julia 1.0 ‚Äì Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 49 bytes
```
‚äûœÖŒ∏Ôº¶œÖÔº¶ŒπÔº¶‚ÅºŒ∫‚Å∫‚ü¶‚üßŒ∫‚äûœÖŒ∫Ôº∑‚àßœÖ‚äüœÖ¬´‚âî‚ü¶‚üßŒ∑Ôº∑Œπ‚äûŒ∑‚äüŒπÔº∑‚ÅªŒ∑ŒπÔº¶‚ÑñŒ∑‚åäŒ∫‚äûŒπ‚åäŒ∫¬ªÔº©Œ∏
```
[Try it online!](https://tio.run/##VU7LCsIwEDzbr9hjAhF8o3gS8Sj0XnoovrI0bW1j9CB@e5y0FXUJ7GQeyRx01hyqzHgfO6uFU1TLdXSuGhJOUru537vaZcaKXFFsnBVJqiiXUtInmCP40GxOJDblMTBxdcUrsDyjwcZavpRtSsM46J3c53XnZvmj7bnEP1DAdhW2lStvgYHEhSvEtwD/kevoFcUNw7zN7E3UYLxPMOORormiFWokC0UznDTgZKII92nAU2xFk44HWkIKeNxGFynGD@/mDQ "Charcoal ‚Äì Try It Online") Link is to verbose version of code. Outputs using Charcoal's default output format, where depth 1 arrays print their elements on their own line but the arrays themselves are double-spaced from each other, then depth 2 arrays are triple-spaced from each other etc. Explanation:
```
‚äûœÖŒ∏
```
Start enumerating all of the arrays at each depth.
```
Ôº¶œÖÔº¶Œπ
```
Process all elements of each array.
```
Ôº¶‚ÅºŒ∫‚Å∫‚ü¶‚üßŒ∫‚äûœÖŒ∫
```
If this element is itself an array then push it to the list of all arrays.
```
Ôº∑‚àßœÖ‚äüœÖ¬´
```
Process the list in reverse order.
```
‚âî‚ü¶‚üßŒ∑Ôº∑Œπ‚äûŒ∑‚äüŒπ
```
Move the elements from this array into a temporary array.
```
Ôº∑‚ÅªŒ∑ŒπÔº¶‚ÑñŒ∑‚åäŒ∫‚äûŒπ‚åäŒ∫
```
Move them back in ascending order.
```
¬ªÔº©Œ∏
```
Output the final array.
[Answer]
# [Fig](https://github.com/Seggan/Fig), \$7\log\_{256}(96)\approx\$ 5.762 bytes
```
!#lxKMX
```
[See the README to see how to run this](https://github.com/Seggan/Fig/blob/master/README.md)
This answer uses that fact that programs = functions in Fig, so I can invoke the program from within the program.
```
!#lxKMX # Takes the list as input
!       # If
 #lx    # The input is a list
     M  # Map the list
      X # By this function (i.e. the program itself)
    K   # Then sort the resulting list
        # If the input is not a list, simply return the input
```
]


[Question]
      []