Find median of a circular set

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite
1












Given a set of elements and a number $k$, each element is as a disc has a number from $0$ to $k-1$ written around its circumference. Consecutive numbers are adjacent to each other, i.e., $1$ is between $0$ and $2$, and because the discs are circular, $0$ is between $k-1$ and $1$.



Discs can rotate freely in either direction, we can only rotate one disc at a time, and it takes $1$ second to rotate it by one position) find the smallest number we should choose to make all elements equal and that number costs minimum steps.



E.g.: set = $[2,7,1]$, $k = 10$; the output should be $1$.



It takes $1$ step for the first element to reach $1$ $(2 to 1)$.
It takes $4$ steps for the second element to reach $1$ $(7 to 8 to 9 to 0 to 1)$. The third element is already at $1$.



I tried to find the median but it do not work out (or may be i find it wrong) and although sometime the steps is minimum but the number is not.



Is finding median of a circle is answer for this problem, if it is not, what should anothor approach should I consider?







share|cite|improve this question

























    up vote
    0
    down vote

    favorite
    1












    Given a set of elements and a number $k$, each element is as a disc has a number from $0$ to $k-1$ written around its circumference. Consecutive numbers are adjacent to each other, i.e., $1$ is between $0$ and $2$, and because the discs are circular, $0$ is between $k-1$ and $1$.



    Discs can rotate freely in either direction, we can only rotate one disc at a time, and it takes $1$ second to rotate it by one position) find the smallest number we should choose to make all elements equal and that number costs minimum steps.



    E.g.: set = $[2,7,1]$, $k = 10$; the output should be $1$.



    It takes $1$ step for the first element to reach $1$ $(2 to 1)$.
    It takes $4$ steps for the second element to reach $1$ $(7 to 8 to 9 to 0 to 1)$. The third element is already at $1$.



    I tried to find the median but it do not work out (or may be i find it wrong) and although sometime the steps is minimum but the number is not.



    Is finding median of a circle is answer for this problem, if it is not, what should anothor approach should I consider?







    share|cite|improve this question























      up vote
      0
      down vote

      favorite
      1









      up vote
      0
      down vote

      favorite
      1






      1





      Given a set of elements and a number $k$, each element is as a disc has a number from $0$ to $k-1$ written around its circumference. Consecutive numbers are adjacent to each other, i.e., $1$ is between $0$ and $2$, and because the discs are circular, $0$ is between $k-1$ and $1$.



      Discs can rotate freely in either direction, we can only rotate one disc at a time, and it takes $1$ second to rotate it by one position) find the smallest number we should choose to make all elements equal and that number costs minimum steps.



      E.g.: set = $[2,7,1]$, $k = 10$; the output should be $1$.



      It takes $1$ step for the first element to reach $1$ $(2 to 1)$.
      It takes $4$ steps for the second element to reach $1$ $(7 to 8 to 9 to 0 to 1)$. The third element is already at $1$.



      I tried to find the median but it do not work out (or may be i find it wrong) and although sometime the steps is minimum but the number is not.



      Is finding median of a circle is answer for this problem, if it is not, what should anothor approach should I consider?







      share|cite|improve this question













      Given a set of elements and a number $k$, each element is as a disc has a number from $0$ to $k-1$ written around its circumference. Consecutive numbers are adjacent to each other, i.e., $1$ is between $0$ and $2$, and because the discs are circular, $0$ is between $k-1$ and $1$.



      Discs can rotate freely in either direction, we can only rotate one disc at a time, and it takes $1$ second to rotate it by one position) find the smallest number we should choose to make all elements equal and that number costs minimum steps.



      E.g.: set = $[2,7,1]$, $k = 10$; the output should be $1$.



      It takes $1$ step for the first element to reach $1$ $(2 to 1)$.
      It takes $4$ steps for the second element to reach $1$ $(7 to 8 to 9 to 0 to 1)$. The third element is already at $1$.



      I tried to find the median but it do not work out (or may be i find it wrong) and although sometime the steps is minimum but the number is not.



      Is finding median of a circle is answer for this problem, if it is not, what should anothor approach should I consider?









      share|cite|improve this question












      share|cite|improve this question




      share|cite|improve this question








      edited Jul 24 at 13:30









      Rodrigo de Azevedo

      12.6k41751




      12.6k41751









      asked Jul 24 at 13:00









      Zac Jonathan

      545




      545

























          active

          oldest

          votes











          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.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "69"
          ;
          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',
          convertImagesToLinks: true,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          noCode: true, onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2861309%2ffind-median-of-a-circular-set%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes










           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2861309%2ffind-median-of-a-circular-set%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          What is the equation of a 3D cone with generalised tilt?

          Relationship between determinant of matrix and determinant of adjoint?

          Color the edges and diagonals of a regular polygon