Elegant way of partitioning in two starting from the second element?

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











up vote
4
down vote

favorite












I wrote a code for partitioning a list. I want to group them into two groups following the same pattern: 1. element added, then 2. and 3. are omitted, then 4. and 5. added and goes like this. Partitioning is easy, then I have to add the first element manually but the problem is when I partition the list, it omits the last element because then the list contains odd number of elements and I have to add it to the list manually also. I thought maybe someone can figure out a more elegant way. My list is as follow:



 vars= c0r, c0i, c1r, c1i, c2r, c2i, c3r, c3i, c4r, c4i, c5r, c5i, c6r, 
c6i, c7r, c7i, c8r, c8i, c9r, c9i, c10r, c10i, c11r, c11i, c12r,
c12i, c13r, c13i, c14r, c14i, c15r, c15i


and here is my code;



 varr1 = Partition[vars[[2 ;;]], 2]

c0i, c1r, c1i, c2r, c2i, c3r, c3i, c4r, c4i, c5r, c5i,
c6r, c6i, c7r, c7i, c8r, c8i, c9r, c9i, c10r, c10i,
c11r, c11i, c12r, c12i, c13r, c13i, c14r, c14i, c15r

Join[vars[[1]], Flatten[varr1[[2 ;; ;; 2]]], vars[[-1]]]

c0r, c1i, c2r, c3i, c4r, c5i, c6r, c7i, c8r, c9i, c10r, c11i, c12r,
c13i, c14r, c15i


and this is the list I want.










share|improve this question



























    up vote
    4
    down vote

    favorite












    I wrote a code for partitioning a list. I want to group them into two groups following the same pattern: 1. element added, then 2. and 3. are omitted, then 4. and 5. added and goes like this. Partitioning is easy, then I have to add the first element manually but the problem is when I partition the list, it omits the last element because then the list contains odd number of elements and I have to add it to the list manually also. I thought maybe someone can figure out a more elegant way. My list is as follow:



     vars= c0r, c0i, c1r, c1i, c2r, c2i, c3r, c3i, c4r, c4i, c5r, c5i, c6r, 
    c6i, c7r, c7i, c8r, c8i, c9r, c9i, c10r, c10i, c11r, c11i, c12r,
    c12i, c13r, c13i, c14r, c14i, c15r, c15i


    and here is my code;



     varr1 = Partition[vars[[2 ;;]], 2]

    c0i, c1r, c1i, c2r, c2i, c3r, c3i, c4r, c4i, c5r, c5i,
    c6r, c6i, c7r, c7i, c8r, c8i, c9r, c9i, c10r, c10i,
    c11r, c11i, c12r, c12i, c13r, c13i, c14r, c14i, c15r

    Join[vars[[1]], Flatten[varr1[[2 ;; ;; 2]]], vars[[-1]]]

    c0r, c1i, c2r, c3i, c4r, c5i, c6r, c7i, c8r, c9i, c10r, c11i, c12r,
    c13i, c14r, c15i


    and this is the list I want.










    share|improve this question

























      up vote
      4
      down vote

      favorite









      up vote
      4
      down vote

      favorite











      I wrote a code for partitioning a list. I want to group them into two groups following the same pattern: 1. element added, then 2. and 3. are omitted, then 4. and 5. added and goes like this. Partitioning is easy, then I have to add the first element manually but the problem is when I partition the list, it omits the last element because then the list contains odd number of elements and I have to add it to the list manually also. I thought maybe someone can figure out a more elegant way. My list is as follow:



       vars= c0r, c0i, c1r, c1i, c2r, c2i, c3r, c3i, c4r, c4i, c5r, c5i, c6r, 
      c6i, c7r, c7i, c8r, c8i, c9r, c9i, c10r, c10i, c11r, c11i, c12r,
      c12i, c13r, c13i, c14r, c14i, c15r, c15i


      and here is my code;



       varr1 = Partition[vars[[2 ;;]], 2]

      c0i, c1r, c1i, c2r, c2i, c3r, c3i, c4r, c4i, c5r, c5i,
      c6r, c6i, c7r, c7i, c8r, c8i, c9r, c9i, c10r, c10i,
      c11r, c11i, c12r, c12i, c13r, c13i, c14r, c14i, c15r

      Join[vars[[1]], Flatten[varr1[[2 ;; ;; 2]]], vars[[-1]]]

      c0r, c1i, c2r, c3i, c4r, c5i, c6r, c7i, c8r, c9i, c10r, c11i, c12r,
      c13i, c14r, c15i


      and this is the list I want.










      share|improve this question















      I wrote a code for partitioning a list. I want to group them into two groups following the same pattern: 1. element added, then 2. and 3. are omitted, then 4. and 5. added and goes like this. Partitioning is easy, then I have to add the first element manually but the problem is when I partition the list, it omits the last element because then the list contains odd number of elements and I have to add it to the list manually also. I thought maybe someone can figure out a more elegant way. My list is as follow:



       vars= c0r, c0i, c1r, c1i, c2r, c2i, c3r, c3i, c4r, c4i, c5r, c5i, c6r, 
      c6i, c7r, c7i, c8r, c8i, c9r, c9i, c10r, c10i, c11r, c11i, c12r,
      c12i, c13r, c13i, c14r, c14i, c15r, c15i


      and here is my code;



       varr1 = Partition[vars[[2 ;;]], 2]

      c0i, c1r, c1i, c2r, c2i, c3r, c3i, c4r, c4i, c5r, c5i,
      c6r, c6i, c7r, c7i, c8r, c8i, c9r, c9i, c10r, c10i,
      c11r, c11i, c12r, c12i, c13r, c13i, c14r, c14i, c15r

      Join[vars[[1]], Flatten[varr1[[2 ;; ;; 2]]], vars[[-1]]]

      c0r, c1i, c2r, c3i, c4r, c5i, c6r, c7i, c8r, c9i, c10r, c11i, c12r,
      c13i, c14r, c15i


      and this is the list I want.







      list-manipulation






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 hours ago

























      asked 2 hours ago









      Buddha_the_Scientist

      6715




      6715




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          You can use the five-argument form of Partition:



          Flatten[Partition[vars, 2, 4, -1, 1, ]]



          c0r, c1i, c2r, c3i, c4r, c5i, c6r, c7i, c8r, c9i, c10r, c11i, c12r,
          c13i, c14r, c15i




          You can also use



          Pick[#, Mod[Range @ Length @ #, 4], 1 | 0]& @ vars 
          Flatten[Partition[vars, 4][[All, 1, -1]]]
          Flatten[List @@@ ListConvolve[1, 0, 0, 1, vars][[ ;; ;; 4]]]





          share|improve this answer






















          • You find the more clever way of picking them as first and third.
            – Buddha_the_Scientist
            1 hour ago










          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: "387"
          ;
          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: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f183538%2felegant-way-of-partitioning-in-two-starting-from-the-second-element%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote



          accepted










          You can use the five-argument form of Partition:



          Flatten[Partition[vars, 2, 4, -1, 1, ]]



          c0r, c1i, c2r, c3i, c4r, c5i, c6r, c7i, c8r, c9i, c10r, c11i, c12r,
          c13i, c14r, c15i




          You can also use



          Pick[#, Mod[Range @ Length @ #, 4], 1 | 0]& @ vars 
          Flatten[Partition[vars, 4][[All, 1, -1]]]
          Flatten[List @@@ ListConvolve[1, 0, 0, 1, vars][[ ;; ;; 4]]]





          share|improve this answer






















          • You find the more clever way of picking them as first and third.
            – Buddha_the_Scientist
            1 hour ago














          up vote
          3
          down vote



          accepted










          You can use the five-argument form of Partition:



          Flatten[Partition[vars, 2, 4, -1, 1, ]]



          c0r, c1i, c2r, c3i, c4r, c5i, c6r, c7i, c8r, c9i, c10r, c11i, c12r,
          c13i, c14r, c15i




          You can also use



          Pick[#, Mod[Range @ Length @ #, 4], 1 | 0]& @ vars 
          Flatten[Partition[vars, 4][[All, 1, -1]]]
          Flatten[List @@@ ListConvolve[1, 0, 0, 1, vars][[ ;; ;; 4]]]





          share|improve this answer






















          • You find the more clever way of picking them as first and third.
            – Buddha_the_Scientist
            1 hour ago












          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          You can use the five-argument form of Partition:



          Flatten[Partition[vars, 2, 4, -1, 1, ]]



          c0r, c1i, c2r, c3i, c4r, c5i, c6r, c7i, c8r, c9i, c10r, c11i, c12r,
          c13i, c14r, c15i




          You can also use



          Pick[#, Mod[Range @ Length @ #, 4], 1 | 0]& @ vars 
          Flatten[Partition[vars, 4][[All, 1, -1]]]
          Flatten[List @@@ ListConvolve[1, 0, 0, 1, vars][[ ;; ;; 4]]]





          share|improve this answer














          You can use the five-argument form of Partition:



          Flatten[Partition[vars, 2, 4, -1, 1, ]]



          c0r, c1i, c2r, c3i, c4r, c5i, c6r, c7i, c8r, c9i, c10r, c11i, c12r,
          c13i, c14r, c15i




          You can also use



          Pick[#, Mod[Range @ Length @ #, 4], 1 | 0]& @ vars 
          Flatten[Partition[vars, 4][[All, 1, -1]]]
          Flatten[List @@@ ListConvolve[1, 0, 0, 1, vars][[ ;; ;; 4]]]






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 1 hour ago

























          answered 1 hour ago









          kglr

          164k8188388




          164k8188388











          • You find the more clever way of picking them as first and third.
            – Buddha_the_Scientist
            1 hour ago
















          • You find the more clever way of picking them as first and third.
            – Buddha_the_Scientist
            1 hour ago















          You find the more clever way of picking them as first and third.
          – Buddha_the_Scientist
          1 hour ago




          You find the more clever way of picking them as first and third.
          – Buddha_the_Scientist
          1 hour ago

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f183538%2felegant-way-of-partitioning-in-two-starting-from-the-second-element%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          What does second last employer means? [closed]

          Installing NextGIS Connect into QGIS 3?

          One-line joke