[Question]
  [
Suppose we have an array \$\texttt{ps}\$ of length \$n\$ with pointers pointing to some location in the array: The process of "[*pointer jumping*](https://en.wikipedia.org/wiki/Pointer_jumping)" will set every pointer to the location the pointer it points to points to.
For the purpose of this challenge a pointer is the (zero-based) index of an element of the array, this implies that every element in the array will be greater or equal to \$0\$ and less than \$n\$. Using this notation the process can be formulated as follows:
```
for i = 0..(n-1) {
  ps[i] = ps[ps[i]]
}
```
This means (for this challenge) that the pointers are updated in-place in sequential order (ie. lower indices first).
## Example
Let's work through an example, \$\texttt{ps = [2,1,4,1,3,2]}\$:
$$
\texttt{i = 0}: \text{the element at position }\texttt{ps[0] = 2}\text{ points to }\texttt{4} \\ \to \texttt{ps = [4,1,4,1,3,2]} \\
\texttt{i = 1}: \text{the element at position }\texttt{ps[1] = 1}\text{ points to }\texttt{1} \\ \to \texttt{ps = [4,1,4,1,3,2]} \\
\texttt{i = 2}: \text{the element at position }\texttt{ps[2] = 4}\text{ points to }\texttt{3} \\ \to \texttt{ps = [4,1,3,1,3,2]} \\
\texttt{i = 3}: \text{the element at position }\texttt{ps[3] = 1}\text{ points to }\texttt{1} \\ \to \texttt{ps = [4,1,3,1,3,2]} \\
\texttt{i = 4}: \text{the element at position }\texttt{ps[4] = 3}\text{ points to }\texttt{1} \\ \to \texttt{ps = [4,1,3,1,1,2]} \\
\texttt{i = 5}: \text{the element at position }\texttt{ps[5] = 2}\text{ points to }\texttt{3} \\ \to \texttt{ps = [4,1,3,1,1,3]}
$$
So after **one iteration** of "*pointer jumping*" we get the array \$\texttt{[4,1,3,1,1,3]}\$.
## Challenge
Given an array with indices output the array obtained by iterating the above described pointer jumping until the array does not change anymore.
## Rules
Your program/function will take and return/output the same type, a list/vector/array etc. which
* is guaranteed to be non-empty and
* is guaranteed to only contain entries \$0 \leq p < n\$.
**Variants:** You may choose
* to use 1-based indexing or
* use actual pointers,
however you should mention this in your submission.
## Test cases
```
[0] ‚Üí [0]
[1,0] ‚Üí [0,0]
[1,2,3,4,0] ‚Üí [2,2,2,2,2]
[0,1,1,1,0,3] ‚Üí [0,1,1,1,0,1]
[4,1,3,0,3,2] ‚Üí [3,1,3,3,3,3]
[5,1,2,0,4,5,6] ‚Üí [5,1,2,5,4,5,6]
[9,9,9,2,5,4,4,5,8,1,0,0] ‚Üí [1,1,1,1,4,4,4,4,8,1,1,1]
```
  
[Answer]
# JavaScript, 36 bytes
Modifies the original input array.
```
a=>a.map(_=>a.map((x,y)=>a[y]=a[x]))
```
[Try it online](https://tio.run/##NY7BDsIgEETvfEgDydpQoEYP@CNI7Ka2pk0LjTWm/XoE1Mxh501mkxnxjWv7HJbXwfl7F3odUF@wnHGht7@hG@wsgtmtRrNZxkLr3eqnrpz8gxpiuAViKvgdARLUFzhUWRxkQhWtTAAiYQ2pzGO5hmMKzpAkIqocnvIrt8TmIXFaT5EVBbJy9INrrq5h4QM)
[Answer]
## Haskell, 56 bytes
```
foldr(\_->([]#))=<<id
x#a@(b:c)=(x++[(x++a)!!b])#c
x#_=x
```
Haskell and in-place updates are a bad match.
[Try it online!](https://tio.run/##PUtZDoIwEP3nFCX8tGEwZTNqqPECngAaUoooEbABPzi9ta1LXuZN3nYTy/0yDLpjle4eQzvjqo6OuOQBIawo@tZbA3HCzUEShtcwLC0J4vsNJ4E0Yc1WPYp@QgyNQp1rhNXcT0@0QR1BpYfKBGLIzKWQcDCaOo7h9xOTZF9FTc@CQur0Z0f/2xxsn5p@Dlvn7MEiMTpz7s6tKef6JbtBXBcdSaXe "Haskell ‚Äì Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), 53 bytes
```
def f(l):L=len(l);i=0;exec'l[i]=l[l[i]];i=-~i%L;'*L*L
```
[Try it online!](https://tio.run/##K6gsycjPM/r/PyU1TSFNI0fTysc2JzUPyLDOtDWwTq1ITVbPic6Mtc2JBlGxQFHdukxVH2t1LR8tn/@JCrYKmXkFpSUamlxcaRqJQLKgKDOvRCHxf7SlDgga6ZjqmAChqY6FjqGOgY5BLAA "Python 2 ‚Äì Try It Online")
-6 thanks to [HyperNeutrino](https://codegolf.stackexchange.com/users/68942/hyperneutrino).
Alters `l` to the result in place.
[Answer]
# [C++14 (gcc)](https://gcc.gnu.org/), 61 bytes
As unnamed generic lambda. Requires sequential containers like `std::vector`.
```
[](auto&c){auto d=c;do{d=c;for(auto&x:c)x=c[x];}while(d!=c);}
```
[Try it online!](https://tio.run/##RU1LCoMwEN3nFFMLxUAK/a2M8SLiQibaBtSIxjQQcnbrD7qZN/N@g31/fSPOZ9VhM8kKUqVHM1Rlm5E/Zys0esgIKSejoQYx50W87hekfuOkQC61X6HWw665BKkTmLuCh@9HNVUsTwIpDzMnRHUG2lJ1MQVPAEYjk2R/ky5SBtb7O3uwJ3uxWwh8sdSxpRse/eASS5f7CKOeDKQpuHVEDCJOwvwD "C++ (gcc) ‚Äì Try It Online")
[Answer]
## [Swift](https://swift.org), ~~68~~ 53 bytes
```
{a in for _ in a{var i=0;a.forEach{a[i]=a[$0];i+=1}}}
```
[Try it online!](https://tio.run/##TY7LasMwEEX3/opZlGLTaZD1sNsEdddFfiAbY4JIYioodlHVdmH87a7GiRwxmzP3SFf6/rOdl/PnxUO3hdz2w4@HZt/7tnh@Owz2DHoeDdgeusHBkcCMv8aB1WxnNiF8N6eP0TS21aZ5YO3OPulymqaZDhnnStDQsDa7rZzWEu@BuAYcBcoklss1LJdhKFahSMgQCoqRr6IioZCqWKhSWK2qJvWKNDwIueiXpTi8mHX5I320uAGPICLICCpCFaEusuzL2d7n14qVecIiYZmwSrhKuC7mfw)
-15 thanks to BMO
[Answer]
# JavaScript (ES6), 41 bytes
```
f=a=>a+''==a.map((x,i)=>a[i]=a[x])?a:f(a)
```
[Try it online!](https://tio.run/##dc9NDoIwEAXgvadgRxtHaPkxaFI9COligmIwSIkYw@1rW3Ah1L5V5/HBcMc3DtWz6V@7Tl2uWtcCxQm3YSgERg/sCRmhoWZUNlJgOUp6xmNNkOpKdYNqr1GrbqQmJZOUBv4Tx4GpNwvA4S9xAHwkgRQyH7QkgTkryIC7MEiXdPrWt@Yrmpl5aqF5rYemrnZZ0RzswswsnMP@F1s61flcL/EBbKbePlG4/dyfW8znlbM5xXSX@gM "JavaScript (Node.js) ‚Äì Try It Online")
[Answer]
# [05AB1E (legacy)](https://github.com/Adriandmen/05AB1E/tree/fb4a2ce2bce6660e1a680a74dd61b72c945e6c3b), 8 bytes
```
ŒîDvDy√®N«ù
```
[Try it online!](https://tio.run/##MzBNTDJM/f//3BSXMpfKwyv8js/9/z/aUgcEjXRMdUyA0FTHQsdQx0DHIBYA "05AB1E (legacy) ‚Äì Try It Online")
**Explanation**
```
Œî          # apply until the top of the stack stops changing
 D         # duplicate current list
  v        # for each (element y, index N) in the list
   Dy√®     # get the element at index y
      N«ù   # and insert it at index N
```
# [05AB1E](https://github.com/Adriandmen/05AB1E), 14 bytes
```
[D¬©vDy√®N«ù}D¬ÆQ#
```
[Try it online!](https://tio.run/##yy9OTMpM/f8/2uXQyjKXysMr/I7PrXU5tC5QGShmqQOCRjqmOiZAaKpjoWOoY6BjEAsA "05AB1E ‚Äì Try It Online")
[Answer]
# Japt, ~~15~~ ~~13~~ 7 bytes
Modifies the original input array.
```
¬£¬£hYXgU
```
[Try it](https://ethproductions.github.io/japt/?v=1.4.6&code=o6NoWVhnVcPDVQ==&input=WzksOSw5LDIsNSw0LDQsNSw4LDEsMCwwXQ==) (additional bytes are to write the modified input to the console)
```
¬£¬£hYXgU
¬£           :Map
 ¬£          :  Map each X at index Y
  hY        :    Replace the element at index Y
    XgU     :    With the element at index X
```
[Answer]
# Java 8, ~~105~~ 54 bytes
```
a->{for(int l=a.length,i=0;i<l*l;)a[i%l]=a[a[i++%l]];}
```
Modifies the input-array instead of returning a new one to save bytes.
-51 bytes by just modifying the array \$length^2\$ times, instead of until it no longer changes.
[Try it online.](https://tio.run/##fVFBasMwELznFXspOI0iFMcpLa4LfUBzydHksHWUVK4iB0tOCcZvd1eyC4XiIiSk3dHMMFviFZfl4bMvNFoLb6hMOwNQxsn6iIWErX8CXCt1gCKier4HnKdU7GZ0WIdOFbAFAxn0uHxpj1XtYaAz5Fqak/tgKhOpetb3Op1jru70PsOcLosFXfdp16ee6dK8a2IaCYPemdxEO1crcwqqgxUnrYuM/IJgpo3ZiiW01yzugq8/CDFRX7HpTkx8yWRfkJ5fgq0nEIMj8Y@rDfMqglQ27GEC88T8igmRBNxj0Bxd/c4/xBU@/0xoyMrwIsKRe3ezTp551Th@oUidNlFJ0@eNU5q/1jXeLHfVEDd9GjW6/hs)
**Explanation:**
```
a->{                // Method with integer-array parameter and no return-type
  int l=a.length,   //  Length of the input-array
  i=0;i<l*l;)       //  Loop `i` in the range [0, length squared):
    a[i%l]=         //   Set the (`i` modulo-length)'th item in the array to:
      a[            //    The `p`'th value of the input-array,
        a[i++%l]];} //    where `p` is the (`i` modulo-length)'th value of the array
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 17 bytes
```
¬Æ
¬£hYUgX
eV ?U:√ü
```
[Try all test cases](https://ethproductions.github.io/japt/?v=1.4.6&code=Cq4Ko2hZVWdYCmVWID9VOt8=&input=W1swXQpbMSwwXQpbMSwyLDMsNCwwXQpbMCwxLDEsMSwwLDNdCls0LDEsMywwLDMsMl0KWzUsMSwyLDAsNCw1LDZdCls5LDksOSwyLDUsNCw0LDUsOCwxLDAsMF1dCi1tUQ==)
This feels like it should be shorter, but unfortunately my initial thought of `UmgU` doesn't work because each `g` accesses the original `U` rather than modifying it at each step. Preserving different components appropriately cost a handful of bytes as well.
Explanation:
```
           #Blank line preserves input in U long enough for the next line
¬Æ          #Copy U into V to preserve its original value
¬£hY        #Modify U in-place by replacing each element X with...
   UgX     #The value from the current U at the index X
eV ?U      #If the modified U is identical to the copy V, output it
     :√ü    #Otherwise start again with the modified U as the new input
```
[Answer]
# [C (clang)](http://clang.llvm.org/), 32-bit, ~~49~~ 44 bytes
```
i;f(**p,n){for(i=0;i<n*n;)p[i++%n]=*p[i%n];}
```
[Try it online!](https://tio.run/##fY/RToQwEEWf4SsmmDVtKYYFdtWw@CPIAwFZm7AFdtEXwq@LMwUSg8akaad3zr3TFl5R5/o8TSqumBCt1HyomitTiR@rkxY65m2qXHens0RghWc8TndKF/VH@QanW1@q5uH9xf5sVAk9U7oHTAE6NYfBtozSpeizLUwGg1A8YD5urstty@pSlUFimoLfdymOyoyDdRKD/vW2V5Qr5uxKcOQcITgFeh0Z1/ardvA62pRxyZVm5nk9I0Oa8QF8GCXsyfJD3MtZD37rgYRQQrQAhw3gS2LmhXVIzHHDRKYbzgAG/sUc5DLLN7PweiTscYM9y2UFholW@Gl9wPw7@sY4fRVVnZ9vk3cJg28 "C (clang) ‚Äì Try It Online")
Uses pointers.
**~~50~~ 45 bytes** with integers:
```
i;f(*p,n){for(i=0;i<n*n;)p[i++%n]=p[p[i%n]];}
```
[Try it online!](https://tio.run/##bY/RboMwDEWf4SsspkpJySYKtN2Udj/CeKigbJZagxjbC@LbmR1AmtgkK7Fvjq/j4rG4Xeh9HNFWatsY0n1VtwrPkcUTbcnqJsMw3FB@bjJOOcntMD4gFbev8gqnz67E@unj1f@usYROIXXAPiA3aeh9r1Jckrac1S04QOyB/fkIQ@17XtOyXKlgU0JggOfkwi/qGwVcDr603i9Iyvl2SryyXPcQwWBgJy2/xJ2Z9PivHhtIDKQzsF8BkRFmCs4TYQ4rJnWvyQSw4X/M3syzIjeLy4NgxxX2YuaIHZMu8PPygWk7WWMYfwA "C (clang) ‚Äì Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~37~~ 34 bytes
```
->a{a.size.times{a.map!{|x|a[x]}}}
```
[Try it online!](https://tio.run/##NY7NDsIgEITvPEWN17WBQk2N0RchHNDQ2EOTxmJSLTw7Ln@ZA8w3uwPvz@Mbxls43fWu23X6mdZOs1nRzHo57G5zWm7Kex8kkVQ1cGzwIJJBNZBtBxxEhR0UYUSBJVHgdaMChrHAG48hDqeYJ5CEcQ@xmmJ1D@c8kFFfEJEXiMoksiF1l5@w8pgoGrJXRLVGP1@7s26UVl2XxvrwBw "Ruby ‚Äì Try It Online")
Returns by modifying the input array in-place.
[Answer]
# [Red](http://www.red-lang.org), 63 bytes
```
func[b][loop(l: length? b)* l[repeat i l[b/:i: b/(1 + b/:i)]]b]
```
[Try it online!](https://tio.run/##ZY3NDsIgEITvfYo5tnoo9MdYLr6DV8JBLGgTQhuCz48rHgw2m012vtmdDWZOVzNLVVmR7MvfpVbSretWOwFn/CM@L9DNAU4Gs5lbxEKjbsUioNua44iPaJTSKm1h8REWEh04BuqeJlX9OCsU3@mOLoY/yojzvNsX/JvPdj/GnMPIH3EqnClXR3zI7jmn0rf0Bg "Red ‚Äì Try It Online")
Modifies the array in place
[Answer]
# [R](https://www.r-project.org/), ~~60~~ 58 bytes
-2 bytes thanks to @digEmAll for reading the rules.
```
function(x,n=sum(x|1)){for(i in rep(1:n,n))x[i]=x[x[i]];x}
```
[Try it online!](https://tio.run/##VY5NCsIwEIX3niLgJsERnCatvz1J6aoYyMIo1UJA3XoAj@hF4jQNJvICQ2a@efN6r9lh6fVgu5s5W@7A1tfhxN0Dhbjrc88NM5b1xwvHnQUrhGtMW7tmLO3ePb3mKNicfV5v1qxatmA407zjBZDBrw9/EwkKynxeQFSiMLYQVO6DQVQTWRKlRg5kIiU15KREVjDeRrpdwTqxFIUGZQhVZQnoSniS8DIsbUOgLDjGQCpqM/2Dif8C "R ‚Äì Try It Online")
1-indexed.
`n` is the length of the input array.
`rep(1:n,n)` replicates `1:n` `n` times (e.g. `n=3 => 1,2,3,1,2,3,1,2,3`)
Loop through the array `n` times. Steady state will be acheived by then for sure, in fact by the end of the n-1st time through I think. The proof is left to the reader.
[Answer]
# Common Lisp, ~~59~~ 58 bytes
```
(lambda(a)(dolist(j a)(map-into a(lambda(x)(elt a x))a))a)
```
[Try it online!](https://tio.run/##NY7LCsJADEV/5VIQM4vC9CW6UOinxLZCpW1GO4u66a@PmRFJCOeGm0c3jasLNIk4POSNDeOCI5E1oAK/WqJCndiiSGFRqaqVqsgoVTWITqvOBifVF8QoVdWpd05z1hj0AtJbM3t4ZHuL6w17ux8yUCfuk6/DC5tu0Ld4vvdMbKgXfdTTE8ozu3xcvID/hs3QMHmwjhmOGRRM@AI)
[Answer]
# [Clean](https://github.com/Ourous/curated-clean-linux), 80 bytes
```
import StdEnv
```
# 
```
limit o iterate\b=foldl(\l i=updateAt i(l!!(l!!i))l)b(indexList b)
```
[Try it online!](https://tio.run/##pc69DoIwFAXgvU9x2SjB4N/KYKKDCRujOJS26E1uWwIXoy9vRQcTZ4eznJN8OZqs8tEFM5EFp9CLogCleVIExnbokTF4uNrBCnR9GBhqNgd/E93k9WcrgdAhQwBkOyi2TVt2gQylDQGWU2/mbseAKSXJOyglyTZFb@y9wpGhlaLI4i//vxmzQtSsZrKE79nTKl/nm3ybL8/xqTtSlzEujlXcP7xyqMcX "Clean ‚Äì Try It Online")
[Answer]
# [Clojure](https://clojure.org/), 136 bytes
```
(defn j[a](let[f(fn[a](loop[i 0 a a](if(= i(count a))a(recur(inc i)(assoc a i(a(a i)))))))](loop[p nil a a](if(= p a)a(recur a(f a))))))
```
[Try it online!](https://tio.run/##bY1NCsMgEEb3PcUsR5iF@SvtoieRLMQqGETFJOe3arNoSWZA9HvjG@XCsiedM7618bAIOaPTmzBofLuHEIUFDhLKyxp8gUUVdr@BZExi0mpPaL0Cy1Cua1Bl0qLEcrJvHZII3rofTSyC4z9INFVXK2NM1m/OAy4g@MzY7S/p6CrraaDxgnDqWnMaTmws@VAJ9Sc2UXXy4pzofqJPqt0XNraJR9tQt@cP "Clojure ‚Äì Try It Online")
[Answer]
# Perl 5, ~~35~~ ~~34~~ 26 bytes
using the fact that convergence is reach at most for the size number of iterations
```
$_=$F[$_]for@F x@F;$_="@F"
```
[26 bytes](https://tio.run/##K0gtyjH9/18l3lbFLVolPjYtv8jBTaHCwc0aKKTk4Kb0/78Bl6ECCBspGCuYAFkGCoZgaKBgzGUCpI1BLAUjLlMFkBoDoBpTBTMuSwUQNAKyTcAiFmAdBv/yC0oy8/OK/@smFuQAAA)
```
$_=$F[$_]for@F;/@F/ or$_="@F",redo
```
[34 bytes](https://tio.run/##HYvNCsIwEITveYqh5Gjt5k8UEXLKzScQKYIVhNIN0ed3TcIwzMcwk5eyBhE9X3S66fn@4hLTeYppApfaDjENu7I8WYSUQbOFg69EMF0Ep3xN1whWBbQN1U3AQZ3QZCv73hz7g36cv2/ePjJew56MjI@8/gE)
```
$_=$F[$_]for@F;$_="@F",redo if!/@F/
```
[35 bytes](https://tio.run/##HYvNCsIwEITveYqx5Gjt5k8UKeSUW59ApAi2UCgmRJ/fNQnDsN8sM2nJu2OW8yjDXc6PNWYfbiV2PnTHvLwitvUw@DAwk1Co1jCwhQiqiWCELddUghYOtUOl43AWV1TpwrZ9Lm1Bv5i@W3x/uJ/ciRT3z7T/AQ)
[Answer]
# [Clojure](https://clojure.org/), 88 bytes
```
#(reduce(fn[x i](assoc x i(get x(get x i))))%(flatten(repeat(count %)(range(count %)))))
```
[Try it online!](https://tio.run/##ZY3RCoMwDEXf9xWFIaSQh1p1bN8iPpSaikOq1Bb8@67tYDBNIOTeQ270sr6DowgjGWbiHRyNQRMY2x9sHkDt@6pZWmEiz47vZDNPVYFZlPdk081GyoNeg/Ws4uCUnegnc0V@g83N1i8WTC8G/qdrvDoSG2wvvsC6tMDmRNrkNtlHeSId5jSR0jp8nNgLc8tE2sKfJTt/jR8 "Clojure ‚Äì Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 16 bytes
```
Ôº¶Œ∏Ôº¶Ôº¨Œ∏¬ß‚âîŒ∏Œ∫¬ßŒ∏¬ßŒ∏Œ∫Ôº©Œ∏
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z8tv0hBo1BTAUz7pOall2QAuZoKjsXFmel5jiWeeSmpFRqFOgrZOgpIPGQJTU1Na66Aosy8Eg3nxOISkHbr//@joy11QNBIx1THBAhNdSx0DHUMdAxiY//rluUAAA "Charcoal ‚Äì Try It Online") Link is to verbose version of code. Sadly all the usual mapping functions only operate on a copy of the array with the result being that they just permute the elements rather than jumping them, so the code has to do everything manually. Explanation:
```
Ôº¶Œ∏
```
Repeat the inner loop once for each element. This just ensures that the result stabilises.
```
Ôº¶Ôº¨Œ∏
```
Loop over the array indices.
```
¬ß‚âîŒ∏Œ∫¬ßŒ∏¬ßŒ∏Œ∫
```
Get the array element at the current index, use that to index into the array, and replace the current element with that value.
```
Ôº©Œ∏
```
Cast the elements to string and implicitly print each on their own line.
[Answer]
# F#, ~~74~~ 73 bytes
```
fun(c:'a[])->let l=c.Length in(for i in 0..l*l do c.[i%l]<-c.[c.[i%l]]);c
```
Nothing special. Uses the modulus idea seen in other answers.
[Answer]
## K, 27 Bytes
```
{{@[x;y;:;x x y]}/[x;!#x]}/
```
* `{..}/` applies lambda {..} over arg (until convergence)
* inside outer lambda:
	+ `{..}/[x;y]` applies lambda iteratively over x (updated at each iteration) and an item of y (y is a list of values, and uses an item at each iteration). In this case arg y is `!#x`(til count x, that is, indexes of the array)
	+ `@[x;y;:;x x y]` amend array x (at index y assign x[x[y]])
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 26 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?")[SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set")
Requires `‚éïIO‚Üê0`
```
{m‚ä£{m[‚çµ]‚Üêm[m[‚çµ]]}¬®‚ç≥‚â¢m‚Üê‚çµ}‚ç£‚â°
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkG/6tzH3Utrs6NftS7NRYokBsNYcbWHlrxqHfzo85FuUBRoEjto97FjzoX/k8Dc/sgBnQ1H1pv/KhtIpAXHOQMJEM8PIP/pynoGHClKRhCSSMdYx0TMNtAxxAMDXSMgTwTIMsYxNYxAvJMdUAqDYAqTXXMgHxLHRA0AvJMwGIWYH0GAA "APL (Dyalog Unicode) ‚Äì Try It Online")
]