Pointer jumping












18












$begingroup$


Suppose we have an array $texttt{ps}$ of length $n$ with pointers pointing to some location in the array: The process of "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]









share|improve this question











$endgroup$












  • $begingroup$
    Related: Jump the array
    $endgroup$
    – BMO
    2 days ago










  • $begingroup$
    Are we allowed to take the length n as additional input?
    $endgroup$
    – Kevin Cruijssen
    yesterday






  • 2




    $begingroup$
    @KevinCruijssen, see this meta discussion.
    $endgroup$
    – Shaggy
    yesterday










  • $begingroup$
    It's too bad the entries need to be updated sequentially; if they could be updated simultaneously, Mathematica would have the 21-character solution #[[#]]&~FixedPoint~#&.
    $endgroup$
    – Greg Martin
    17 hours ago
















18












$begingroup$


Suppose we have an array $texttt{ps}$ of length $n$ with pointers pointing to some location in the array: The process of "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]









share|improve this question











$endgroup$












  • $begingroup$
    Related: Jump the array
    $endgroup$
    – BMO
    2 days ago










  • $begingroup$
    Are we allowed to take the length n as additional input?
    $endgroup$
    – Kevin Cruijssen
    yesterday






  • 2




    $begingroup$
    @KevinCruijssen, see this meta discussion.
    $endgroup$
    – Shaggy
    yesterday










  • $begingroup$
    It's too bad the entries need to be updated sequentially; if they could be updated simultaneously, Mathematica would have the 21-character solution #[[#]]&~FixedPoint~#&.
    $endgroup$
    – Greg Martin
    17 hours ago














18












18








18


2



$begingroup$


Suppose we have an array $texttt{ps}$ of length $n$ with pointers pointing to some location in the array: The process of "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]









share|improve this question











$endgroup$




Suppose we have an array $texttt{ps}$ of length $n$ with pointers pointing to some location in the array: The process of "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]






code-golf array-manipulation graph-theory






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago







BMO

















asked 2 days ago









BMOBMO

12k22290




12k22290












  • $begingroup$
    Related: Jump the array
    $endgroup$
    – BMO
    2 days ago










  • $begingroup$
    Are we allowed to take the length n as additional input?
    $endgroup$
    – Kevin Cruijssen
    yesterday






  • 2




    $begingroup$
    @KevinCruijssen, see this meta discussion.
    $endgroup$
    – Shaggy
    yesterday










  • $begingroup$
    It's too bad the entries need to be updated sequentially; if they could be updated simultaneously, Mathematica would have the 21-character solution #[[#]]&~FixedPoint~#&.
    $endgroup$
    – Greg Martin
    17 hours ago


















  • $begingroup$
    Related: Jump the array
    $endgroup$
    – BMO
    2 days ago










  • $begingroup$
    Are we allowed to take the length n as additional input?
    $endgroup$
    – Kevin Cruijssen
    yesterday






  • 2




    $begingroup$
    @KevinCruijssen, see this meta discussion.
    $endgroup$
    – Shaggy
    yesterday










  • $begingroup$
    It's too bad the entries need to be updated sequentially; if they could be updated simultaneously, Mathematica would have the 21-character solution #[[#]]&~FixedPoint~#&.
    $endgroup$
    – Greg Martin
    17 hours ago
















$begingroup$
Related: Jump the array
$endgroup$
– BMO
2 days ago




$begingroup$
Related: Jump the array
$endgroup$
– BMO
2 days ago












$begingroup$
Are we allowed to take the length n as additional input?
$endgroup$
– Kevin Cruijssen
yesterday




$begingroup$
Are we allowed to take the length n as additional input?
$endgroup$
– Kevin Cruijssen
yesterday




2




2




$begingroup$
@KevinCruijssen, see this meta discussion.
$endgroup$
– Shaggy
yesterday




$begingroup$
@KevinCruijssen, see this meta discussion.
$endgroup$
– Shaggy
yesterday












$begingroup$
It's too bad the entries need to be updated sequentially; if they could be updated simultaneously, Mathematica would have the 21-character solution #[[#]]&~FixedPoint~#&.
$endgroup$
– Greg Martin
17 hours ago




$begingroup$
It's too bad the entries need to be updated sequentially; if they could be updated simultaneously, Mathematica would have the 21-character solution #[[#]]&~FixedPoint~#&.
$endgroup$
– Greg Martin
17 hours ago










21 Answers
21






active

oldest

votes


















7












$begingroup$

JavaScript, 36 bytes



Modifies the original input array.



a=>a.map(_=>a.map((x,y)=>a[y]=a[x]))


Try it online






share|improve this answer









$endgroup$





















    5












    $begingroup$


    Python 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!



    -6 thanks to HyperNeutrino.



    Alters l to the result in place.






    share|improve this answer











    $endgroup$





















      4












      $begingroup$

      JavaScript (ES6), 41 bytes





      f=a=>a+''==a.map((x,i)=>a[i]=a[x])?a:f(a)


      Try it online!






      share|improve this answer









      $endgroup$













      • $begingroup$
        Gah! I was waiting for this challenge to be posted so I could post the exact same solution : Damn your ninja skills! :p
        $endgroup$
        – Shaggy
        2 days ago






      • 2




        $begingroup$
        @shaggy 🐱‍👤(this is supposed to be a Ninja Cat ... but it's probably not supported everywhere)
        $endgroup$
        – Arnauld
        2 days ago



















      4












      $begingroup$

      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!






      share|improve this answer









      $endgroup$





















        4












        $begingroup$


        C++14 (gcc), 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!






        share|improve this answer











        $endgroup$





















          4












          $begingroup$


          Swift, 68 53 bytes



          {a in for _ in a{var i=0;a.forEach{a[i]=a[$0];i+=1}}}


          Try it online!



          -15 thanks to BMO






          share|improve this answer










          New contributor




          Sean is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          $endgroup$









          • 2




            $begingroup$
            Welcome to PPCG! I don't know Swift, but on codegolf.SE the default is to accept typed lambda-functions which I guess a closure would count as. So this can be 53 bytes (you don't need to count f=). Enjoy your stay here!
            $endgroup$
            – BMO
            yesterday










          • $begingroup$
            Thank you for the welcome and advice which I have used to update my answer.
            $endgroup$
            – Sean
            yesterday



















          3












          $begingroup$


          Japt, 17 bytes




          ®
          £hYUgX
          eV ?U:ß


          Try all test cases



          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





          share|improve this answer









          $endgroup$





















            3












            $begingroup$


            05AB1E (legacy), 8 bytes



            ΔDvDyèNǝ


            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, 14 bytes



            [D©vDyèNǝ}D®Q#


            Try it online!






            share|improve this answer











            $endgroup$





















              3












              $begingroup$

              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.



              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





              share|improve this answer











              $endgroup$





















                2












                $begingroup$


                C (gcc), 32-bit, 49 bytes





                f(p,n,i)int**p;{for(i=0;i<n*n;)p[i++%n]=*p[i%n];}


                Try it online!



                Uses pointers.



                50 bytes with integers:



                f(p,n,i)int*p;{for(i=0;i<n*n;)p[i++%n]=p[p[i%n]];}


                Try it online!






                share|improve this answer











                $endgroup$





















                  2












                  $begingroup$

                  Japt, 15 13 7 bytes



                  Modifies the original input array.



                  ££hYXgU


                  Try it (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





                  share|improve this answer











                  $endgroup$





















                    2












                    $begingroup$


                    Ruby, 37 34 bytes





                    ->a{a.size.times{a.map!{|x|a[x]}}}


                    Try it online!



                    Returns by modifying the input array in-place.






                    share|improve this answer











                    $endgroup$





















                      2












                      $begingroup$


                      Red, 63 bytes



                      func[b][loop(l: length? b)* l[repeat i l[b/:i: b/(1 + b/:i)]]b]


                      Try it online!



                      Modifies the array in place






                      share|improve this answer











                      $endgroup$





















                        2












                        $begingroup$


                        R, 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!



                        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.






                        share|improve this answer











                        $endgroup$









                        • 1




                          $begingroup$
                          I think you can remove the +1 and simply take the 1-based input, the post states : You may choose to use 1-based indexing
                          $endgroup$
                          – digEmAll
                          yesterday












                        • $begingroup$
                          -4 by switching to scan() for input. I always feel like my scan() solutions are suboptimal, so keep an eye out a shorter way to assign x and n together: n=length(x<-scan());for(i in rep(1:n,n))x[i]=x[x[i]];x Try it online!
                          $endgroup$
                          – CriminallyVulgar
                          13 hours ago



















                        2












                        $begingroup$

                        Common Lisp, 59 58 bytes



                        (lambda(a)(dolist(j a)(map-into a(lambda(x)(elt a x))a))a)


                        Try it online!






                        share|improve this answer











                        $endgroup$





















                          2












                          $begingroup$


                          Clojure, 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!






                          share|improve this answer










                          New contributor




                          Ethan McCue is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






                          $endgroup$













                          • $begingroup$
                            Hello and welcome to PPCG. Would it be possible for you to provide a link to an online interpreter such that one could easily verify your solution? Furthermore, can loop [ not become loop[?
                            $endgroup$
                            – Jonathan Frech
                            2 days ago






                          • 1




                            $begingroup$
                            The most recent edit should fix the test failures. Sorry for the inconvenience everybody.
                            $endgroup$
                            – Ethan McCue
                            7 hours ago



















                          1












                          $begingroup$

                          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



                          $_=$F[$_]for@F;/@F/ or$_="@F",redo


                          34 bytes



                          $_=$F[$_]for@F;$_="@F",redo if!/@F/


                          35 bytes






                          share|improve this answer











                          $endgroup$





















                            1












                            $begingroup$


                            Clojure, 88 bytes





                            #(reduce(fn[x i](assoc x i(get x(get x i))))%(flatten(repeat(count %)(range(count %)))))


                            Try it online!






                            share|improve this answer









                            $endgroup$





















                              1












                              $begingroup$


                              Charcoal, 16 bytes



                              FθFLθ§≔θκ§θ§θκIθ


                              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:



                              Fθ


                              Repeat the inner loop once for each element. This just ensures that the result stabilises.



                              FLθ


                              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.



                              Iθ


                              Cast the elements to string and implicitly print each on their own line.






                              share|improve this answer









                              $endgroup$





















                                1












                                $begingroup$


                                Clean, 80 bytes



                                import StdEnv




                                limit o iterateb=foldl(l i=updateAt i(l!!(l!!i))l)b(indexList b)


                                Try it online!






                                share|improve this answer









                                $endgroup$





















                                  1












                                  $begingroup$

                                  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.






                                  share|improve this answer











                                  $endgroup$













                                    Your Answer





                                    StackExchange.ifUsing("editor", function () {
                                    return StackExchange.using("mathjaxEditing", function () {
                                    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
                                    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
                                    });
                                    });
                                    }, "mathjax-editing");

                                    StackExchange.ifUsing("editor", function () {
                                    StackExchange.using("externalEditor", function () {
                                    StackExchange.using("snippets", function () {
                                    StackExchange.snippets.init();
                                    });
                                    });
                                    }, "code-snippets");

                                    StackExchange.ready(function() {
                                    var channelOptions = {
                                    tags: "".split(" "),
                                    id: "200"
                                    };
                                    initTagRenderer("".split(" "), "".split(" "), channelOptions);

                                    StackExchange.using("externalEditor", function() {
                                    // Have to fire editor after snippets, if snippets enabled
                                    if (StackExchange.settings.snippets.snippetsEnabled) {
                                    StackExchange.using("snippets", function() {
                                    createEditor();
                                    });
                                    }
                                    else {
                                    createEditor();
                                    }
                                    });

                                    function createEditor() {
                                    StackExchange.prepareEditor({
                                    heartbeatType: 'answer',
                                    autoActivateHeartbeat: false,
                                    convertImagesToLinks: false,
                                    noModals: true,
                                    showLowRepImageUploadWarning: true,
                                    reputationToPostImages: null,
                                    bindNavPrevention: true,
                                    postfix: "",
                                    imageUploader: {
                                    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                                    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                                    allowUrls: true
                                    },
                                    onDemand: true,
                                    discardSelector: ".discard-answer"
                                    ,immediatelyShowMarkdownHelp:true
                                    });


                                    }
                                    });














                                    draft saved

                                    draft discarded


















                                    StackExchange.ready(
                                    function () {
                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f179050%2fpointer-jumping%23new-answer', 'question_page');
                                    }
                                    );

                                    Post as a guest















                                    Required, but never shown

























                                    21 Answers
                                    21






                                    active

                                    oldest

                                    votes








                                    21 Answers
                                    21






                                    active

                                    oldest

                                    votes









                                    active

                                    oldest

                                    votes






                                    active

                                    oldest

                                    votes









                                    7












                                    $begingroup$

                                    JavaScript, 36 bytes



                                    Modifies the original input array.



                                    a=>a.map(_=>a.map((x,y)=>a[y]=a[x]))


                                    Try it online






                                    share|improve this answer









                                    $endgroup$


















                                      7












                                      $begingroup$

                                      JavaScript, 36 bytes



                                      Modifies the original input array.



                                      a=>a.map(_=>a.map((x,y)=>a[y]=a[x]))


                                      Try it online






                                      share|improve this answer









                                      $endgroup$
















                                        7












                                        7








                                        7





                                        $begingroup$

                                        JavaScript, 36 bytes



                                        Modifies the original input array.



                                        a=>a.map(_=>a.map((x,y)=>a[y]=a[x]))


                                        Try it online






                                        share|improve this answer









                                        $endgroup$



                                        JavaScript, 36 bytes



                                        Modifies the original input array.



                                        a=>a.map(_=>a.map((x,y)=>a[y]=a[x]))


                                        Try it online







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered 2 days ago









                                        ShaggyShaggy

                                        19.5k21666




                                        19.5k21666























                                            5












                                            $begingroup$


                                            Python 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!



                                            -6 thanks to HyperNeutrino.



                                            Alters l to the result in place.






                                            share|improve this answer











                                            $endgroup$


















                                              5












                                              $begingroup$


                                              Python 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!



                                              -6 thanks to HyperNeutrino.



                                              Alters l to the result in place.






                                              share|improve this answer











                                              $endgroup$
















                                                5












                                                5








                                                5





                                                $begingroup$


                                                Python 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!



                                                -6 thanks to HyperNeutrino.



                                                Alters l to the result in place.






                                                share|improve this answer











                                                $endgroup$




                                                Python 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!



                                                -6 thanks to HyperNeutrino.



                                                Alters l to the result in place.







                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited 2 days ago

























                                                answered 2 days ago









                                                Erik the OutgolferErik the Outgolfer

                                                31.6k429103




                                                31.6k429103























                                                    4












                                                    $begingroup$

                                                    JavaScript (ES6), 41 bytes





                                                    f=a=>a+''==a.map((x,i)=>a[i]=a[x])?a:f(a)


                                                    Try it online!






                                                    share|improve this answer









                                                    $endgroup$













                                                    • $begingroup$
                                                      Gah! I was waiting for this challenge to be posted so I could post the exact same solution : Damn your ninja skills! :p
                                                      $endgroup$
                                                      – Shaggy
                                                      2 days ago






                                                    • 2




                                                      $begingroup$
                                                      @shaggy 🐱‍👤(this is supposed to be a Ninja Cat ... but it's probably not supported everywhere)
                                                      $endgroup$
                                                      – Arnauld
                                                      2 days ago
















                                                    4












                                                    $begingroup$

                                                    JavaScript (ES6), 41 bytes





                                                    f=a=>a+''==a.map((x,i)=>a[i]=a[x])?a:f(a)


                                                    Try it online!






                                                    share|improve this answer









                                                    $endgroup$













                                                    • $begingroup$
                                                      Gah! I was waiting for this challenge to be posted so I could post the exact same solution : Damn your ninja skills! :p
                                                      $endgroup$
                                                      – Shaggy
                                                      2 days ago






                                                    • 2




                                                      $begingroup$
                                                      @shaggy 🐱‍👤(this is supposed to be a Ninja Cat ... but it's probably not supported everywhere)
                                                      $endgroup$
                                                      – Arnauld
                                                      2 days ago














                                                    4












                                                    4








                                                    4





                                                    $begingroup$

                                                    JavaScript (ES6), 41 bytes





                                                    f=a=>a+''==a.map((x,i)=>a[i]=a[x])?a:f(a)


                                                    Try it online!






                                                    share|improve this answer









                                                    $endgroup$



                                                    JavaScript (ES6), 41 bytes





                                                    f=a=>a+''==a.map((x,i)=>a[i]=a[x])?a:f(a)


                                                    Try it online!







                                                    share|improve this answer












                                                    share|improve this answer



                                                    share|improve this answer










                                                    answered 2 days ago









                                                    ArnauldArnauld

                                                    74k690310




                                                    74k690310












                                                    • $begingroup$
                                                      Gah! I was waiting for this challenge to be posted so I could post the exact same solution : Damn your ninja skills! :p
                                                      $endgroup$
                                                      – Shaggy
                                                      2 days ago






                                                    • 2




                                                      $begingroup$
                                                      @shaggy 🐱‍👤(this is supposed to be a Ninja Cat ... but it's probably not supported everywhere)
                                                      $endgroup$
                                                      – Arnauld
                                                      2 days ago


















                                                    • $begingroup$
                                                      Gah! I was waiting for this challenge to be posted so I could post the exact same solution : Damn your ninja skills! :p
                                                      $endgroup$
                                                      – Shaggy
                                                      2 days ago






                                                    • 2




                                                      $begingroup$
                                                      @shaggy 🐱‍👤(this is supposed to be a Ninja Cat ... but it's probably not supported everywhere)
                                                      $endgroup$
                                                      – Arnauld
                                                      2 days ago
















                                                    $begingroup$
                                                    Gah! I was waiting for this challenge to be posted so I could post the exact same solution : Damn your ninja skills! :p
                                                    $endgroup$
                                                    – Shaggy
                                                    2 days ago




                                                    $begingroup$
                                                    Gah! I was waiting for this challenge to be posted so I could post the exact same solution : Damn your ninja skills! :p
                                                    $endgroup$
                                                    – Shaggy
                                                    2 days ago




                                                    2




                                                    2




                                                    $begingroup$
                                                    @shaggy 🐱‍👤(this is supposed to be a Ninja Cat ... but it's probably not supported everywhere)
                                                    $endgroup$
                                                    – Arnauld
                                                    2 days ago




                                                    $begingroup$
                                                    @shaggy 🐱‍👤(this is supposed to be a Ninja Cat ... but it's probably not supported everywhere)
                                                    $endgroup$
                                                    – Arnauld
                                                    2 days ago











                                                    4












                                                    $begingroup$

                                                    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!






                                                    share|improve this answer









                                                    $endgroup$


















                                                      4












                                                      $begingroup$

                                                      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!






                                                      share|improve this answer









                                                      $endgroup$
















                                                        4












                                                        4








                                                        4





                                                        $begingroup$

                                                        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!






                                                        share|improve this answer









                                                        $endgroup$



                                                        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!







                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered 2 days ago









                                                        niminimi

                                                        31.7k32285




                                                        31.7k32285























                                                            4












                                                            $begingroup$


                                                            C++14 (gcc), 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!






                                                            share|improve this answer











                                                            $endgroup$


















                                                              4












                                                              $begingroup$


                                                              C++14 (gcc), 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!






                                                              share|improve this answer











                                                              $endgroup$
















                                                                4












                                                                4








                                                                4





                                                                $begingroup$


                                                                C++14 (gcc), 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!






                                                                share|improve this answer











                                                                $endgroup$




                                                                C++14 (gcc), 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!







                                                                share|improve this answer














                                                                share|improve this answer



                                                                share|improve this answer








                                                                edited 2 days ago

























                                                                answered 2 days ago









                                                                BierpfurzBierpfurz

                                                                1113




                                                                1113























                                                                    4












                                                                    $begingroup$


                                                                    Swift, 68 53 bytes



                                                                    {a in for _ in a{var i=0;a.forEach{a[i]=a[$0];i+=1}}}


                                                                    Try it online!



                                                                    -15 thanks to BMO






                                                                    share|improve this answer










                                                                    New contributor




                                                                    Sean is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                    Check out our Code of Conduct.






                                                                    $endgroup$









                                                                    • 2




                                                                      $begingroup$
                                                                      Welcome to PPCG! I don't know Swift, but on codegolf.SE the default is to accept typed lambda-functions which I guess a closure would count as. So this can be 53 bytes (you don't need to count f=). Enjoy your stay here!
                                                                      $endgroup$
                                                                      – BMO
                                                                      yesterday










                                                                    • $begingroup$
                                                                      Thank you for the welcome and advice which I have used to update my answer.
                                                                      $endgroup$
                                                                      – Sean
                                                                      yesterday
















                                                                    4












                                                                    $begingroup$


                                                                    Swift, 68 53 bytes



                                                                    {a in for _ in a{var i=0;a.forEach{a[i]=a[$0];i+=1}}}


                                                                    Try it online!



                                                                    -15 thanks to BMO






                                                                    share|improve this answer










                                                                    New contributor




                                                                    Sean is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                    Check out our Code of Conduct.






                                                                    $endgroup$









                                                                    • 2




                                                                      $begingroup$
                                                                      Welcome to PPCG! I don't know Swift, but on codegolf.SE the default is to accept typed lambda-functions which I guess a closure would count as. So this can be 53 bytes (you don't need to count f=). Enjoy your stay here!
                                                                      $endgroup$
                                                                      – BMO
                                                                      yesterday










                                                                    • $begingroup$
                                                                      Thank you for the welcome and advice which I have used to update my answer.
                                                                      $endgroup$
                                                                      – Sean
                                                                      yesterday














                                                                    4












                                                                    4








                                                                    4





                                                                    $begingroup$


                                                                    Swift, 68 53 bytes



                                                                    {a in for _ in a{var i=0;a.forEach{a[i]=a[$0];i+=1}}}


                                                                    Try it online!



                                                                    -15 thanks to BMO






                                                                    share|improve this answer










                                                                    New contributor




                                                                    Sean is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                    Check out our Code of Conduct.






                                                                    $endgroup$




                                                                    Swift, 68 53 bytes



                                                                    {a in for _ in a{var i=0;a.forEach{a[i]=a[$0];i+=1}}}


                                                                    Try it online!



                                                                    -15 thanks to BMO







                                                                    share|improve this answer










                                                                    New contributor




                                                                    Sean is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                    Check out our Code of Conduct.









                                                                    share|improve this answer



                                                                    share|improve this answer








                                                                    edited yesterday





















                                                                    New contributor




                                                                    Sean is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                    Check out our Code of Conduct.









                                                                    answered yesterday









                                                                    SeanSean

                                                                    414




                                                                    414




                                                                    New contributor




                                                                    Sean is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                    Check out our Code of Conduct.





                                                                    New contributor





                                                                    Sean is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                    Check out our Code of Conduct.






                                                                    Sean is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                    Check out our Code of Conduct.








                                                                    • 2




                                                                      $begingroup$
                                                                      Welcome to PPCG! I don't know Swift, but on codegolf.SE the default is to accept typed lambda-functions which I guess a closure would count as. So this can be 53 bytes (you don't need to count f=). Enjoy your stay here!
                                                                      $endgroup$
                                                                      – BMO
                                                                      yesterday










                                                                    • $begingroup$
                                                                      Thank you for the welcome and advice which I have used to update my answer.
                                                                      $endgroup$
                                                                      – Sean
                                                                      yesterday














                                                                    • 2




                                                                      $begingroup$
                                                                      Welcome to PPCG! I don't know Swift, but on codegolf.SE the default is to accept typed lambda-functions which I guess a closure would count as. So this can be 53 bytes (you don't need to count f=). Enjoy your stay here!
                                                                      $endgroup$
                                                                      – BMO
                                                                      yesterday










                                                                    • $begingroup$
                                                                      Thank you for the welcome and advice which I have used to update my answer.
                                                                      $endgroup$
                                                                      – Sean
                                                                      yesterday








                                                                    2




                                                                    2




                                                                    $begingroup$
                                                                    Welcome to PPCG! I don't know Swift, but on codegolf.SE the default is to accept typed lambda-functions which I guess a closure would count as. So this can be 53 bytes (you don't need to count f=). Enjoy your stay here!
                                                                    $endgroup$
                                                                    – BMO
                                                                    yesterday




                                                                    $begingroup$
                                                                    Welcome to PPCG! I don't know Swift, but on codegolf.SE the default is to accept typed lambda-functions which I guess a closure would count as. So this can be 53 bytes (you don't need to count f=). Enjoy your stay here!
                                                                    $endgroup$
                                                                    – BMO
                                                                    yesterday












                                                                    $begingroup$
                                                                    Thank you for the welcome and advice which I have used to update my answer.
                                                                    $endgroup$
                                                                    – Sean
                                                                    yesterday




                                                                    $begingroup$
                                                                    Thank you for the welcome and advice which I have used to update my answer.
                                                                    $endgroup$
                                                                    – Sean
                                                                    yesterday











                                                                    3












                                                                    $begingroup$


                                                                    Japt, 17 bytes




                                                                    ®
                                                                    £hYUgX
                                                                    eV ?U:ß


                                                                    Try all test cases



                                                                    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





                                                                    share|improve this answer









                                                                    $endgroup$


















                                                                      3












                                                                      $begingroup$


                                                                      Japt, 17 bytes




                                                                      ®
                                                                      £hYUgX
                                                                      eV ?U:ß


                                                                      Try all test cases



                                                                      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





                                                                      share|improve this answer









                                                                      $endgroup$
















                                                                        3












                                                                        3








                                                                        3





                                                                        $begingroup$


                                                                        Japt, 17 bytes




                                                                        ®
                                                                        £hYUgX
                                                                        eV ?U:ß


                                                                        Try all test cases



                                                                        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





                                                                        share|improve this answer









                                                                        $endgroup$




                                                                        Japt, 17 bytes




                                                                        ®
                                                                        £hYUgX
                                                                        eV ?U:ß


                                                                        Try all test cases



                                                                        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






                                                                        share|improve this answer












                                                                        share|improve this answer



                                                                        share|improve this answer










                                                                        answered 2 days ago









                                                                        Kamil DrakariKamil Drakari

                                                                        3,191416




                                                                        3,191416























                                                                            3












                                                                            $begingroup$


                                                                            05AB1E (legacy), 8 bytes



                                                                            ΔDvDyèNǝ


                                                                            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, 14 bytes



                                                                            [D©vDyèNǝ}D®Q#


                                                                            Try it online!






                                                                            share|improve this answer











                                                                            $endgroup$


















                                                                              3












                                                                              $begingroup$


                                                                              05AB1E (legacy), 8 bytes



                                                                              ΔDvDyèNǝ


                                                                              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, 14 bytes



                                                                              [D©vDyèNǝ}D®Q#


                                                                              Try it online!






                                                                              share|improve this answer











                                                                              $endgroup$
















                                                                                3












                                                                                3








                                                                                3





                                                                                $begingroup$


                                                                                05AB1E (legacy), 8 bytes



                                                                                ΔDvDyèNǝ


                                                                                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, 14 bytes



                                                                                [D©vDyèNǝ}D®Q#


                                                                                Try it online!






                                                                                share|improve this answer











                                                                                $endgroup$




                                                                                05AB1E (legacy), 8 bytes



                                                                                ΔDvDyèNǝ


                                                                                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, 14 bytes



                                                                                [D©vDyèNǝ}D®Q#


                                                                                Try it online!







                                                                                share|improve this answer














                                                                                share|improve this answer



                                                                                share|improve this answer








                                                                                edited 2 days ago

























                                                                                answered 2 days ago









                                                                                EmignaEmigna

                                                                                45.8k432139




                                                                                45.8k432139























                                                                                    3












                                                                                    $begingroup$

                                                                                    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.



                                                                                    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





                                                                                    share|improve this answer











                                                                                    $endgroup$


















                                                                                      3












                                                                                      $begingroup$

                                                                                      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.



                                                                                      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





                                                                                      share|improve this answer











                                                                                      $endgroup$
















                                                                                        3












                                                                                        3








                                                                                        3





                                                                                        $begingroup$

                                                                                        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.



                                                                                        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





                                                                                        share|improve this answer











                                                                                        $endgroup$



                                                                                        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.



                                                                                        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






                                                                                        share|improve this answer














                                                                                        share|improve this answer



                                                                                        share|improve this answer








                                                                                        edited yesterday

























                                                                                        answered yesterday









                                                                                        Kevin CruijssenKevin Cruijssen

                                                                                        36.8k555193




                                                                                        36.8k555193























                                                                                            2












                                                                                            $begingroup$


                                                                                            C (gcc), 32-bit, 49 bytes





                                                                                            f(p,n,i)int**p;{for(i=0;i<n*n;)p[i++%n]=*p[i%n];}


                                                                                            Try it online!



                                                                                            Uses pointers.



                                                                                            50 bytes with integers:



                                                                                            f(p,n,i)int*p;{for(i=0;i<n*n;)p[i++%n]=p[p[i%n]];}


                                                                                            Try it online!






                                                                                            share|improve this answer











                                                                                            $endgroup$


















                                                                                              2












                                                                                              $begingroup$


                                                                                              C (gcc), 32-bit, 49 bytes





                                                                                              f(p,n,i)int**p;{for(i=0;i<n*n;)p[i++%n]=*p[i%n];}


                                                                                              Try it online!



                                                                                              Uses pointers.



                                                                                              50 bytes with integers:



                                                                                              f(p,n,i)int*p;{for(i=0;i<n*n;)p[i++%n]=p[p[i%n]];}


                                                                                              Try it online!






                                                                                              share|improve this answer











                                                                                              $endgroup$
















                                                                                                2












                                                                                                2








                                                                                                2





                                                                                                $begingroup$


                                                                                                C (gcc), 32-bit, 49 bytes





                                                                                                f(p,n,i)int**p;{for(i=0;i<n*n;)p[i++%n]=*p[i%n];}


                                                                                                Try it online!



                                                                                                Uses pointers.



                                                                                                50 bytes with integers:



                                                                                                f(p,n,i)int*p;{for(i=0;i<n*n;)p[i++%n]=p[p[i%n]];}


                                                                                                Try it online!






                                                                                                share|improve this answer











                                                                                                $endgroup$




                                                                                                C (gcc), 32-bit, 49 bytes





                                                                                                f(p,n,i)int**p;{for(i=0;i<n*n;)p[i++%n]=*p[i%n];}


                                                                                                Try it online!



                                                                                                Uses pointers.



                                                                                                50 bytes with integers:



                                                                                                f(p,n,i)int*p;{for(i=0;i<n*n;)p[i++%n]=p[p[i%n]];}


                                                                                                Try it online!







                                                                                                share|improve this answer














                                                                                                share|improve this answer



                                                                                                share|improve this answer








                                                                                                edited 2 days ago

























                                                                                                answered 2 days ago









                                                                                                nwellnhofnwellnhof

                                                                                                6,66511126




                                                                                                6,66511126























                                                                                                    2












                                                                                                    $begingroup$

                                                                                                    Japt, 15 13 7 bytes



                                                                                                    Modifies the original input array.



                                                                                                    ££hYXgU


                                                                                                    Try it (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





                                                                                                    share|improve this answer











                                                                                                    $endgroup$


















                                                                                                      2












                                                                                                      $begingroup$

                                                                                                      Japt, 15 13 7 bytes



                                                                                                      Modifies the original input array.



                                                                                                      ££hYXgU


                                                                                                      Try it (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





                                                                                                      share|improve this answer











                                                                                                      $endgroup$
















                                                                                                        2












                                                                                                        2








                                                                                                        2





                                                                                                        $begingroup$

                                                                                                        Japt, 15 13 7 bytes



                                                                                                        Modifies the original input array.



                                                                                                        ££hYXgU


                                                                                                        Try it (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





                                                                                                        share|improve this answer











                                                                                                        $endgroup$



                                                                                                        Japt, 15 13 7 bytes



                                                                                                        Modifies the original input array.



                                                                                                        ££hYXgU


                                                                                                        Try it (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






                                                                                                        share|improve this answer














                                                                                                        share|improve this answer



                                                                                                        share|improve this answer








                                                                                                        edited 2 days ago

























                                                                                                        answered 2 days ago









                                                                                                        ShaggyShaggy

                                                                                                        19.5k21666




                                                                                                        19.5k21666























                                                                                                            2












                                                                                                            $begingroup$


                                                                                                            Ruby, 37 34 bytes





                                                                                                            ->a{a.size.times{a.map!{|x|a[x]}}}


                                                                                                            Try it online!



                                                                                                            Returns by modifying the input array in-place.






                                                                                                            share|improve this answer











                                                                                                            $endgroup$


















                                                                                                              2












                                                                                                              $begingroup$


                                                                                                              Ruby, 37 34 bytes





                                                                                                              ->a{a.size.times{a.map!{|x|a[x]}}}


                                                                                                              Try it online!



                                                                                                              Returns by modifying the input array in-place.






                                                                                                              share|improve this answer











                                                                                                              $endgroup$
















                                                                                                                2












                                                                                                                2








                                                                                                                2





                                                                                                                $begingroup$


                                                                                                                Ruby, 37 34 bytes





                                                                                                                ->a{a.size.times{a.map!{|x|a[x]}}}


                                                                                                                Try it online!



                                                                                                                Returns by modifying the input array in-place.






                                                                                                                share|improve this answer











                                                                                                                $endgroup$




                                                                                                                Ruby, 37 34 bytes





                                                                                                                ->a{a.size.times{a.map!{|x|a[x]}}}


                                                                                                                Try it online!



                                                                                                                Returns by modifying the input array in-place.







                                                                                                                share|improve this answer














                                                                                                                share|improve this answer



                                                                                                                share|improve this answer








                                                                                                                edited yesterday

























                                                                                                                answered 2 days ago









                                                                                                                Kirill L.Kirill L.

                                                                                                                3,9451319




                                                                                                                3,9451319























                                                                                                                    2












                                                                                                                    $begingroup$


                                                                                                                    Red, 63 bytes



                                                                                                                    func[b][loop(l: length? b)* l[repeat i l[b/:i: b/(1 + b/:i)]]b]


                                                                                                                    Try it online!



                                                                                                                    Modifies the array in place






                                                                                                                    share|improve this answer











                                                                                                                    $endgroup$


















                                                                                                                      2












                                                                                                                      $begingroup$


                                                                                                                      Red, 63 bytes



                                                                                                                      func[b][loop(l: length? b)* l[repeat i l[b/:i: b/(1 + b/:i)]]b]


                                                                                                                      Try it online!



                                                                                                                      Modifies the array in place






                                                                                                                      share|improve this answer











                                                                                                                      $endgroup$
















                                                                                                                        2












                                                                                                                        2








                                                                                                                        2





                                                                                                                        $begingroup$


                                                                                                                        Red, 63 bytes



                                                                                                                        func[b][loop(l: length? b)* l[repeat i l[b/:i: b/(1 + b/:i)]]b]


                                                                                                                        Try it online!



                                                                                                                        Modifies the array in place






                                                                                                                        share|improve this answer











                                                                                                                        $endgroup$




                                                                                                                        Red, 63 bytes



                                                                                                                        func[b][loop(l: length? b)* l[repeat i l[b/:i: b/(1 + b/:i)]]b]


                                                                                                                        Try it online!



                                                                                                                        Modifies the array in place







                                                                                                                        share|improve this answer














                                                                                                                        share|improve this answer



                                                                                                                        share|improve this answer








                                                                                                                        edited yesterday

























                                                                                                                        answered yesterday









                                                                                                                        Galen IvanovGalen Ivanov

                                                                                                                        6,64711032




                                                                                                                        6,64711032























                                                                                                                            2












                                                                                                                            $begingroup$


                                                                                                                            R, 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!



                                                                                                                            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.






                                                                                                                            share|improve this answer











                                                                                                                            $endgroup$









                                                                                                                            • 1




                                                                                                                              $begingroup$
                                                                                                                              I think you can remove the +1 and simply take the 1-based input, the post states : You may choose to use 1-based indexing
                                                                                                                              $endgroup$
                                                                                                                              – digEmAll
                                                                                                                              yesterday












                                                                                                                            • $begingroup$
                                                                                                                              -4 by switching to scan() for input. I always feel like my scan() solutions are suboptimal, so keep an eye out a shorter way to assign x and n together: n=length(x<-scan());for(i in rep(1:n,n))x[i]=x[x[i]];x Try it online!
                                                                                                                              $endgroup$
                                                                                                                              – CriminallyVulgar
                                                                                                                              13 hours ago
















                                                                                                                            2












                                                                                                                            $begingroup$


                                                                                                                            R, 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!



                                                                                                                            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.






                                                                                                                            share|improve this answer











                                                                                                                            $endgroup$









                                                                                                                            • 1




                                                                                                                              $begingroup$
                                                                                                                              I think you can remove the +1 and simply take the 1-based input, the post states : You may choose to use 1-based indexing
                                                                                                                              $endgroup$
                                                                                                                              – digEmAll
                                                                                                                              yesterday












                                                                                                                            • $begingroup$
                                                                                                                              -4 by switching to scan() for input. I always feel like my scan() solutions are suboptimal, so keep an eye out a shorter way to assign x and n together: n=length(x<-scan());for(i in rep(1:n,n))x[i]=x[x[i]];x Try it online!
                                                                                                                              $endgroup$
                                                                                                                              – CriminallyVulgar
                                                                                                                              13 hours ago














                                                                                                                            2












                                                                                                                            2








                                                                                                                            2





                                                                                                                            $begingroup$


                                                                                                                            R, 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!



                                                                                                                            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.






                                                                                                                            share|improve this answer











                                                                                                                            $endgroup$




                                                                                                                            R, 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!



                                                                                                                            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.







                                                                                                                            share|improve this answer














                                                                                                                            share|improve this answer



                                                                                                                            share|improve this answer








                                                                                                                            edited yesterday

























                                                                                                                            answered 2 days ago









                                                                                                                            ngmngm

                                                                                                                            3,36924




                                                                                                                            3,36924








                                                                                                                            • 1




                                                                                                                              $begingroup$
                                                                                                                              I think you can remove the +1 and simply take the 1-based input, the post states : You may choose to use 1-based indexing
                                                                                                                              $endgroup$
                                                                                                                              – digEmAll
                                                                                                                              yesterday












                                                                                                                            • $begingroup$
                                                                                                                              -4 by switching to scan() for input. I always feel like my scan() solutions are suboptimal, so keep an eye out a shorter way to assign x and n together: n=length(x<-scan());for(i in rep(1:n,n))x[i]=x[x[i]];x Try it online!
                                                                                                                              $endgroup$
                                                                                                                              – CriminallyVulgar
                                                                                                                              13 hours ago














                                                                                                                            • 1




                                                                                                                              $begingroup$
                                                                                                                              I think you can remove the +1 and simply take the 1-based input, the post states : You may choose to use 1-based indexing
                                                                                                                              $endgroup$
                                                                                                                              – digEmAll
                                                                                                                              yesterday












                                                                                                                            • $begingroup$
                                                                                                                              -4 by switching to scan() for input. I always feel like my scan() solutions are suboptimal, so keep an eye out a shorter way to assign x and n together: n=length(x<-scan());for(i in rep(1:n,n))x[i]=x[x[i]];x Try it online!
                                                                                                                              $endgroup$
                                                                                                                              – CriminallyVulgar
                                                                                                                              13 hours ago








                                                                                                                            1




                                                                                                                            1




                                                                                                                            $begingroup$
                                                                                                                            I think you can remove the +1 and simply take the 1-based input, the post states : You may choose to use 1-based indexing
                                                                                                                            $endgroup$
                                                                                                                            – digEmAll
                                                                                                                            yesterday






                                                                                                                            $begingroup$
                                                                                                                            I think you can remove the +1 and simply take the 1-based input, the post states : You may choose to use 1-based indexing
                                                                                                                            $endgroup$
                                                                                                                            – digEmAll
                                                                                                                            yesterday














                                                                                                                            $begingroup$
                                                                                                                            -4 by switching to scan() for input. I always feel like my scan() solutions are suboptimal, so keep an eye out a shorter way to assign x and n together: n=length(x<-scan());for(i in rep(1:n,n))x[i]=x[x[i]];x Try it online!
                                                                                                                            $endgroup$
                                                                                                                            – CriminallyVulgar
                                                                                                                            13 hours ago




                                                                                                                            $begingroup$
                                                                                                                            -4 by switching to scan() for input. I always feel like my scan() solutions are suboptimal, so keep an eye out a shorter way to assign x and n together: n=length(x<-scan());for(i in rep(1:n,n))x[i]=x[x[i]];x Try it online!
                                                                                                                            $endgroup$
                                                                                                                            – CriminallyVulgar
                                                                                                                            13 hours ago











                                                                                                                            2












                                                                                                                            $begingroup$

                                                                                                                            Common Lisp, 59 58 bytes



                                                                                                                            (lambda(a)(dolist(j a)(map-into a(lambda(x)(elt a x))a))a)


                                                                                                                            Try it online!






                                                                                                                            share|improve this answer











                                                                                                                            $endgroup$


















                                                                                                                              2












                                                                                                                              $begingroup$

                                                                                                                              Common Lisp, 59 58 bytes



                                                                                                                              (lambda(a)(dolist(j a)(map-into a(lambda(x)(elt a x))a))a)


                                                                                                                              Try it online!






                                                                                                                              share|improve this answer











                                                                                                                              $endgroup$
















                                                                                                                                2












                                                                                                                                2








                                                                                                                                2





                                                                                                                                $begingroup$

                                                                                                                                Common Lisp, 59 58 bytes



                                                                                                                                (lambda(a)(dolist(j a)(map-into a(lambda(x)(elt a x))a))a)


                                                                                                                                Try it online!






                                                                                                                                share|improve this answer











                                                                                                                                $endgroup$



                                                                                                                                Common Lisp, 59 58 bytes



                                                                                                                                (lambda(a)(dolist(j a)(map-into a(lambda(x)(elt a x))a))a)


                                                                                                                                Try it online!







                                                                                                                                share|improve this answer














                                                                                                                                share|improve this answer



                                                                                                                                share|improve this answer








                                                                                                                                edited yesterday

























                                                                                                                                answered yesterday









                                                                                                                                RenzoRenzo

                                                                                                                                1,730516




                                                                                                                                1,730516























                                                                                                                                    2












                                                                                                                                    $begingroup$


                                                                                                                                    Clojure, 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!






                                                                                                                                    share|improve this answer










                                                                                                                                    New contributor




                                                                                                                                    Ethan McCue is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                                    Check out our Code of Conduct.






                                                                                                                                    $endgroup$













                                                                                                                                    • $begingroup$
                                                                                                                                      Hello and welcome to PPCG. Would it be possible for you to provide a link to an online interpreter such that one could easily verify your solution? Furthermore, can loop [ not become loop[?
                                                                                                                                      $endgroup$
                                                                                                                                      – Jonathan Frech
                                                                                                                                      2 days ago






                                                                                                                                    • 1




                                                                                                                                      $begingroup$
                                                                                                                                      The most recent edit should fix the test failures. Sorry for the inconvenience everybody.
                                                                                                                                      $endgroup$
                                                                                                                                      – Ethan McCue
                                                                                                                                      7 hours ago
















                                                                                                                                    2












                                                                                                                                    $begingroup$


                                                                                                                                    Clojure, 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!






                                                                                                                                    share|improve this answer










                                                                                                                                    New contributor




                                                                                                                                    Ethan McCue is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                                    Check out our Code of Conduct.






                                                                                                                                    $endgroup$













                                                                                                                                    • $begingroup$
                                                                                                                                      Hello and welcome to PPCG. Would it be possible for you to provide a link to an online interpreter such that one could easily verify your solution? Furthermore, can loop [ not become loop[?
                                                                                                                                      $endgroup$
                                                                                                                                      – Jonathan Frech
                                                                                                                                      2 days ago






                                                                                                                                    • 1




                                                                                                                                      $begingroup$
                                                                                                                                      The most recent edit should fix the test failures. Sorry for the inconvenience everybody.
                                                                                                                                      $endgroup$
                                                                                                                                      – Ethan McCue
                                                                                                                                      7 hours ago














                                                                                                                                    2












                                                                                                                                    2








                                                                                                                                    2





                                                                                                                                    $begingroup$


                                                                                                                                    Clojure, 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!






                                                                                                                                    share|improve this answer










                                                                                                                                    New contributor




                                                                                                                                    Ethan McCue is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                                    Check out our Code of Conduct.






                                                                                                                                    $endgroup$




                                                                                                                                    Clojure, 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!







                                                                                                                                    share|improve this answer










                                                                                                                                    New contributor




                                                                                                                                    Ethan McCue is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                                    Check out our Code of Conduct.









                                                                                                                                    share|improve this answer



                                                                                                                                    share|improve this answer








                                                                                                                                    edited 7 hours ago





















                                                                                                                                    New contributor




                                                                                                                                    Ethan McCue is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                                    Check out our Code of Conduct.









                                                                                                                                    answered 2 days ago









                                                                                                                                    Ethan McCueEthan McCue

                                                                                                                                    212




                                                                                                                                    212




                                                                                                                                    New contributor




                                                                                                                                    Ethan McCue is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                                    Check out our Code of Conduct.





                                                                                                                                    New contributor





                                                                                                                                    Ethan McCue is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                                    Check out our Code of Conduct.






                                                                                                                                    Ethan McCue is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                                    Check out our Code of Conduct.












                                                                                                                                    • $begingroup$
                                                                                                                                      Hello and welcome to PPCG. Would it be possible for you to provide a link to an online interpreter such that one could easily verify your solution? Furthermore, can loop [ not become loop[?
                                                                                                                                      $endgroup$
                                                                                                                                      – Jonathan Frech
                                                                                                                                      2 days ago






                                                                                                                                    • 1




                                                                                                                                      $begingroup$
                                                                                                                                      The most recent edit should fix the test failures. Sorry for the inconvenience everybody.
                                                                                                                                      $endgroup$
                                                                                                                                      – Ethan McCue
                                                                                                                                      7 hours ago


















                                                                                                                                    • $begingroup$
                                                                                                                                      Hello and welcome to PPCG. Would it be possible for you to provide a link to an online interpreter such that one could easily verify your solution? Furthermore, can loop [ not become loop[?
                                                                                                                                      $endgroup$
                                                                                                                                      – Jonathan Frech
                                                                                                                                      2 days ago






                                                                                                                                    • 1




                                                                                                                                      $begingroup$
                                                                                                                                      The most recent edit should fix the test failures. Sorry for the inconvenience everybody.
                                                                                                                                      $endgroup$
                                                                                                                                      – Ethan McCue
                                                                                                                                      7 hours ago
















                                                                                                                                    $begingroup$
                                                                                                                                    Hello and welcome to PPCG. Would it be possible for you to provide a link to an online interpreter such that one could easily verify your solution? Furthermore, can loop [ not become loop[?
                                                                                                                                    $endgroup$
                                                                                                                                    – Jonathan Frech
                                                                                                                                    2 days ago




                                                                                                                                    $begingroup$
                                                                                                                                    Hello and welcome to PPCG. Would it be possible for you to provide a link to an online interpreter such that one could easily verify your solution? Furthermore, can loop [ not become loop[?
                                                                                                                                    $endgroup$
                                                                                                                                    – Jonathan Frech
                                                                                                                                    2 days ago




                                                                                                                                    1




                                                                                                                                    1




                                                                                                                                    $begingroup$
                                                                                                                                    The most recent edit should fix the test failures. Sorry for the inconvenience everybody.
                                                                                                                                    $endgroup$
                                                                                                                                    – Ethan McCue
                                                                                                                                    7 hours ago




                                                                                                                                    $begingroup$
                                                                                                                                    The most recent edit should fix the test failures. Sorry for the inconvenience everybody.
                                                                                                                                    $endgroup$
                                                                                                                                    – Ethan McCue
                                                                                                                                    7 hours ago











                                                                                                                                    1












                                                                                                                                    $begingroup$

                                                                                                                                    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



                                                                                                                                    $_=$F[$_]for@F;/@F/ or$_="@F",redo


                                                                                                                                    34 bytes



                                                                                                                                    $_=$F[$_]for@F;$_="@F",redo if!/@F/


                                                                                                                                    35 bytes






                                                                                                                                    share|improve this answer











                                                                                                                                    $endgroup$


















                                                                                                                                      1












                                                                                                                                      $begingroup$

                                                                                                                                      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



                                                                                                                                      $_=$F[$_]for@F;/@F/ or$_="@F",redo


                                                                                                                                      34 bytes



                                                                                                                                      $_=$F[$_]for@F;$_="@F",redo if!/@F/


                                                                                                                                      35 bytes






                                                                                                                                      share|improve this answer











                                                                                                                                      $endgroup$
















                                                                                                                                        1












                                                                                                                                        1








                                                                                                                                        1





                                                                                                                                        $begingroup$

                                                                                                                                        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



                                                                                                                                        $_=$F[$_]for@F;/@F/ or$_="@F",redo


                                                                                                                                        34 bytes



                                                                                                                                        $_=$F[$_]for@F;$_="@F",redo if!/@F/


                                                                                                                                        35 bytes






                                                                                                                                        share|improve this answer











                                                                                                                                        $endgroup$



                                                                                                                                        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



                                                                                                                                        $_=$F[$_]for@F;/@F/ or$_="@F",redo


                                                                                                                                        34 bytes



                                                                                                                                        $_=$F[$_]for@F;$_="@F",redo if!/@F/


                                                                                                                                        35 bytes







                                                                                                                                        share|improve this answer














                                                                                                                                        share|improve this answer



                                                                                                                                        share|improve this answer








                                                                                                                                        edited yesterday

























                                                                                                                                        answered 2 days ago









                                                                                                                                        Nahuel FouilleulNahuel Fouilleul

                                                                                                                                        1,84028




                                                                                                                                        1,84028























                                                                                                                                            1












                                                                                                                                            $begingroup$


                                                                                                                                            Clojure, 88 bytes





                                                                                                                                            #(reduce(fn[x i](assoc x i(get x(get x i))))%(flatten(repeat(count %)(range(count %)))))


                                                                                                                                            Try it online!






                                                                                                                                            share|improve this answer









                                                                                                                                            $endgroup$


















                                                                                                                                              1












                                                                                                                                              $begingroup$


                                                                                                                                              Clojure, 88 bytes





                                                                                                                                              #(reduce(fn[x i](assoc x i(get x(get x i))))%(flatten(repeat(count %)(range(count %)))))


                                                                                                                                              Try it online!






                                                                                                                                              share|improve this answer









                                                                                                                                              $endgroup$
















                                                                                                                                                1












                                                                                                                                                1








                                                                                                                                                1





                                                                                                                                                $begingroup$


                                                                                                                                                Clojure, 88 bytes





                                                                                                                                                #(reduce(fn[x i](assoc x i(get x(get x i))))%(flatten(repeat(count %)(range(count %)))))


                                                                                                                                                Try it online!






                                                                                                                                                share|improve this answer









                                                                                                                                                $endgroup$




                                                                                                                                                Clojure, 88 bytes





                                                                                                                                                #(reduce(fn[x i](assoc x i(get x(get x i))))%(flatten(repeat(count %)(range(count %)))))


                                                                                                                                                Try it online!







                                                                                                                                                share|improve this answer












                                                                                                                                                share|improve this answer



                                                                                                                                                share|improve this answer










                                                                                                                                                answered yesterday









                                                                                                                                                Kirill L.Kirill L.

                                                                                                                                                3,9451319




                                                                                                                                                3,9451319























                                                                                                                                                    1












                                                                                                                                                    $begingroup$


                                                                                                                                                    Charcoal, 16 bytes



                                                                                                                                                    FθFLθ§≔θκ§θ§θκIθ


                                                                                                                                                    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:



                                                                                                                                                    Fθ


                                                                                                                                                    Repeat the inner loop once for each element. This just ensures that the result stabilises.



                                                                                                                                                    FLθ


                                                                                                                                                    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.



                                                                                                                                                    Iθ


                                                                                                                                                    Cast the elements to string and implicitly print each on their own line.






                                                                                                                                                    share|improve this answer









                                                                                                                                                    $endgroup$


















                                                                                                                                                      1












                                                                                                                                                      $begingroup$


                                                                                                                                                      Charcoal, 16 bytes



                                                                                                                                                      FθFLθ§≔θκ§θ§θκIθ


                                                                                                                                                      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:



                                                                                                                                                      Fθ


                                                                                                                                                      Repeat the inner loop once for each element. This just ensures that the result stabilises.



                                                                                                                                                      FLθ


                                                                                                                                                      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.



                                                                                                                                                      Iθ


                                                                                                                                                      Cast the elements to string and implicitly print each on their own line.






                                                                                                                                                      share|improve this answer









                                                                                                                                                      $endgroup$
















                                                                                                                                                        1












                                                                                                                                                        1








                                                                                                                                                        1





                                                                                                                                                        $begingroup$


                                                                                                                                                        Charcoal, 16 bytes



                                                                                                                                                        FθFLθ§≔θκ§θ§θκIθ


                                                                                                                                                        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:



                                                                                                                                                        Fθ


                                                                                                                                                        Repeat the inner loop once for each element. This just ensures that the result stabilises.



                                                                                                                                                        FLθ


                                                                                                                                                        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.



                                                                                                                                                        Iθ


                                                                                                                                                        Cast the elements to string and implicitly print each on their own line.






                                                                                                                                                        share|improve this answer









                                                                                                                                                        $endgroup$




                                                                                                                                                        Charcoal, 16 bytes



                                                                                                                                                        FθFLθ§≔θκ§θ§θκIθ


                                                                                                                                                        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:



                                                                                                                                                        Fθ


                                                                                                                                                        Repeat the inner loop once for each element. This just ensures that the result stabilises.



                                                                                                                                                        FLθ


                                                                                                                                                        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.



                                                                                                                                                        Iθ


                                                                                                                                                        Cast the elements to string and implicitly print each on their own line.







                                                                                                                                                        share|improve this answer












                                                                                                                                                        share|improve this answer



                                                                                                                                                        share|improve this answer










                                                                                                                                                        answered yesterday









                                                                                                                                                        NeilNeil

                                                                                                                                                        80k744178




                                                                                                                                                        80k744178























                                                                                                                                                            1












                                                                                                                                                            $begingroup$


                                                                                                                                                            Clean, 80 bytes



                                                                                                                                                            import StdEnv




                                                                                                                                                            limit o iterateb=foldl(l i=updateAt i(l!!(l!!i))l)b(indexList b)


                                                                                                                                                            Try it online!






                                                                                                                                                            share|improve this answer









                                                                                                                                                            $endgroup$


















                                                                                                                                                              1












                                                                                                                                                              $begingroup$


                                                                                                                                                              Clean, 80 bytes



                                                                                                                                                              import StdEnv




                                                                                                                                                              limit o iterateb=foldl(l i=updateAt i(l!!(l!!i))l)b(indexList b)


                                                                                                                                                              Try it online!






                                                                                                                                                              share|improve this answer









                                                                                                                                                              $endgroup$
















                                                                                                                                                                1












                                                                                                                                                                1








                                                                                                                                                                1





                                                                                                                                                                $begingroup$


                                                                                                                                                                Clean, 80 bytes



                                                                                                                                                                import StdEnv




                                                                                                                                                                limit o iterateb=foldl(l i=updateAt i(l!!(l!!i))l)b(indexList b)


                                                                                                                                                                Try it online!






                                                                                                                                                                share|improve this answer









                                                                                                                                                                $endgroup$




                                                                                                                                                                Clean, 80 bytes



                                                                                                                                                                import StdEnv




                                                                                                                                                                limit o iterateb=foldl(l i=updateAt i(l!!(l!!i))l)b(indexList b)


                                                                                                                                                                Try it online!







                                                                                                                                                                share|improve this answer












                                                                                                                                                                share|improve this answer



                                                                                                                                                                share|improve this answer










                                                                                                                                                                answered yesterday









                                                                                                                                                                ΟurousΟurous

                                                                                                                                                                6,63211033




                                                                                                                                                                6,63211033























                                                                                                                                                                    1












                                                                                                                                                                    $begingroup$

                                                                                                                                                                    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.






                                                                                                                                                                    share|improve this answer











                                                                                                                                                                    $endgroup$


















                                                                                                                                                                      1












                                                                                                                                                                      $begingroup$

                                                                                                                                                                      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.






                                                                                                                                                                      share|improve this answer











                                                                                                                                                                      $endgroup$
















                                                                                                                                                                        1












                                                                                                                                                                        1








                                                                                                                                                                        1





                                                                                                                                                                        $begingroup$

                                                                                                                                                                        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.






                                                                                                                                                                        share|improve this answer











                                                                                                                                                                        $endgroup$



                                                                                                                                                                        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.







                                                                                                                                                                        share|improve this answer














                                                                                                                                                                        share|improve this answer



                                                                                                                                                                        share|improve this answer








                                                                                                                                                                        edited 9 hours ago

























                                                                                                                                                                        answered 9 hours ago









                                                                                                                                                                        LSM07LSM07

                                                                                                                                                                        1213




                                                                                                                                                                        1213






























                                                                                                                                                                            draft saved

                                                                                                                                                                            draft discarded




















































                                                                                                                                                                            If this is an answer to a challenge…




                                                                                                                                                                            • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                                                                                                                                                            • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                                                                                                                                                              Explanations of your answer make it more interesting to read and are very much encouraged.


                                                                                                                                                                            • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.



                                                                                                                                                                            More generally…




                                                                                                                                                                            • …Please make sure to answer the question and provide sufficient detail.


                                                                                                                                                                            • …Avoid asking for help, clarification or responding to other answers (use comments instead).





                                                                                                                                                                            draft saved


                                                                                                                                                                            draft discarded














                                                                                                                                                                            StackExchange.ready(
                                                                                                                                                                            function () {
                                                                                                                                                                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f179050%2fpointer-jumping%23new-answer', 'question_page');
                                                                                                                                                                            }
                                                                                                                                                                            );

                                                                                                                                                                            Post as a guest















                                                                                                                                                                            Required, but never shown





















































                                                                                                                                                                            Required, but never shown














                                                                                                                                                                            Required, but never shown












                                                                                                                                                                            Required, but never shown







                                                                                                                                                                            Required, but never shown

































                                                                                                                                                                            Required, but never shown














                                                                                                                                                                            Required, but never shown












                                                                                                                                                                            Required, but never shown







                                                                                                                                                                            Required, but never shown