[Question]
  [
Your challenge today is to write a program or function which takes a list `l` and gives the positions in `l` at which each successive element of `l` sorted appears.
In other words, output the index of the smallest value, followed by the index of the second smallest value, etc.
You can assume that the input array will contain only positive integers, and will contain at least one element. 
Test cases:
```
Input                  | Output (1-indexed)
[7, 4, 5]              | [2, 3, 1]
[1, 2, 3]              | [1, 2, 3]
[2, 6, 1, 9, 1, 2, 3]  | [3, 5, 1, 6, 7, 2, 4]
[4]                    | [1]
```
When two or more elements with the same value appear, their indices should appear next to each other from smallest to largest.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), fewest bytes wins!
  
[Answer]
# Dyalog APL, 1 byte
```
⍋
```
Dyalog APL has a built in operator function (thank you Zacharý for clearing this up) to do this.
## Example
```
⍋11 2 4 15
    2 3 1 4  
{⍵[⍋⍵]}11 4 2 15
    2 4 11 15
```
Here I'm indexing into the list by the sorted indices to return the list in ascending order.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 1 byte
```
Ụ
```
[Try it online!](https://tio.run/##y0rNyan8///h7iX/D7c/alrj/v9/dLS5joKJjoJprA6XQrShjoKRjoIxmA1kmOkoAEUswSRc3CQ2FgA "Jelly – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), ~~43~~ 42 bytes
`1`-indexed:
```
import Data.List
map snd.sort.(`zip`[1..])
```
[Try it online!](https://tio.run/##ZY7BCsIwEETv@Yo5thAD1ap48KRHhR6FWGzQRoNJDN2c/HhjKIKIe1jYecvM3BTde2uTceExRGxVVGJnKDKNNY7JqQDyF0EZiqJ7mtDJSoi2TLGnSPlHQi45ao55y/AZDllxTDlmP1oWFhyZrMb9x@vv1TLmlPHZPzfYn1CEwfgodIkxN73O2qorpclh0zRv "Haskell – Try It Online")
`-1` byte thanks to @ØrjanJohansen!
[Answer]
# [Python 2](https://docs.python.org/2/), 56 bytes
This solution is 0-indexed. This abuses the fact that `sorted()` creates a copy of the original list.
```
l=input()
for k in sorted(l):a=l.index(k);print a;l[a]=0
```
[Try it online!](https://tio.run/##K6gsycjPM/r/P8c2M6@gtERDkystv0ghWyEzT6E4v6gkNUUjR9Mq0TZHLzMvJbVCI1vTuqAoM69EIdE6Jzox1tbg//9oIx0FMx0FQx0FSzAJ5BrHAgA "Python 2 – Try It Online")
[Answer]
# Javascript (ES6), 39 bytes
-2 bytes thanks to @powelles
This only works in browsers where `Array.prototype.sort` is stable.
```
a=>[...a.keys()].sort((b,c)=>a[b]-a[c])
```
1-indexed version (47 bytes):
```
a=>a.map((_,i)=>i+1).sort((b,c)=>a[b-1]-a[c-1])
```
**Example code snippet:**
```
f=
a=>[...a.keys()].sort((b,c)=>a[b]-a[c])
console.log("7,4,5 => "+f([7,4,5]))
console.log("1,2,3 => "+f([1,2,3]))
console.log("2,6,1,9,1,2,3 => "+f([2,6,1,9,1,2,3]))
console.log("4 -> "+f([4]))
```
[Answer]
# [Python 2](https://docs.python.org/2/), 48 bytes
```
lambda x:sorted(range(len(x)),key=x.__getitem__)
```
[Try it online!](https://tio.run/##HcdRCoMwDADQq@QzgTKYgjDBk2yjVBq1TNNSI9TTV9nPg5dOXaI0dRo@dXXb6B2Ufo9Z2WN2MjOuLFiIzI/PoTysnVmD8mYt1ZSDKEwYJB2KRPXdGOgMPA28/t5tvxc "Python 2 – Try It Online")
[Answer]
# [Perl 6](https://perl6.org), ~~27~~ 21 bytes
```
*.pairs.sort(*.value)».key
```
[Test it](https://tio.run/##ZZBBasMwEEX3OsVfFTuVBU4ch2ISfIAuuyiELIw9BVE3FpZsYkpOll0v5o7lhJBWC6GZ//5oZgy1dTp2ltCnqszE14CnsqkI23GhTKFbq2zTumCh@qLuKPy5qE8aRg/mjqzDFoEA9huJRGJ9wMOR2C8lVhLxQU5ULDHF/6mb4Cl@pWyRePH31cEUF1r7FMsbLySzI/lT8V6X9TAT04Bv3G0mTF0c8Ty3Xukey0x8NO11lmiHXB9N5yRyOhkqHVX45g@0jSoiUw@YlhPMUKhetWU0uLPvEeJbeoaU4Q2L8/gL "Perl 6 – Try It Online")
```
->\x{sort {x[$_]},^x}
```
[Test it](https://tio.run/##ZZDBaoNAEIbv@xT/oRRDR8HEGIok@AA99lAwphSdgmDj4m6CQXx2O64JIe0elp35v392ZjS3dTyeDOMcB0Wifi54LpqSsR393b7rTdNa9F329JkPdOiG0SGpZWOxhaeAbEOICOscD4eQLQkrQpjTRIWEKf5P3QRHySsWC@HV3VeHUFJo7VIib5wQzY7oT8V7XdEXiZpGe5duE6XrryNe5tbL6oxlor6b9jqLv0NaHfXJElLuNBeWS/TyQWX8klnXF0xr8WZoEbxVRlDvzn74CG/pGQq07FYN4y8 "Perl 6 – Try It Online")
Inspired by a [Python answer](https://codegolf.stackexchange.com/questions/136637/get-the-indices-of-an-array-after-sorting/136656#136656)
## Expanded:
```
->    # pointy block lambda
  \x  # declare sigilless parameter
{
  sort
    { x[$_] },  # sort by the value in ｢x｣ at the given position
    ^x          # Range up-to the number of elements in ｢x｣
}
```
[Answer]
# Bash + coreutils, 20
```
nl|sort -nk2|cut -f1
```
[Try it online](https://tio.run/##S0oszvj/Py@npji/qERBNy/bqCa5FMhIM/z/34jLjMuQyxKIjbiMAQ).
[Answer]
# [Swift 4](https://github.com/apple/swift), 82 bytes
```
func f(l:[Int]){var l=l;for k in l.sorted(){let a=l.index(of:k)!;print(a);l[a]=0}}
```
[Test Suite.](http://swift.sandbox.bluemix.net/#/repl/597d9e77c5cfd27e04c56f0e)
## Explanation
In Swift, `l.sorted()` creates a sorted copy of the original Array. We loop through the sorted elements in the list and after printing each item's index in the original Array with `let a=l.index(of:k)!;print(a)`, and then, in order to keep the correct indexes in the Array, we assign `l[a]` to `0`, because it does not affect our normal output.
---
Take note that this is 0-indexed, since it is a port of my Python solution. If you want it to be 1-indexed, replace `print(a)` with `print(a+1)` or [Try it online!](http://swift.sandbox.bluemix.net/#/repl/597da09cc5cfd27e04c56f0f).
[Answer]
# [J](http://jsoftware.com/), 2 bytes
```
/:
```
[Try it online!](https://tio.run/##y/r/X98KhBXMFUwUTLmADEMFIwXj/2AuAA "J – Try It Online")
Zero-based indexing.
[Answer]
# [R](https://www.r-project.org/), 5 bytes
There is a builtin function for this.
```
order
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 40 bytes
```
->a{a.zip([*1..a.size]).sort.map &:last}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6xOlGvKrNAI1rLUE8vUa84syo1VlOvOL@oRC83sUBBzSonsbik9n@BQlp0tJGOgpmOgqGOgiWYBHKNY2P/AwA "Ruby – Try It Online")
[Answer]
# [Octave](https://www.gnu.org/software/octave/), 17 bytes
```
@(i)[~,y]=sort(i)
```
[Try it online!](https://tio.run/##y08uSSxL/f/fQSNTM7pOpzLWtji/qATI@Z@YV6yRmVdQWqKhrq6p@T/aSEfBTEfBUEfBEkwCucaxAA "Octave – Try It Online")
Octave is like MATLAB but with inline assignment, making things possible that gives the folks at Mathworks HQ headaches. It doesn't matter what you call `y`, but you can't do without that dummy variable, as far as I know.
[Answer]
# [Julia](https://julialang.org), 8 bytes
```
sortperm
```
[Attempt This Online!](https://ato.pxeger.com/run?1=nY8xTsMwGIXn-BRPmRzJRRTSlg6NWDlDlMFJ_7ZGqWvZjmDIJZhZulTiMhwgt8FJGiFg4x8s_e89f3r_--W5qZU8d5-7k4WC0rAkt7XS5HjCEEYKlNjAmVp5rgTiNk5YpLRpfJBzI60j_qT9MhX-5ih9dUjQw3wPI1kdBo3bmOe3s3WRxAIyKVhEr4YqT9v_QsoeIrV7IRsQY582Q0l7pS-N380ePtzJekP2OK5dFpHesshYpX2t-fWEDCMkHPUonSPrMVE3mEqy8HOknLu3fCWQCiwK_JgW-Z3AvcC8YPlcoF_-RiaD9eFlCAush_caD5GAWAxSsFeDkYZ4-ov1TSzGZl8)
[Answer]
# [MATL](https://github.com/lmendo/MATL), 2 bytes
```
&S
```
[Try it online!](https://tio.run/##y00syfn/Xy34//9oIx0FMx0FQx0FSzAJ5BrHAgA "MATL – Try It Online")
Input and output are implicit. 
[Answer]
# [MY](https://bitbucket.org/zacharyjtaylor/my-language/src/5984ac62a269d7a763c1ef664f5b7d745b7f9390?at=master), 3 bytes
MY also has a builtin for this!
```
⎕⍋↵
```
[Try it online!](https://tio.run/##y638//9R39RHvd2P2rb@/x9tqGOkY6xjomMQCwA)
### How?
Evaluated input, grade up, then output with a newline.
Indexed however you set the index, with `⌶`/`0x48`. (Can even be some weird integer like `-1` or `2`, the default is `1`).
[Answer]
# Java 8, 128 + 19 = 147 bytes
Based on Mr. Xcoder's [solution](https://codegolf.stackexchange.com/a/136643). 0-based. Lambda takes input as an `Integer[]` and returns `Integer[]`. Byte count includes lambda expression and required import.
```
import java.util.*;
```
```
l->{Integer o[]=l.clone(),s[]=l.clone(),i=0;for(Arrays.sort(s);i<l.length;)l[o[i]=Arrays.asList(l).indexOf(s[i++])]=0;return o;}
```
[Try It Online](https://tio.run/##VZBNS8NAEIbPya@Y465NFz9AkDQFL0JB8dBjyGFNtnHqdjbsTqql5LfHrUZLL8N8zzzvVu/13HWGts3HiLvOeYZtzKme0aqrPE27/s1iDbXVIcCLRoJjmnQe95oNBNYci@eJTU81oyP1NDmLFbFpjS@rDP7dJYR4yDQrarA2AYrRzpfHqQyurAqrauvICJmFiwiL63zjvHj0Xh@COq0RQea4sMoaavk9l7Z0JVbF1KHDMwYWViqkxny9bkQocTarZBU3ecO9J3D5MCYRNZlYJ6q9wwZ2kVis2SO1ZQXat0GeBEjWh8Bmp1zPKopBbOnvJ3a/7eKCUemuswdB5vMsAxxvM7jP4CaDhx8bw7tBSpmnyZAO4zc)
## Ungolfed lambda
```
l -> {
    Integer
        o[] = l.clone(),
        s[] = l.clone(),
        i = 0
    ;
    for (Arrays.sort(s); i < l.length; )
        l[o[i] = Arrays.asList(l).indexOf(s[i++])] = 0;
    return o;
}
```
## Notes
I use `Integer[]` instead of `int[]` to allow use of [`Arrays.asList`](http://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#asList-T...-), which has no primitive versions. `Integer` is preferred to `Long` because values are used as array indices and would require casting.
This ended up being shorter than my best procedural-style `List` solution because of the cost of class and method names.
This also beat a solution I tried that streamed the inputs, mapped to *(value, index)* pairs, sorted on values, and mapped to indices, mostly because of the baggage needed to collect the stream.
## Acknowledgments
* -5 bytes thanks to *Nevay*
[Answer]
# [Factor](https://factorcode.org/), 8 bytes
```
arg-sort
```
[Try it online!](https://tio.run/##bczBCoJAEAbg@z7F3wMkmJZUDyBdukSn6DDIJNKybrMbZOKzb6t0EZzDMMP/8T@o8q2E6@V0Lg9w/Hqzqdgl/PFCDlbY@85KYzyeLIY1ajYspJsv@aY1DkelehTIscWA2azQY4MMKYZI0uleIP9AjXgXv/2cjiSL5WkMixjkE40bN2CpbVCBpF67Vny4R2jIWt0hcag0k4Qf "Factor – Try It Online")
0-indexed
[Answer]
# Common Lisp, 82 bytes
```
(lambda(l)(loop as i in(sort(copy-seq l)'<)do(setf(elt l(print(position i l)))0)))
```
[Try it online!](https://tio.run/##DcsxCsMwDEbhq2jLr6HQJlAo9DJO4oBAsdRIS07veviWB29TCe/o0HKue4Ey1MypBAlJQ9iV2MzvR9QfKU9f3g1R80DVJIVf0hJuISnWxqTM/Bz6hJne9KLPMNMyyh8)
[Answer]
## Clojure, 39 bytes
```
#(map key(sort-by val(zipmap(range)%)))
```
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 12 bytes
```
{ee{1=}$0f=}
```
[Try it online!](https://tio.run/##S85KzP1fWPe/OjW12tC2VsUgzbb2f13C/2gjBTMFQwVLIDZSMI4FAA "CJam – Try It Online")
[Answer]
# MATLAB / [Octave](https://www.gnu.org/software/octave/), 29 bytes
```
[~,y]=sort(input(''));disp(y)
```
[Try it online!](https://tio.run/##y08uSSxL/f8/uk6nMta2OL@oRCMzr6C0RENdXVPTOiWzuECjUhMobaSjYKajYKijYAkmgVzjWAA "Octave – Try It Online")
[Answer]
## JavaScript (ES6), 69 bytes
0-indexed. Works for lists containing up to 65,536 elements.
```
a=>[...a=a.map((n,i)=>n<<16|i)].sort((a,b)=>a-b).map(n=>a.indexOf(n))
```
### Test cases
```
let f =
a=>[...a=a.map((n,i)=>n<<16|i)].sort((a,b)=>a-b).map(n=>a.indexOf(n))
console.log(JSON.stringify(f([7, 4, 5])))
console.log(JSON.stringify(f([1, 2, 3])))
console.log(JSON.stringify(f([2, 6, 1, 9, 1, 2, 3])))
console.log(JSON.stringify(f([4])))
```
[Answer]
# [Python 3](https://docs.python.org/3/), 52 bytes
0-indexed. Based on [Bruce Forte's Haskell answer here](https://codegolf.stackexchange.com/a/136639/47581) and [G B's Ruby answer here](https://codegolf.stackexchange.com/a/136765/47581).
```
lambda l:list(zip(*sorted(zip(l,range(len(l))))))[1]
```
[Try it online!](https://tio.run/##HcZNCoAgEEDhq7QcYzZlPxB0knJhaCVMJjqburyFb/O@8PB5e5n3ec2kr83oiiZyieF1Aep0R7ammDBqf1gg64FEaWlUDtF5hh0WiR1K7LEtb3DA8XevhMgf "Python 3 – Try It Online")
[Answer]
# [Husk](https://github.com/barbuz/Husk), ~~10~~ 7 bytes
This is a direct port of my [Haskell answer](https://codegolf.stackexchange.com/a/136639/48198), also `1`-indexed:
```
m→O`z,N
```
[Try it online!](https://tio.run/##yygtzv7/P/dR2yT/hCodv////0cb6ZjpGOpYArGRjnEsAA "Husk – Try It Online")
### Ungolfed/Explained
```
Code        Description               Example
         -- implicit input            [2,6,1]
      N  -- natural numbers           [1,2,3,..]
   `z,   -- zip, but keep input left  [(2,1),(6,2),(1,3)]
  O      -- sort                      [(1,3),(2,1),(6,2)]
m→       -- keep only indices         [3,1,2]
```
[Answer]
# [Java (OpenJDK 8)](http://openjdk.java.net/), 72 bytes
```
l->l.stream().sorted().map(i->{int j=l.indexOf(i);l.set(j,0);return j;})
```
[Try it online!](https://tio.run/##fVLLTsMwEDzHX7FHG6UWbwRpI3FBqgTiwBFxMIlTOU2cyHZKS9VvD5tHaVpaLn7szs6Ox5uKhRgVpdRpPK9VXhbGQYoxXjmV8bOA/IkllY6cKjR/6g9HMNYZKXL@1m4BIWX1makIokxYCy9CabImXh@0TjjcFoWKIccUxSqlZ@8fIMzMMuIh1Csx5GiEdE4@GiNWz8o6eufDtQ83jAUnIZc@3Ppw4cN9u@L16j/4ELIhHmlgC0RsVf4ix1Pt5EyaEA4pkJZzDqpXfqRCwAS0/BqQhbTVlBQGmnpYwgMSeIKLOKbLNmekq4wGcUJYa1/3pmMdezFvK@tkzovK8Rab6Q5tuSs626lV33KqY7mkgmG0TVM2MGTv17of3jXaVR9RMe9VbAdnvJf2D8lCSNCoOhuF24GijFscNBnjIRclVaNw3diVTjKumq6vCVUsQLh0NPXPWdC7lgYbVg9cTLgoy2xF592zNqT@AQ "Java (OpenJDK 8) – Try It Online")
Takes a `List<Integer>`, returns a `Stream<Integer>` containing the results.
We get a Stream based off the initial list, sort it, then map each number to it's index in the list. In order to accommodate duplicate elements, we set the original element in the list to `0`.
[Answer]
# SmileBASIC, 67 bytes
```
DEF I(A)DIM B[0]FOR I=1TO LEN(A)PUSH B,I
NEXT
SORT A,B
RETURN B
END
```
Very simple, all it does is generate a list of numbers from 1 to (length of array) and sort this by the same order as the input.
[Answer]
# [Python 3](https://docs.python.org/3/) with [Numpy](http://www.numpy.org/), ~~38~~ 26 bytes
*12 bytes saved thanks to [Jo King](https://codegolf.stackexchange.com/users/76162/jo-king) (no need to give the function a name)*
```
import numpy
numpy.argsort
```
Output is 0-based.
[Try it online!](https://tio.run/##K6gsycjPM/7/PzO3IL@oRCGvNLegkgtM6iUWpRcDxf6nKdgqoIhwFRRl5pVopGlEG@komOkoGOooWIJJINc4VlPzPwA "Python 3 – Try It Online")
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 1 byte
```
⇧
```
[Try It Online!](https://vyxapedia.hyper-neutrino.xyz/tio#WyIiLCLih6ciLCIiLCIiLCJbMiwgNiwgMSwgOSwgMSwgMiwgM10iXQ==)
0-indexed
[Answer]
# [Thunno 2](https://github.com/Thunno/Thunno2), 1 [byte](https://github.com/Thunno/Thunno2/blob/main/docs/codepage.md)
```
ƙ
```
[Try it online!](https://Not-Thonnu.github.io/run#aGVhZGVyPSZjb2RlPSVDNiU5OSZmb290ZXI9JUUyJTgxJUJBJmlucHV0PSU1QjclMkMlMjA0JTJDJTIwNSU1RCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMC0lM0UlMjAlNUIyJTJDJTIwMyUyQyUyMDElNUQlMEElNUIxJTJDJTIwMiUyQyUyMDMlNUQlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAtJTNFJTIwJTVCMSUyQyUyMDIlMkMlMjAzJTVEJTBBJTVCMiUyQyUyMDYlMkMlMjAxJTJDJTIwOSUyQyUyMDElMkMlMjAyJTJDJTIwMyU1RCUyMCUyMC0lM0UlMjAlNUIzJTJDJTIwNSUyQyUyMDElMkMlMjA2JTJDJTIwNyUyQyUyMDIlMkMlMjA0JTVEJTBBJTVCNCU1RCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMC0lM0UlMjAlNUIxJTVEJmZsYWdzPUM=)
Same as the other golflangs - built-in for "grade up".
]