[Question]
  [
# The task
Write a program or function whose input is a list/array *X* of integers, and whose output is a list of sets of integers *Y*, such that for each element *e* in each set *Y*[*i*], *X*[*e*] = *i*, and such that the total number of elements in the sets in *Y* equals the number of elements in *X*.
(This is basically the same operation as reversing a hashtable/dictionary, except applied to arrays instead.)
# Examples
These examples assume 1-based indexing, but you can use 0-based indexing instead if you prefer.
```
X             Y
[4]           [{},{},{},{1}]
[1,2,3]       [{1},{2},{3}]
[2,2,2]       [{},{1,2,3}]
[5,5,6,6]     [{},{},{},{},{1,2},{3,4}]
[6,6,5,5]     [{},{},{},{},{3,4},{1,2}]
```
# Clarifications
* You may represent a set as a list, if you wish. If you do so, the order of its elements does not matter, but you may not repeat elements.
* You can use any reasonable unambiguous I/O format; for example, you could separate elements of a set with spaces, and the sets themselves with newlines.
* *Y* should be finitely long, and at least long enough to have all elements of *X* as array indexes. It may, however, be longer than the maximal element of *X* (the extra elements would be empty sets).
* The elements of *X* will all be valid array indices, i.e. non-negative integers if you use 0-based indexing, or positive integers if you use 1-based indexing.
# Victory condition
As a [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") challenge, shorter is better.
  
[Answer]
# [MATL](https://github.com/lmendo/MATL), 8 bytes
```
tn:IXQ&D
```
Input is a column vector, with `;` as separator (for example `[2;2;2]`). Output is the string representation of a cell array of row vectors (for example `{[]; [1 2 3]}`). A row vector of a single element is the same as a number (so `{1; 2; 3}` would be output instead of `{[1]; [2]; [3]}`).
[Try it online!](https://tio.run/nexus/matl#@1@SZ@UZEajm8v9/tJm1mbWptWksAA "MATL ‚Äì TIO Nexus") Or [verify all test cases](https://tio.run/nexus/matl#S/hfkmflGRGo5vLfJeR/tEksV7ShtZG1MZA2AtJGQNrU2tTazNoMyAKSQLZpLAA).
### Explanation
```
t     % Implicit input, say x. Duplicate
n     % Number of elements, say N
:     % Range: [1 2 ... N]
IXQ   % accumarray(x, [1 2 ... N], [], @(x){sort(x).'})
&D    % String representation
```
Most of the work is done by Matlab's higher-order function `accumarray`, which groups elements in the second input according to matching values in the first, and applies a specified function to each group. The function in this case is `@(x){sort(x).'}`, which outputs the sorted elements in each group and causes the results for all groups to be packed in a cell array.
[Answer]
# Python, 69 bytes
```
lambda s:[[j for j,x in enumerate(s)if x==i]for i in range(max(s)+1)]
```
Uses 0-based indexing.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~7~~ 5 bytes
```
=√æ·πÄT‚Ç¨
```
[Try it online!](https://tio.run/nexus/jelly#@297eN/DnQ0hj5rW/D/cDiQVjk56uHMGiBGp8HDH9kcNcxR8EwsUSjJSFXIy87J1FJLz88pSi0oUSvIVAipLMvLz1IsVikuKMvPSFYpSC4pSi1PzShJLMvPzdBSKUwsSixJLUhWSKhXyUsuB@lOL9f7/jzaJ1VGINtQx0jEGMYyADCMQw1THVMdMxwzEBFJAjmksAA "Jelly ‚Äì TIO Nexus")
### How it works
```
=√æ·πÄT‚Ç¨  Main link. Argument: A (array)
  ·πÄ    Yield m, the maximum of A.
=√æ     Equals table; for each t in [1, ..., m], compare all elemnts of A with t,
       yielding a 2D Boolean array.
   T‚Ç¨  Truth each; for each Boolean array, yield all indices of 1.
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes
```
J·∫ã"·π¨‚Ç¨;"/
```
[Try it online!](https://tio.run/nexus/jelly#@@/1cFe30sOdax41rbFW0v///3@0mY6ZjomOSSwA "Jelly ‚Äì TIO Nexus")
## How it works
```
J·∫ã"·π¨‚Ç¨;"/  argument: z           eg. [6,6,4,4]
J         [1 .. len(z)]             [1,2,3,4]
   ·π¨‚Ç¨     untruth each of z         [[0,0,0,0,0,1],
                                     [0,0,0,0,0,1],
                                     [0,0,0,1],
                                     [0,0,0,1]]
 ·∫ã"       repeat each of ^^         [[[],[],[],[],[],[1]],
          as many times as           [[],[],[],[],[],[2]],
          each of ^                  [[],[],[],[3]],
                                     [[],[],[],[4]]]
       /  reduce by...
     ;"   vectorized concatenation  [[],[],[],[3,4],[],[1,2]]
```
[Answer]
## Mathematica, 36 bytes
```
Join@@@#~Position~n~Table~{n,Max@#}&
```
## Explanation
[![enter image description here](https://i.stack.imgur.com/LRfYZ.png)](https://i.stack.imgur.com/LRfYZ.png)
For each `n` in `{1, 2, ..., Max@#}`, where `Max@#` is the largest integer in the input list, computes the `Position`s where `n` appears in the input list `#`. Since `Position[{6,6,5,5},5]` (for example) returns `{{3},{4}}`, we then `Apply` `Join` to all elements at level `{1}` of the result.
[Answer]
# [Haskell](https://www.haskell.org/), 45 bytes
`s` takes a list of integers and returns a list of lists. 1-indexed to keep the test case inputs unmodified (although the output gets some extra empty lists).
```
s l=[[i|(i,y)<-zip[1..]l,y==x]|x<-[1..sum l]]
```
[Try it online!](https://tio.run/nexus/haskell#HYhBCoMwEEX3nsJFFwrjgGnjypwkzCLYQAeSVIxSLd49Trv5770fHSfDafWLm9bblgInnzG6ucmv9wczLt49W/zfJdfBWMtnw3C0Y/fl2faIFOAwZqdzH7tf5y3WgagU@6DK9qDgLlRCJdSgYYBBTFZcU3UB "Haskell ‚Äì TIO Nexus")
These are pretty straightforward nested list comprehensions. The only slight tweak is taking advantage of the option to make a longer list by using `sum` instead of `maximum`.
[Answer]
# PHP, 55 bytes
```
<?while($i<=max($_GET))print_r(array_keys($_GET,$i++));
```
0-indexed.
[Answer]
# R, ~~68~~ ~~49~~ 47 bytes
```
lapply(1:max(x<-scan()),function(y)which(y==x)) 
```
Surprisingly, a lot more straightforward than the longer solutions. Takes a vector `x` from STDIN, creates a vector from `1` to `max(x)`, implicitly generates a list of length `max(x)`, and checks which indices in `x` correspond with those in the new list. Implicitly prints output.
## Older version:
```
o=vector('list',max(x<-scan()));for(i in x)o[[i]]=c(o[[i]],F<-F+1);o
```
Slightly different approach to the other R answer. Takes a vector to STDIN, creates a list with length equal to the maximum value in the input. Loops over the input and adds the index into the right place.
Uses 1-based indexing.
[Answer]
# [Python 2](https://docs.python.org/2/), ~~91~~ ~~86~~ 85 bytes
I am programming on my phone but I really liked this challenge. I can most definitely golf this further.
```
def f(a):
 r=[[]for i in range(max(a)+1)]
 for i,j in enumerate(a):r[j]+=[i]
 print r
```
[Try it online!](https://tio.run/nexus/python2#JYtBCsMwDATvfoWONvElbppDIS8ROhgqBwfiFpFCf@/INiyI0ezWNydINrqXAdkQKX0EMuQCEsvO9ox/ldPsyEBX/miSy@9kiRe3peBB04ZZK1/J5QKpyeJCzuiZPQQPjwGhQxjw9KBZNYPXDu1Lrt4 "Python 2 ‚Äì TIO Nexus")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
·π¨+\·ªãƒ†»ß@"·π¨
```
1-indexed, empty sets represented as `0`, sets of one item represented as `N` sets of multiple items represented as `[M,N,...]`
**[Try it online!](https://tio.run/nexus/jelly#@/9w5xrtmIe7u48sOLHcQQnI@///f7SZjpmOiY5JLAA "Jelly ‚Äì TIO Nexus")**
### How?
```
·π¨+\·ªãƒ†»ß@"·π¨ - Main link: list a        e.g. [6,6,4,4]
·π¨         - untruth a                     [0,0,0,1,0,1]
  \       - cumulative reduce with:
 +        -   addition                    [0,0,0,1,1,2]
    ƒ†     - group indices of a by value   [[3,4],[1,2]]
   ·ªã      - index into                    [[1,2],[1,2],[1,2],[3,4],[3,4],[1,2]]
        ·π¨ - untruth a                     [0,0,0,1,0,1]
       "  - zip with:
     »ß@   -   and with reversed @rguments [0,0,0,[3,4],0,[1,2]]
```
[Answer]
## JavaScript (ES6), ~~64~~ 62 bytes
*Saved 2 bytes thanks to @SteveBennett*
---
Takes 0-indexed input. Returns a comma-separated list of sets.
```
a=>a.map((n,i)=>o[n]=[i,...o[n]||[]],o=[])&&`{${o.join`},{`}}`
```
### Test cases
```
let f =
a=>a.map((n,i)=>o[n]=[i,...o[n]||[]],o=[])&&`{${o.join`},{`}}`
console.log(f([3]))
console.log(f([0,1,2]))
console.log(f([1,1,1]))
console.log(f([4,4,5,5]))
console.log(f([5,5,4,4]))
```
---
### Alternate version, 53 bytes
If a simplified output such as `'||||3,2|1,0'` is acceptable, we can just do:
```
a=>a.map((n,i)=>o[n]=[i,...o[n]||[]],o=[])&&o.join`|`
```
[Answer]
# [Bash](https://www.gnu.org/software/bash/), 109 bytes
Too bad there is no built-in for array max value.
```
a=($@)
for((x=m=1;x<=m;x++)){ for((y=0;y<$#;)){((m<a[y]))&&((m=a[y]));((a[y++]==x))&&printf "%d " $y;};echo;}
```
[Try it online!](https://tio.run/nexus/bash#@59oq6HioMmVll@koVFhm2traF1hY5trXaGtralZrQAWrrQ1sK60UVG2BopoaOTaJEZXxmpqqqkB2bYQtrWGBpChrR1ra1sBkikoyswrSVNQUk1RUFJQqbSutU5Nzsi3rv3//78ZEJr@NwUA "Bash ‚Äì TIO Nexus")
[Answer]
## Mathematica 62 bytes
```
(Y={}~Table~Max@#;Y[[#[[j]]]]~AppendTo~j~Table~{j,Tr[1^#]};Y)&
```
I'll run it for you
```
(Y={}~Table~Max@#;Y[[#[[j]]]]~AppendTo~j~Table~{j,Tr[1^#]};Y)&[{4,5,2,3,3,8,6,3}]
```
> 
> {{}, {3}, {4, 5, 8}, {1}, {2}, {7}, {}, {6}}
> 
> 
> 
[**Try it online**](https://sandbox.open.wolframcloud.com/app/objects/) (just paste the code with ctrl-v and press shift+enter)  
don't forget to paste the input list at the end like in the example above
[Answer]
# [Perl¬†6](https://perl6.org), ~~¬†36 32¬†~~ 29 bytes
```
->\a{map {a.grep(*==$_):k},1..a.max}
```
[Try it](https://tio.run/nexus/perl6#bZDRboIwFIbv@xTnYq6AtQZULmQYH2CXu4NmabQaMlBiwWgIe3V32qpziwRKTv/v/Kf9W63gGPNVQqozvK72awXpZbTIZVfJGjrJtwdVe0Gavnz686@ehZxLXslTf0F@2SjdQAplsVPa83G/nncEoJrrMf4AaEbhG6igsHwrdnXbLJD28vXQD2AAlNG/lK0AWXWq1apRa4tfd5HrLNcbt6MsW6Wf2gE8lOOEwH24OaA3DHz@XuiGPYyxQnAzddUodJxbSU9ajOoDL5yQupQ7GNrbJ2SzP1yDGC3wMHYSy2/WPthAzpAflG5Lk5YJ2bOYszYnLDQ4ncGtk0FmIcG3CPFN1Xh0EMbaBOFjDplrcHJC@ks2FfD7ZF3Prm/YC5KFLGITcRdD3I/wmxgtQi0Sj42WNtKMzVjMYvHf0zHGgE0NhwySs2ecIRwtfgA "Perl 6 ‚Äì TIO Nexus")
```
{map {.grep(*==$^a):k},1.. .max}
```
[Try it](https://tio.run/nexus/perl6#bZDRboIwFIbv@xTnYq6AtQZULmQYH2CXu8MuIVoNGSixYDSke3V32qpjiwRKTv/v/Kf9WyXhFPN1QqoLvK4PGwnptavyGjq@O8raC9L05TP351@ahZwDr/KzviK7bKRqIIWy2Evl@bhfzzsCUM3VGH8ANKPwDVRQWL4V@7ptFkh7q83QD2AAlNG/lK0AWXmu5bqRG4vfdpHrLKeN2ykvW6me2gH0ynFC4DHcHNAbBj5/L1TDemOsENxNXTUKHedWokmLMX3ghRNSl/kehvb2CdkejrcgRgs8jJ3EVndrH2wgF1gdpWpLk5YJ2LOYszYnLBQ4ncG9k0FmIcF3CPFt1Xh0EMbKBOFjDplrcHJC9DWbCvh9sk6z2xtqQbKQRWwiHmKI@xF@E6NFqEWi32hpI83YjMUsFv89HWMM2NRwyCA5e8YZwtHiBw "Perl 6 ‚Äì TIO Nexus")
```
{map {.grep($^a):k},1.. .max}
```
[Try it](https://tio.run/nexus/perl6#bZDfboIwFMbv@xTnYq78qTWgciHT@AC73B12CdFqyECJBaMh3au701YdWyRQcvr9znfar1USTglfp6S6wOv6sJEwv3ZVXkPHd0dZey@fuT/70iziHHiVn/UVwWUjVQNzKIu9VJ6P@/WsIwDVTI3wB0AzCt9ABYXlW7Gv22aBtLfahH4AA6CM/qVsBcjKcy3XjdxY/LaLXGc5bdxOedlK9dQOoFeOUgKP4eaAXhj4/L1QDeuNsUJwN3XVMHKcW4kmLWb0gRdOSV3mewjt7VOyPRxvQQwXeBg7ia3u1j7YQC6wOkrVliYtk65nMWdtTlgocDqDeyeDzEKC7xDi26rx6CBKlAnCxxwy1@DklOhrNhHw@2SdZrc30oJkEYvZWDzECPdj/MZGi1GLRb/R0kaasilLWCL@ezrGGLCJ4ZBBcvqMM4SjxQ8 "Perl 6 ‚Äì TIO Nexus")
---
## Expanded:
```
{  # bare block lambda with implicit parameter ÔΩ¢$_ÔΩ£
  map
    {  # bare block lambda with placeholder parameter ÔΩ¢$aÔΩ£
      .grep(  # grep for the values in ÔΩ¢$_ÔΩ£
        $^a   # that are equal to the currently tested value (and declare param)
      ) :k    # return the key (index) rather than the value
    },
    1 .. .max # Range from 1 to the maximum value in ÔΩ¢$_ÔΩ£
}
```
---
Returns zero based indexes, to get 1 based [use cross operator (`X`) combined with `+` op](https://tio.run/nexus/perl6#bZBRb4IwFIXf@yvOwxwgXRdQeZBp/AF73MMS7BKi1ZCBEgtGQ9hfd7dFnS4SKGnPd8@9PbVW2EdiEbPiiOfFdqkwOTVFWqIJ8OmL9U6V7tNX6o2/Wx4IAVGkh/ZE8KxSusIEebZR2vXovBw3DCjG@pV@gJM4@IEjHczesk1ZV1Oi3fnS9/roweHOPWV3IFYdSrWo1NLi51PiGsu1xm2f5rXSD@2Am@1rzHBtbgZ0/b4n3jNd8Zs2VuhfTO@wbmUtqymmD7pvzMo83cC3l4/Zars75/AypVlsIz6/OHuweRwx3yld5yYsE7Brsc7aDJhpdDrHpZIjsZAUa4LEqqhcpxdE2uTgUQxJV9DJMWtPyVDi70malp/foJUsCXjIB/IqBnQe0jcwWkhaKG8LLW2kER/xiEfyv2fHGAM@NBwxRI4ecYboaPkL "Perl 6 ‚Äì TIO Nexus"). (33¬†bytes)
```
{1 X+.grep($^a):k}
```
To get it to return [Set](https://docs.perl6.org/type/Set)s just [add `set`](https://tio.run/nexus/perl6#bZDRboIwFIbv@xTnYq4gXRdQuZBpfIDdbRdLsEuIVkMGSmwxGtK9ujtt1blFAiE9/3f@c/q3SsI@5YuM1Ed4XGyXEianri4a6JTUEMNHxNc72QQPn0U4/jIs5hx4XRzMCRtmWioNE6jKjVRBiPVm3BGAeqye8QdAcwrfQAWF2Uu5aVo9RTqYL6OwDz2gjP6l3AmQlYdGLrRcOvxcRa5znLFu@6JqpbprB3BzfM4IXIfbBYOoH/LXUml2M8YJ/YvpFXuT2rPEkBaTesfrZqSpig1E7u4ZWW135xiepriKm8PmF@MQXBxHmO@kaiublc04cJi3tvuVCrzO4NLJIHeQ4GuE@KrWAe3FqbIxhJhC7hu8nBFzyocCfp@8M@z8xkaQPGYJG4irGGM9wW9gtQS1RNw2OtpKIzZiKUvFf0/PWAM2tBwySI7ucZbwtPgB "Perl 6 ‚Äì TIO Nexus") in there (total¬†37¬†bytes)
```
{set 1 X+.grep($^a):k}
```
[Answer]
# [R√∂da](https://github.com/fergusq/roda), 51 bytes
```
f s{seq(1,max(s))|[[s()|enum|[_2+1]if[_1=i]]]for i}
```
It's a port of the [Python answer by Uriel](https://codegolf.stackexchange.com/a/119868/66323).
Another version (88 bytes):
```
f a{I=indexOf;seq(1,max(a))|{|i|b=a[:]c=[]x=1{c+=x+I(i,b)b-=i;x++}until[I(i,b)<0];[c]}_}
```
[Try it online!](https://tio.run/nexus/roda#PZDNboMwEITP8BSjnCC4zU9LDqHunVMuuVlWZYxpLIFpwahUhGdPFyH14vl25Z0de7cNscX1ZtCoEdXgtLetw4/qYZ3v2nLQpkRhqrYz8HRN31RdG/dpGIrBw/ZwrQeNXPMLfo1/Jr9d@G9ErpGKMYVBgzPHflEOC/Kj0zoo2AqC@B0NZBh0xg8dzYXzo4Kacm5dacZLlfXmOzqw1S@@T3d7L7gSZ6m5kCM/TDrhY5JHlhVx8cRtNibJPDhva7E23/YyE1rOH/OjUbSYIi0hvF5SiDAIxKtkixzYkb2seCQ8rpiylJ3YaS0IqEwprkTZUqeKvI5Jvzr6tWizIS5bZ@gRfw "R√∂da ‚Äì TIO Nexus")
Both a 1-indexed.
[Answer]
# R, ~~80~~ 72 bytes
1-indexed, takes `X` from stdin. Returns a list of vectors of the indices, with `NULL` as the empty set.
```
X=scan();Y=vector('list',max(X));Y[X]=lapply(X,function(x)which(X==x));Y
```
[Try it online!](https://tio.run/nexus/r#@x9hW5ycmKehaR1pW5aaXJJfpKGek1lcoq6Tm1ihEaEJFI@OiLXNSSwoyKnUiNBJK81LLsnMz9Oo0CzPyEzO0Iiwta0AqfpvqmCqYKZg9h8A)
old version:
```
X=scan();Y=vector('list',max(X));for(i in 1:length(X))Y[[X[i]]]=c(Y[[X[i]]],i);Y
```
[Try it online!](https://tio.run/nexus/r#@x9hW5ycmKehaR1pW5aaXJJfpKGek1lcoq6Tm1ihEaGpaZ0GFMpUyMxTMLTKSc1LL8kAiUZGR0dEZ8bGxtoma8DZOplAU/6bKpgqmCmY/QcA)
[Answer]
## PowerShell, 81 bytes
```
$args[0]|%{if($_-gt($c=$r.count)){$r+=@($t)*($_-$c)}$r[--$_]+=,++$i};$r|%{"{$_}"}
```
[Try it online!](https://tio.run/nexus/powershell#FctLCoAgFAXQvcQNNJ/Rh5qE0D4iJISiScHLRubarcaHk7Dwdk3V/ORhXwWs3ryAM@DSnffhpQxgZUYBL4uf4WQET1rDzsqQUtjjAP56FmBjFlNKdUU9ddRS8wI)
1-indexed.
[Answer]
# [GNU Make](https://www.gnu.org/software/make/), ~~214~~ ~~213~~ ~~208~~ 204 bytes
```
X=$(MAKECMDGOALS)
M=0
P=$(eval N=$(word $1,$X))$(if $N,$(if $(shell dc -e$Nd$Mds.\>.p),$(eval M=$N),)$(eval A$N+=$1$(call $0,$(shell expr $1 + 1))),)
$(call P,1)$(foreach K,$(shell seq $M),$(info $(A$K)))
```
I/O: input array via arguments, output to stdout, one per line, separated by spaces.
```
$ make -f swap.mk 2 2 2
3 2 1
make: *** No rule to make target `2'.  Stop.
```
## Explanation
```
X=$(MAKECMDGOALS)     # Input array
M=0                   # Max value encountered in X
P=$(eval
    N=$(word $1,$X))  # Get next word from X
  $(if $N,$(if $(shell dc -e$Nd$Mds.\>.p),
    $(eval M=$N),)    # Update M
    $(eval A$N+=$1    # Append index to a variable named after value
      $(call $0,      # Recurse (call returns empty string)
        $(shell expr $1 + 1))),)
$(call P,1)           # Initial call to P. 1 is the first index
$(foreach K,          # Print all values of A* variables
  $(shell seq $M),
  $(info $(A$K)))     # Uninitialized ones default to empty strings
```
The order of indices in sets is reversed because `P` calls itself recursively before updating `A$2` (call executed in the evaluation of the right-hand side).
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 10 bytes
```
ZFƒÅ¬πN-√èÀÜ}¬Ø
```
[Try it online!](https://tio.run/nexus/05ab1e#@x/ldqTx0E4/3cP9p9tqD63//z/aTMdMx1THNBYA "05AB1E ‚Äì TIO Nexus")
[Answer]
# Common Lisp, 91 bytes
```
(lambda(x &aux(l(make-list(eval`(max,@x))))(i 0))(dolist(y x l)(push(incf i)(nth(1- y)l))))
```
1-based indexing, returns the sets as lists.
[Try it online!](https://tio.run/##HYpBDoJAEAS/0iftTSTRA5x9iiNgmDisG1nI8Pp1sQ@dVKp60yUVpq/GDBaazM9B6DjJ6jTO8h6b2mSOm9ijsl/uHuqouNYfPn@7w2GBaV0mauxf0MCYJ94a7MGOvpzZokWH7oAf)
[Answer]
# [k](https://en.wikipedia.org/wiki/K_(programming_language)), 13 bytes
```
{(=x)@!1+|/x}
```
This is 0-indexed.
[Try it online!](https://tio.run/##y9bNz/7/P82qWsO2QtNB0VC7Rr@i9n@aup6VuoGVkn5Kapl@cUlKZp7Sfx1jLgMFQwUjLkMgachlomCiYKpgygXEQJYJAA "K (oK) ‚Äì Try It Online")
```
{           } /function(x)
 (=x)         /make a map/dictionary of values to their indices
         |/x  /get maximum value in x
      !1+     /make a range from 0 to the value, inclusive
     @        /get map value at each of the values in the range
              /    0N is given where there is no result
```
[Answer]
# [Uiua](https://uiua.org), 6 [bytes](https://codegolf.stackexchange.com/a/265917/97916)
```
‚äï‚ñ°‚à∂‚á°‚ßª.
```
[Try it!](https://uiua.org/pad?src=ZiDihpAg4oqV4pah4oi24oeh4qe7LgoKZiBbM10KZiBbMCAxIDJdCmYgWzEgMSAxXQpmIFs0IDQgNSA1XQpmIFs1IDUgNCA0XQo=)
0-indexed.
```
‚äï‚ñ°‚à∂‚á°‚ßª.
     .  # duplicate
    ‚ßª   # length
   ‚á°    # range
  ‚à∂     # swap
‚äï‚ñ°      # group by box
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 7 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
Output is 0-based.
```
r√î√µ@√∞¬∂X
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=ctT1QPC2WA&input=WzYsNiw1LDVdCi1R)
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 38 [bitsv2](https://github.com/Vyxal/Vyncode/blob/main/README.md), 4.75 bytes
```
G«í=vT
```
[Try it Online!](https://vyxal.pythonanywhere.com/?v=2&c=1#WyI9IiwiIiwiR8eSPXZUIiwiIiwiWzIsMiwyXSJd)
Bitstring:
```
01011011100001100011111110111100010001
```
Exact same algorithm as Jelly, independently discovered.
## Explained
```
G«í=vT¬≠‚Å°‚Äã‚Äé‚Å™‚Å™‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å™‚Äè‚Å†‚Å™‚Å™‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å¢‚Äã‚Äé‚Å™‚Å™‚Äè‚Äã‚Å¢‚Å†‚Å°‚Äå‚Å£‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å°‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å§‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å¢‚Å°‚Äã‚Äé‚Å™‚Å™‚Å†‚Å™‚Å™‚Äè‚Äã‚Å¢‚Å†‚Å°‚Äå‚Å¢‚Å¢‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å§‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å°‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå¬≠
 «í     # ‚Äé‚Å°Reduce pairs in the cartesian product of
# ‚Äé‚Å¢the input
G      # ‚Äé‚Å£and the maximum of the input
  =    # ‚Äé‚Å§by equality
# ‚Äé‚Å¢‚Å°This creates a list of [1s in places where input == x for x in range(max(input))]
   vT  # ‚Äé‚Å¢‚Å¢Get the indices of those 1s for each list
üíé
```
Created with the help of [Luminespire](https://vyxal.github.io/Luminespire).
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 73 bytes
```
x=>x.map((n,i)=>A[(g=n=>n&&g(n-1,A[n]=A[n]||[]))(n),n].push(i),A=[[]])&&A
```
[Try it online!](https://tio.run/##bcpBDsIgEIXhvQchQzIlou1ySDgHYUFqW2vqQIqaLnp3xK3p5i2@/z3CJ@R@ndOr4XgbykhlI7OpZ0gAjLMkYx1MxGRYiAm40Wgde/rNvjsvJbBE9iq98x1miZac814KYUsfOcdlUEucYAR3refTn51R4@XAdXV94C222GF3UKrW1tZSvg "JavaScript (Node.js) ‚Äì Try It Online")
]