Binary self-rotation












13












$begingroup$


Given a binary 3D array, for each layer, cyclically rotate up each of its columns as many steps as indicated by the binary encoding of the columns of the layer above it, and then cyclically rotate left each of its rows as many steps as indicated by the binary encoding of the rows of the layer below it.



There will always be at least three layers. The top layer's columns and the bottom layer's rows should not be rotated.



Walk-through



Lets start with the small 4-layer, 2-row, 3-column array:



[[[1,0,1],
[1,0,0]],

[[1,0,1],
[0,1,1]],

[[0,1,1],
[1,1,1]],

[[1,1,0],
[1,1,1]]]


The first step is evaluating the numbers encoded in binary by the columns and rows of each layer:



     3 0 2
5 [[[1,0,1],
4 [1,0,0]],

2 1 3
5 [[1,0,1],
3 [0,1,1]],

1 3 3
3 [[0,1,1],
7 [1,1,1]],

3 3 1
6 [[1,1,0],
7 [1,1,1]]]


The first layer, [[1,0,1],[1,0,0]] will not have its columns rotated, but its rows will be cyclically rotated left 5 steps and 3 step respectively, thus becoming [[1,1,0],[1,0,0]].

 The second layer, [[1,0,1],[0,1,1]], will have its columns cyclically rotated up 3, 0, and 2 steps respectively, giving [[0,0,1],[1,1,1]], and then the rows are cyclically rotated left 3 and 7 steps respectively, with no visible change.

 The third layer, [[0,1,1],[1,1,1]] rotated up 2, 1, and 3 steps stays the same, and neither does rotating left 6 and 7 steps do anything.

 Finally, the fourth layer, [[1,1,0],[1,1,1]] rotated up 1, 3, and 3 steps is [[1,1,1],[1,1,0]], but its rows are not rotated afterwards, as it is the last layer.

 Putting all the layers together again, gives us the binary self-rotated 3D array:



[[[1,1,0],
[1,0,0]],

[[0,0,1],
[1,1,1]],

[[0,1,1],
[1,1,1]],

[[1,1,1],
[1,1,0]]]


Example cases:



[[[1,0,1],[1,0,0]],[[1,0,1],[0,1,1]],[[0,1,1],[1,1,1]],[[1,1,0],[1,1,1]]] gives
[[[1,1,0],[1,0,0]],[[0,0,1],[1,1,1]],[[0,1,1],[1,1,1]],[[1,1,1],[1,1,0]]]



[[[1]],[[1]],[[0]]] gives
[[[1]],[[1]],[[0]]]



[[[1,0,1],[1,0,1],[1,0,1]],[[0,0,1],[0,0,1],[0,0,1]],[[1,0,0],[1,0,1],[0,0,1]]] gives
[[[0,1,1],[0,1,1],[0,1,1]],[[0,1,0],[1,0,0],[0,1,0]],[[1,0,1],[1,0,1],[0,0,0]]]










share|improve this question









$endgroup$

















    13












    $begingroup$


    Given a binary 3D array, for each layer, cyclically rotate up each of its columns as many steps as indicated by the binary encoding of the columns of the layer above it, and then cyclically rotate left each of its rows as many steps as indicated by the binary encoding of the rows of the layer below it.



    There will always be at least three layers. The top layer's columns and the bottom layer's rows should not be rotated.



    Walk-through



    Lets start with the small 4-layer, 2-row, 3-column array:



    [[[1,0,1],
    [1,0,0]],

    [[1,0,1],
    [0,1,1]],

    [[0,1,1],
    [1,1,1]],

    [[1,1,0],
    [1,1,1]]]


    The first step is evaluating the numbers encoded in binary by the columns and rows of each layer:



         3 0 2
    5 [[[1,0,1],
    4 [1,0,0]],

    2 1 3
    5 [[1,0,1],
    3 [0,1,1]],

    1 3 3
    3 [[0,1,1],
    7 [1,1,1]],

    3 3 1
    6 [[1,1,0],
    7 [1,1,1]]]


    The first layer, [[1,0,1],[1,0,0]] will not have its columns rotated, but its rows will be cyclically rotated left 5 steps and 3 step respectively, thus becoming [[1,1,0],[1,0,0]].

     The second layer, [[1,0,1],[0,1,1]], will have its columns cyclically rotated up 3, 0, and 2 steps respectively, giving [[0,0,1],[1,1,1]], and then the rows are cyclically rotated left 3 and 7 steps respectively, with no visible change.

     The third layer, [[0,1,1],[1,1,1]] rotated up 2, 1, and 3 steps stays the same, and neither does rotating left 6 and 7 steps do anything.

     Finally, the fourth layer, [[1,1,0],[1,1,1]] rotated up 1, 3, and 3 steps is [[1,1,1],[1,1,0]], but its rows are not rotated afterwards, as it is the last layer.

     Putting all the layers together again, gives us the binary self-rotated 3D array:



    [[[1,1,0],
    [1,0,0]],

    [[0,0,1],
    [1,1,1]],

    [[0,1,1],
    [1,1,1]],

    [[1,1,1],
    [1,1,0]]]


    Example cases:



    [[[1,0,1],[1,0,0]],[[1,0,1],[0,1,1]],[[0,1,1],[1,1,1]],[[1,1,0],[1,1,1]]] gives
    [[[1,1,0],[1,0,0]],[[0,0,1],[1,1,1]],[[0,1,1],[1,1,1]],[[1,1,1],[1,1,0]]]



    [[[1]],[[1]],[[0]]] gives
    [[[1]],[[1]],[[0]]]



    [[[1,0,1],[1,0,1],[1,0,1]],[[0,0,1],[0,0,1],[0,0,1]],[[1,0,0],[1,0,1],[0,0,1]]] gives
    [[[0,1,1],[0,1,1],[0,1,1]],[[0,1,0],[1,0,0],[0,1,0]],[[1,0,1],[1,0,1],[0,0,0]]]










    share|improve this question









    $endgroup$















      13












      13








      13





      $begingroup$


      Given a binary 3D array, for each layer, cyclically rotate up each of its columns as many steps as indicated by the binary encoding of the columns of the layer above it, and then cyclically rotate left each of its rows as many steps as indicated by the binary encoding of the rows of the layer below it.



      There will always be at least three layers. The top layer's columns and the bottom layer's rows should not be rotated.



      Walk-through



      Lets start with the small 4-layer, 2-row, 3-column array:



      [[[1,0,1],
      [1,0,0]],

      [[1,0,1],
      [0,1,1]],

      [[0,1,1],
      [1,1,1]],

      [[1,1,0],
      [1,1,1]]]


      The first step is evaluating the numbers encoded in binary by the columns and rows of each layer:



           3 0 2
      5 [[[1,0,1],
      4 [1,0,0]],

      2 1 3
      5 [[1,0,1],
      3 [0,1,1]],

      1 3 3
      3 [[0,1,1],
      7 [1,1,1]],

      3 3 1
      6 [[1,1,0],
      7 [1,1,1]]]


      The first layer, [[1,0,1],[1,0,0]] will not have its columns rotated, but its rows will be cyclically rotated left 5 steps and 3 step respectively, thus becoming [[1,1,0],[1,0,0]].

       The second layer, [[1,0,1],[0,1,1]], will have its columns cyclically rotated up 3, 0, and 2 steps respectively, giving [[0,0,1],[1,1,1]], and then the rows are cyclically rotated left 3 and 7 steps respectively, with no visible change.

       The third layer, [[0,1,1],[1,1,1]] rotated up 2, 1, and 3 steps stays the same, and neither does rotating left 6 and 7 steps do anything.

       Finally, the fourth layer, [[1,1,0],[1,1,1]] rotated up 1, 3, and 3 steps is [[1,1,1],[1,1,0]], but its rows are not rotated afterwards, as it is the last layer.

       Putting all the layers together again, gives us the binary self-rotated 3D array:



      [[[1,1,0],
      [1,0,0]],

      [[0,0,1],
      [1,1,1]],

      [[0,1,1],
      [1,1,1]],

      [[1,1,1],
      [1,1,0]]]


      Example cases:



      [[[1,0,1],[1,0,0]],[[1,0,1],[0,1,1]],[[0,1,1],[1,1,1]],[[1,1,0],[1,1,1]]] gives
      [[[1,1,0],[1,0,0]],[[0,0,1],[1,1,1]],[[0,1,1],[1,1,1]],[[1,1,1],[1,1,0]]]



      [[[1]],[[1]],[[0]]] gives
      [[[1]],[[1]],[[0]]]



      [[[1,0,1],[1,0,1],[1,0,1]],[[0,0,1],[0,0,1],[0,0,1]],[[1,0,0],[1,0,1],[0,0,1]]] gives
      [[[0,1,1],[0,1,1],[0,1,1]],[[0,1,0],[1,0,0],[0,1,0]],[[1,0,1],[1,0,1],[0,0,0]]]










      share|improve this question









      $endgroup$




      Given a binary 3D array, for each layer, cyclically rotate up each of its columns as many steps as indicated by the binary encoding of the columns of the layer above it, and then cyclically rotate left each of its rows as many steps as indicated by the binary encoding of the rows of the layer below it.



      There will always be at least three layers. The top layer's columns and the bottom layer's rows should not be rotated.



      Walk-through



      Lets start with the small 4-layer, 2-row, 3-column array:



      [[[1,0,1],
      [1,0,0]],

      [[1,0,1],
      [0,1,1]],

      [[0,1,1],
      [1,1,1]],

      [[1,1,0],
      [1,1,1]]]


      The first step is evaluating the numbers encoded in binary by the columns and rows of each layer:



           3 0 2
      5 [[[1,0,1],
      4 [1,0,0]],

      2 1 3
      5 [[1,0,1],
      3 [0,1,1]],

      1 3 3
      3 [[0,1,1],
      7 [1,1,1]],

      3 3 1
      6 [[1,1,0],
      7 [1,1,1]]]


      The first layer, [[1,0,1],[1,0,0]] will not have its columns rotated, but its rows will be cyclically rotated left 5 steps and 3 step respectively, thus becoming [[1,1,0],[1,0,0]].

       The second layer, [[1,0,1],[0,1,1]], will have its columns cyclically rotated up 3, 0, and 2 steps respectively, giving [[0,0,1],[1,1,1]], and then the rows are cyclically rotated left 3 and 7 steps respectively, with no visible change.

       The third layer, [[0,1,1],[1,1,1]] rotated up 2, 1, and 3 steps stays the same, and neither does rotating left 6 and 7 steps do anything.

       Finally, the fourth layer, [[1,1,0],[1,1,1]] rotated up 1, 3, and 3 steps is [[1,1,1],[1,1,0]], but its rows are not rotated afterwards, as it is the last layer.

       Putting all the layers together again, gives us the binary self-rotated 3D array:



      [[[1,1,0],
      [1,0,0]],

      [[0,0,1],
      [1,1,1]],

      [[0,1,1],
      [1,1,1]],

      [[1,1,1],
      [1,1,0]]]


      Example cases:



      [[[1,0,1],[1,0,0]],[[1,0,1],[0,1,1]],[[0,1,1],[1,1,1]],[[1,1,0],[1,1,1]]] gives
      [[[1,1,0],[1,0,0]],[[0,0,1],[1,1,1]],[[0,1,1],[1,1,1]],[[1,1,1],[1,1,0]]]



      [[[1]],[[1]],[[0]]] gives
      [[[1]],[[1]],[[0]]]



      [[[1,0,1],[1,0,1],[1,0,1]],[[0,0,1],[0,0,1],[0,0,1]],[[1,0,0],[1,0,1],[0,0,1]]] gives
      [[[0,1,1],[0,1,1],[0,1,1]],[[0,1,0],[1,0,0],[0,1,0]],[[1,0,1],[1,0,1],[0,0,0]]]







      code-golf matrix cellular-automata 3d






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 22 at 9:00









      AdámAdám

      28.9k276204




      28.9k276204






















          6 Answers
          6






          active

          oldest

          votes


















          3












          $begingroup$


          Jelly,  18  17 bytes



          ṙ""Ḅ}
          Z€çŻṖ$$Z€çḊ


          Try it online!



          How?



          ṙ""Ḅ} - Link 1, rotation helper: 3d matrix to rotate, 3d matrix of rotation instructions
          } - use the right argument for:
          Ḅ - un-binary (vectorises) - get the rotation amounts as a 2d matrix
          " - zip with:
          " - zip with:
          ṙ - rotate (the current row) left by (the current amount)

          Z€çŻṖ$ $Z€çḊ - Main Link: 3d matrix, M
          Z€ - transpose €ach (layer of M)
          $ - last two links as a monad:
          $ - last two links as a monad:
          Ż - prepend a zero
          Ṗ - pop (i.e. remove the tail)
          ç - call the last Link as a dyad (i.e. f(Z€ result, ŻṖ$ result) )
          Z€ - transpose €ach (layer of that)
          Ḋ - dequeue (i.e. remove the head layer of M)
          ç - call the last Link as a dyad (i.e. f(Z€çŻṖ$$Z€ result, Ḋ result) )


          Note: $$ (or possibly $$ ... $$?) seems to mess up the code-block formatting (but only once posted, not in the preview), so I added a space to make my life easier.






          share|improve this answer











          $endgroup$





















            3












            $begingroup$


            Python 2, 220 211 209 185 176 174 164 161 159 bytes





            lambda m:map(R,z(map(R,z(m,['']+[z(*l)for l in m])),m[1:]+['']))
            R=lambda(l,L):map(lambda r,i:r[i:]+r[:i or 0],z(*l),[int(`b`[1::3],2)%len(b)for b in L])
            z=zip


            Try it online!



            -2 bytes, thanks to Jonathan Allan






            share|improve this answer











            $endgroup$













            • $begingroup$
              Since you handle None during the slicing for the rotation I believe both of the ['0'] can become [].
              $endgroup$
              – Jonathan Allan
              Jan 22 at 17:29










            • $begingroup$
              @JonathanAllan Thanks :)
              $endgroup$
              – TFeld
              Jan 23 at 8:01



















            2












            $begingroup$

            APL+WIN, 53 39 bytes



            Many thanks to Adám for saving 14 bytes



            (1 0↓⍉2⊥⍉m⍪0)⌽(¯1 0↓2⊥2 1 3⍉0⍪m)⊖[2]m←⎕


            Try it online! Courtesy of Dyalog Classic



            Prompts for input of a 3d array of the form:



            4 2 3⍴1 0 1 1 0 0 1 0 1 0 1 1 0 1 1 1 1 1 1 1 0 1 1 1


            which yields:



            1 0 1
            1 0 0

            1 0 1
            0 1 1

            0 1 1
            1 1 1

            1 1 0
            1 1 1


            Explanation:



            m←⎕ Prompt for input

            (¯1 0↓2⊥2 1 3⍉0⍪m) Calculate column rotations

            (1 0↓⍉2⊥⍉m⍪0) Calculate row rotations

            (...)⌽(...)⊖[2]m Apply column and row rotation and output resulting 3d array:

            1 1 0
            1 0 0

            0 0 1
            1 1 1

            0 1 1
            1 1 1

            1 1 1
            1 1 0





            share|improve this answer











            $endgroup$













            • $begingroup$
              Instead of enclosing and using ¨, just process the entire array at once. Try it online!
              $endgroup$
              – Adám
              Jan 22 at 17:08










            • $begingroup$
              @Adám Many thanks. I do not know why I over thought this one and went the nested route :( Getting old?
              $endgroup$
              – Graham
              Jan 22 at 18:44



















            2












            $begingroup$


            R, 226 216 205 bytes



            -21 bytes thanks to digEmAll





            function(a,L=`for`){d=dim(b<-a)
            r=function(a,n,l=sum(a|1))a[(1:l+sum(n*2^(sum(n|1):1-1))-1)%%l+1]
            L(i,I<-2:d[3],L(j,1:d,b[j,,i]<-r(b[j,,i],a[j,,i-1])))
            L(i,I-1,L(k,1:d[2],b[,k,i]<-r(b[,k,i],a[,k,i+1])))
            b}


            Try it online!






            share|improve this answer











            $endgroup$





















              1












              $begingroup$


              05AB1E, 41 39 bytes



              εNĀiø¹N<èøJC‚øε`._}ø}N¹g<Êi¹N>èJC‚øε`._


              This feels way too long.. Can definitely be golfed some more.



              Try it online or verify all test cases.



              Explanation:





              ε                    # Map each layer in the (implicit) input to:
              # (`N` is the layer-index of this map)
              NĀi # If it is not the first layer:
              ø # Zip/transpose the current layer; swapping rows/columns
              ¹N<è # Get the `N-1`'th layer of the input
              ø # Zip/transpose; swapping rows/columns
              J # Join all inner lists (the columns) together
              C # And convert it from binary to integer
              ‚ # Pair it with the current layer's columns we're mapping
              ø # Zip/transpose; to pair each integer with a layer's columns
              ε } # Map over these pairs:
              ` # Push both values of the pair separately to the stack
              ._ # Rotate the column the integer amount of times
              ø # Zip/transpose the rows/columns of the current layer back
              } # Close the if-statement
              N¹g<Êi # If this is not the last layer (layer-index-1 != amount_of_layers):
              ¹N>è # Get the `N+1`'th layer of the input
              J # Join all inner lists (the rows) together
              C # And convert it from binary to integer
              ‚ # Pair it with the current layer's rows we're mapping
              ø # Zip/transpose; to pair each integer with a layer's rows
              ε # Map over these pairs:
              ` # Push both values of the pair separately to the stack
              ._ # Rotate the row the integer amount of times
              # (implicitly output the result after the layer-mapping is done)





              share|improve this answer











              $endgroup$





















                0












                $begingroup$


                Wolfram Language (Mathematica), 138 131 125 123 bytes



                t=Map@Thread
                m=MapThread[r=RotateLeft,#,2]&
                b=(a=ArrayPad)[Map@Fold[#+##&]/@#,1]~r~#2~a~-1&
                g=m@{t@m@{t@#,t@#~b~-1},#~b~1}&


                Try it online!





                • Map[Thread] is equivalent to Transpose[a, {1,3,2}], which transposes the columns and rows.


                • Fold[#+##&] is shorter than IntegerDigits[#,2] for converting from binary.






                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%2f178984%2fbinary-self-rotation%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  6 Answers
                  6






                  active

                  oldest

                  votes








                  6 Answers
                  6






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  3












                  $begingroup$


                  Jelly,  18  17 bytes



                  ṙ""Ḅ}
                  Z€çŻṖ$$Z€çḊ


                  Try it online!



                  How?



                  ṙ""Ḅ} - Link 1, rotation helper: 3d matrix to rotate, 3d matrix of rotation instructions
                  } - use the right argument for:
                  Ḅ - un-binary (vectorises) - get the rotation amounts as a 2d matrix
                  " - zip with:
                  " - zip with:
                  ṙ - rotate (the current row) left by (the current amount)

                  Z€çŻṖ$ $Z€çḊ - Main Link: 3d matrix, M
                  Z€ - transpose €ach (layer of M)
                  $ - last two links as a monad:
                  $ - last two links as a monad:
                  Ż - prepend a zero
                  Ṗ - pop (i.e. remove the tail)
                  ç - call the last Link as a dyad (i.e. f(Z€ result, ŻṖ$ result) )
                  Z€ - transpose €ach (layer of that)
                  Ḋ - dequeue (i.e. remove the head layer of M)
                  ç - call the last Link as a dyad (i.e. f(Z€çŻṖ$$Z€ result, Ḋ result) )


                  Note: $$ (or possibly $$ ... $$?) seems to mess up the code-block formatting (but only once posted, not in the preview), so I added a space to make my life easier.






                  share|improve this answer











                  $endgroup$


















                    3












                    $begingroup$


                    Jelly,  18  17 bytes



                    ṙ""Ḅ}
                    Z€çŻṖ$$Z€çḊ


                    Try it online!



                    How?



                    ṙ""Ḅ} - Link 1, rotation helper: 3d matrix to rotate, 3d matrix of rotation instructions
                    } - use the right argument for:
                    Ḅ - un-binary (vectorises) - get the rotation amounts as a 2d matrix
                    " - zip with:
                    " - zip with:
                    ṙ - rotate (the current row) left by (the current amount)

                    Z€çŻṖ$ $Z€çḊ - Main Link: 3d matrix, M
                    Z€ - transpose €ach (layer of M)
                    $ - last two links as a monad:
                    $ - last two links as a monad:
                    Ż - prepend a zero
                    Ṗ - pop (i.e. remove the tail)
                    ç - call the last Link as a dyad (i.e. f(Z€ result, ŻṖ$ result) )
                    Z€ - transpose €ach (layer of that)
                    Ḋ - dequeue (i.e. remove the head layer of M)
                    ç - call the last Link as a dyad (i.e. f(Z€çŻṖ$$Z€ result, Ḋ result) )


                    Note: $$ (or possibly $$ ... $$?) seems to mess up the code-block formatting (but only once posted, not in the preview), so I added a space to make my life easier.






                    share|improve this answer











                    $endgroup$
















                      3












                      3








                      3





                      $begingroup$


                      Jelly,  18  17 bytes



                      ṙ""Ḅ}
                      Z€çŻṖ$$Z€çḊ


                      Try it online!



                      How?



                      ṙ""Ḅ} - Link 1, rotation helper: 3d matrix to rotate, 3d matrix of rotation instructions
                      } - use the right argument for:
                      Ḅ - un-binary (vectorises) - get the rotation amounts as a 2d matrix
                      " - zip with:
                      " - zip with:
                      ṙ - rotate (the current row) left by (the current amount)

                      Z€çŻṖ$ $Z€çḊ - Main Link: 3d matrix, M
                      Z€ - transpose €ach (layer of M)
                      $ - last two links as a monad:
                      $ - last two links as a monad:
                      Ż - prepend a zero
                      Ṗ - pop (i.e. remove the tail)
                      ç - call the last Link as a dyad (i.e. f(Z€ result, ŻṖ$ result) )
                      Z€ - transpose €ach (layer of that)
                      Ḋ - dequeue (i.e. remove the head layer of M)
                      ç - call the last Link as a dyad (i.e. f(Z€çŻṖ$$Z€ result, Ḋ result) )


                      Note: $$ (or possibly $$ ... $$?) seems to mess up the code-block formatting (but only once posted, not in the preview), so I added a space to make my life easier.






                      share|improve this answer











                      $endgroup$




                      Jelly,  18  17 bytes



                      ṙ""Ḅ}
                      Z€çŻṖ$$Z€çḊ


                      Try it online!



                      How?



                      ṙ""Ḅ} - Link 1, rotation helper: 3d matrix to rotate, 3d matrix of rotation instructions
                      } - use the right argument for:
                      Ḅ - un-binary (vectorises) - get the rotation amounts as a 2d matrix
                      " - zip with:
                      " - zip with:
                      ṙ - rotate (the current row) left by (the current amount)

                      Z€çŻṖ$ $Z€çḊ - Main Link: 3d matrix, M
                      Z€ - transpose €ach (layer of M)
                      $ - last two links as a monad:
                      $ - last two links as a monad:
                      Ż - prepend a zero
                      Ṗ - pop (i.e. remove the tail)
                      ç - call the last Link as a dyad (i.e. f(Z€ result, ŻṖ$ result) )
                      Z€ - transpose €ach (layer of that)
                      Ḋ - dequeue (i.e. remove the head layer of M)
                      ç - call the last Link as a dyad (i.e. f(Z€çŻṖ$$Z€ result, Ḋ result) )


                      Note: $$ (or possibly $$ ... $$?) seems to mess up the code-block formatting (but only once posted, not in the preview), so I added a space to make my life easier.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Jan 22 at 18:14

























                      answered Jan 22 at 13:27









                      Jonathan AllanJonathan Allan

                      52.7k535170




                      52.7k535170























                          3












                          $begingroup$


                          Python 2, 220 211 209 185 176 174 164 161 159 bytes





                          lambda m:map(R,z(map(R,z(m,['']+[z(*l)for l in m])),m[1:]+['']))
                          R=lambda(l,L):map(lambda r,i:r[i:]+r[:i or 0],z(*l),[int(`b`[1::3],2)%len(b)for b in L])
                          z=zip


                          Try it online!



                          -2 bytes, thanks to Jonathan Allan






                          share|improve this answer











                          $endgroup$













                          • $begingroup$
                            Since you handle None during the slicing for the rotation I believe both of the ['0'] can become [].
                            $endgroup$
                            – Jonathan Allan
                            Jan 22 at 17:29










                          • $begingroup$
                            @JonathanAllan Thanks :)
                            $endgroup$
                            – TFeld
                            Jan 23 at 8:01
















                          3












                          $begingroup$


                          Python 2, 220 211 209 185 176 174 164 161 159 bytes





                          lambda m:map(R,z(map(R,z(m,['']+[z(*l)for l in m])),m[1:]+['']))
                          R=lambda(l,L):map(lambda r,i:r[i:]+r[:i or 0],z(*l),[int(`b`[1::3],2)%len(b)for b in L])
                          z=zip


                          Try it online!



                          -2 bytes, thanks to Jonathan Allan






                          share|improve this answer











                          $endgroup$













                          • $begingroup$
                            Since you handle None during the slicing for the rotation I believe both of the ['0'] can become [].
                            $endgroup$
                            – Jonathan Allan
                            Jan 22 at 17:29










                          • $begingroup$
                            @JonathanAllan Thanks :)
                            $endgroup$
                            – TFeld
                            Jan 23 at 8:01














                          3












                          3








                          3





                          $begingroup$


                          Python 2, 220 211 209 185 176 174 164 161 159 bytes





                          lambda m:map(R,z(map(R,z(m,['']+[z(*l)for l in m])),m[1:]+['']))
                          R=lambda(l,L):map(lambda r,i:r[i:]+r[:i or 0],z(*l),[int(`b`[1::3],2)%len(b)for b in L])
                          z=zip


                          Try it online!



                          -2 bytes, thanks to Jonathan Allan






                          share|improve this answer











                          $endgroup$




                          Python 2, 220 211 209 185 176 174 164 161 159 bytes





                          lambda m:map(R,z(map(R,z(m,['']+[z(*l)for l in m])),m[1:]+['']))
                          R=lambda(l,L):map(lambda r,i:r[i:]+r[:i or 0],z(*l),[int(`b`[1::3],2)%len(b)for b in L])
                          z=zip


                          Try it online!



                          -2 bytes, thanks to Jonathan Allan







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Jan 23 at 8:01

























                          answered Jan 22 at 14:08









                          TFeldTFeld

                          15.7k21248




                          15.7k21248












                          • $begingroup$
                            Since you handle None during the slicing for the rotation I believe both of the ['0'] can become [].
                            $endgroup$
                            – Jonathan Allan
                            Jan 22 at 17:29










                          • $begingroup$
                            @JonathanAllan Thanks :)
                            $endgroup$
                            – TFeld
                            Jan 23 at 8:01


















                          • $begingroup$
                            Since you handle None during the slicing for the rotation I believe both of the ['0'] can become [].
                            $endgroup$
                            – Jonathan Allan
                            Jan 22 at 17:29










                          • $begingroup$
                            @JonathanAllan Thanks :)
                            $endgroup$
                            – TFeld
                            Jan 23 at 8:01
















                          $begingroup$
                          Since you handle None during the slicing for the rotation I believe both of the ['0'] can become [].
                          $endgroup$
                          – Jonathan Allan
                          Jan 22 at 17:29




                          $begingroup$
                          Since you handle None during the slicing for the rotation I believe both of the ['0'] can become [].
                          $endgroup$
                          – Jonathan Allan
                          Jan 22 at 17:29












                          $begingroup$
                          @JonathanAllan Thanks :)
                          $endgroup$
                          – TFeld
                          Jan 23 at 8:01




                          $begingroup$
                          @JonathanAllan Thanks :)
                          $endgroup$
                          – TFeld
                          Jan 23 at 8:01











                          2












                          $begingroup$

                          APL+WIN, 53 39 bytes



                          Many thanks to Adám for saving 14 bytes



                          (1 0↓⍉2⊥⍉m⍪0)⌽(¯1 0↓2⊥2 1 3⍉0⍪m)⊖[2]m←⎕


                          Try it online! Courtesy of Dyalog Classic



                          Prompts for input of a 3d array of the form:



                          4 2 3⍴1 0 1 1 0 0 1 0 1 0 1 1 0 1 1 1 1 1 1 1 0 1 1 1


                          which yields:



                          1 0 1
                          1 0 0

                          1 0 1
                          0 1 1

                          0 1 1
                          1 1 1

                          1 1 0
                          1 1 1


                          Explanation:



                          m←⎕ Prompt for input

                          (¯1 0↓2⊥2 1 3⍉0⍪m) Calculate column rotations

                          (1 0↓⍉2⊥⍉m⍪0) Calculate row rotations

                          (...)⌽(...)⊖[2]m Apply column and row rotation and output resulting 3d array:

                          1 1 0
                          1 0 0

                          0 0 1
                          1 1 1

                          0 1 1
                          1 1 1

                          1 1 1
                          1 1 0





                          share|improve this answer











                          $endgroup$













                          • $begingroup$
                            Instead of enclosing and using ¨, just process the entire array at once. Try it online!
                            $endgroup$
                            – Adám
                            Jan 22 at 17:08










                          • $begingroup$
                            @Adám Many thanks. I do not know why I over thought this one and went the nested route :( Getting old?
                            $endgroup$
                            – Graham
                            Jan 22 at 18:44
















                          2












                          $begingroup$

                          APL+WIN, 53 39 bytes



                          Many thanks to Adám for saving 14 bytes



                          (1 0↓⍉2⊥⍉m⍪0)⌽(¯1 0↓2⊥2 1 3⍉0⍪m)⊖[2]m←⎕


                          Try it online! Courtesy of Dyalog Classic



                          Prompts for input of a 3d array of the form:



                          4 2 3⍴1 0 1 1 0 0 1 0 1 0 1 1 0 1 1 1 1 1 1 1 0 1 1 1


                          which yields:



                          1 0 1
                          1 0 0

                          1 0 1
                          0 1 1

                          0 1 1
                          1 1 1

                          1 1 0
                          1 1 1


                          Explanation:



                          m←⎕ Prompt for input

                          (¯1 0↓2⊥2 1 3⍉0⍪m) Calculate column rotations

                          (1 0↓⍉2⊥⍉m⍪0) Calculate row rotations

                          (...)⌽(...)⊖[2]m Apply column and row rotation and output resulting 3d array:

                          1 1 0
                          1 0 0

                          0 0 1
                          1 1 1

                          0 1 1
                          1 1 1

                          1 1 1
                          1 1 0





                          share|improve this answer











                          $endgroup$













                          • $begingroup$
                            Instead of enclosing and using ¨, just process the entire array at once. Try it online!
                            $endgroup$
                            – Adám
                            Jan 22 at 17:08










                          • $begingroup$
                            @Adám Many thanks. I do not know why I over thought this one and went the nested route :( Getting old?
                            $endgroup$
                            – Graham
                            Jan 22 at 18:44














                          2












                          2








                          2





                          $begingroup$

                          APL+WIN, 53 39 bytes



                          Many thanks to Adám for saving 14 bytes



                          (1 0↓⍉2⊥⍉m⍪0)⌽(¯1 0↓2⊥2 1 3⍉0⍪m)⊖[2]m←⎕


                          Try it online! Courtesy of Dyalog Classic



                          Prompts for input of a 3d array of the form:



                          4 2 3⍴1 0 1 1 0 0 1 0 1 0 1 1 0 1 1 1 1 1 1 1 0 1 1 1


                          which yields:



                          1 0 1
                          1 0 0

                          1 0 1
                          0 1 1

                          0 1 1
                          1 1 1

                          1 1 0
                          1 1 1


                          Explanation:



                          m←⎕ Prompt for input

                          (¯1 0↓2⊥2 1 3⍉0⍪m) Calculate column rotations

                          (1 0↓⍉2⊥⍉m⍪0) Calculate row rotations

                          (...)⌽(...)⊖[2]m Apply column and row rotation and output resulting 3d array:

                          1 1 0
                          1 0 0

                          0 0 1
                          1 1 1

                          0 1 1
                          1 1 1

                          1 1 1
                          1 1 0





                          share|improve this answer











                          $endgroup$



                          APL+WIN, 53 39 bytes



                          Many thanks to Adám for saving 14 bytes



                          (1 0↓⍉2⊥⍉m⍪0)⌽(¯1 0↓2⊥2 1 3⍉0⍪m)⊖[2]m←⎕


                          Try it online! Courtesy of Dyalog Classic



                          Prompts for input of a 3d array of the form:



                          4 2 3⍴1 0 1 1 0 0 1 0 1 0 1 1 0 1 1 1 1 1 1 1 0 1 1 1


                          which yields:



                          1 0 1
                          1 0 0

                          1 0 1
                          0 1 1

                          0 1 1
                          1 1 1

                          1 1 0
                          1 1 1


                          Explanation:



                          m←⎕ Prompt for input

                          (¯1 0↓2⊥2 1 3⍉0⍪m) Calculate column rotations

                          (1 0↓⍉2⊥⍉m⍪0) Calculate row rotations

                          (...)⌽(...)⊖[2]m Apply column and row rotation and output resulting 3d array:

                          1 1 0
                          1 0 0

                          0 0 1
                          1 1 1

                          0 1 1
                          1 1 1

                          1 1 1
                          1 1 0






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Jan 22 at 18:56

























                          answered Jan 22 at 14:49









                          GrahamGraham

                          2,50678




                          2,50678












                          • $begingroup$
                            Instead of enclosing and using ¨, just process the entire array at once. Try it online!
                            $endgroup$
                            – Adám
                            Jan 22 at 17:08










                          • $begingroup$
                            @Adám Many thanks. I do not know why I over thought this one and went the nested route :( Getting old?
                            $endgroup$
                            – Graham
                            Jan 22 at 18:44


















                          • $begingroup$
                            Instead of enclosing and using ¨, just process the entire array at once. Try it online!
                            $endgroup$
                            – Adám
                            Jan 22 at 17:08










                          • $begingroup$
                            @Adám Many thanks. I do not know why I over thought this one and went the nested route :( Getting old?
                            $endgroup$
                            – Graham
                            Jan 22 at 18:44
















                          $begingroup$
                          Instead of enclosing and using ¨, just process the entire array at once. Try it online!
                          $endgroup$
                          – Adám
                          Jan 22 at 17:08




                          $begingroup$
                          Instead of enclosing and using ¨, just process the entire array at once. Try it online!
                          $endgroup$
                          – Adám
                          Jan 22 at 17:08












                          $begingroup$
                          @Adám Many thanks. I do not know why I over thought this one and went the nested route :( Getting old?
                          $endgroup$
                          – Graham
                          Jan 22 at 18:44




                          $begingroup$
                          @Adám Many thanks. I do not know why I over thought this one and went the nested route :( Getting old?
                          $endgroup$
                          – Graham
                          Jan 22 at 18:44











                          2












                          $begingroup$


                          R, 226 216 205 bytes



                          -21 bytes thanks to digEmAll





                          function(a,L=`for`){d=dim(b<-a)
                          r=function(a,n,l=sum(a|1))a[(1:l+sum(n*2^(sum(n|1):1-1))-1)%%l+1]
                          L(i,I<-2:d[3],L(j,1:d,b[j,,i]<-r(b[j,,i],a[j,,i-1])))
                          L(i,I-1,L(k,1:d[2],b[,k,i]<-r(b[,k,i],a[,k,i+1])))
                          b}


                          Try it online!






                          share|improve this answer











                          $endgroup$


















                            2












                            $begingroup$


                            R, 226 216 205 bytes



                            -21 bytes thanks to digEmAll





                            function(a,L=`for`){d=dim(b<-a)
                            r=function(a,n,l=sum(a|1))a[(1:l+sum(n*2^(sum(n|1):1-1))-1)%%l+1]
                            L(i,I<-2:d[3],L(j,1:d,b[j,,i]<-r(b[j,,i],a[j,,i-1])))
                            L(i,I-1,L(k,1:d[2],b[,k,i]<-r(b[,k,i],a[,k,i+1])))
                            b}


                            Try it online!






                            share|improve this answer











                            $endgroup$
















                              2












                              2








                              2





                              $begingroup$


                              R, 226 216 205 bytes



                              -21 bytes thanks to digEmAll





                              function(a,L=`for`){d=dim(b<-a)
                              r=function(a,n,l=sum(a|1))a[(1:l+sum(n*2^(sum(n|1):1-1))-1)%%l+1]
                              L(i,I<-2:d[3],L(j,1:d,b[j,,i]<-r(b[j,,i],a[j,,i-1])))
                              L(i,I-1,L(k,1:d[2],b[,k,i]<-r(b[,k,i],a[,k,i+1])))
                              b}


                              Try it online!






                              share|improve this answer











                              $endgroup$




                              R, 226 216 205 bytes



                              -21 bytes thanks to digEmAll





                              function(a,L=`for`){d=dim(b<-a)
                              r=function(a,n,l=sum(a|1))a[(1:l+sum(n*2^(sum(n|1):1-1))-1)%%l+1]
                              L(i,I<-2:d[3],L(j,1:d,b[j,,i]<-r(b[j,,i],a[j,,i-1])))
                              L(i,I-1,L(k,1:d[2],b[,k,i]<-r(b[,k,i],a[,k,i+1])))
                              b}


                              Try it online!







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Feb 24 at 0:22

























                              answered Feb 23 at 1:11









                              ASCII-onlyASCII-only

                              4,3591338




                              4,3591338























                                  1












                                  $begingroup$


                                  05AB1E, 41 39 bytes



                                  εNĀiø¹N<èøJC‚øε`._}ø}N¹g<Êi¹N>èJC‚øε`._


                                  This feels way too long.. Can definitely be golfed some more.



                                  Try it online or verify all test cases.



                                  Explanation:





                                  ε                    # Map each layer in the (implicit) input to:
                                  # (`N` is the layer-index of this map)
                                  NĀi # If it is not the first layer:
                                  ø # Zip/transpose the current layer; swapping rows/columns
                                  ¹N<è # Get the `N-1`'th layer of the input
                                  ø # Zip/transpose; swapping rows/columns
                                  J # Join all inner lists (the columns) together
                                  C # And convert it from binary to integer
                                  ‚ # Pair it with the current layer's columns we're mapping
                                  ø # Zip/transpose; to pair each integer with a layer's columns
                                  ε } # Map over these pairs:
                                  ` # Push both values of the pair separately to the stack
                                  ._ # Rotate the column the integer amount of times
                                  ø # Zip/transpose the rows/columns of the current layer back
                                  } # Close the if-statement
                                  N¹g<Êi # If this is not the last layer (layer-index-1 != amount_of_layers):
                                  ¹N>è # Get the `N+1`'th layer of the input
                                  J # Join all inner lists (the rows) together
                                  C # And convert it from binary to integer
                                  ‚ # Pair it with the current layer's rows we're mapping
                                  ø # Zip/transpose; to pair each integer with a layer's rows
                                  ε # Map over these pairs:
                                  ` # Push both values of the pair separately to the stack
                                  ._ # Rotate the row the integer amount of times
                                  # (implicitly output the result after the layer-mapping is done)





                                  share|improve this answer











                                  $endgroup$


















                                    1












                                    $begingroup$


                                    05AB1E, 41 39 bytes



                                    εNĀiø¹N<èøJC‚øε`._}ø}N¹g<Êi¹N>èJC‚øε`._


                                    This feels way too long.. Can definitely be golfed some more.



                                    Try it online or verify all test cases.



                                    Explanation:





                                    ε                    # Map each layer in the (implicit) input to:
                                    # (`N` is the layer-index of this map)
                                    NĀi # If it is not the first layer:
                                    ø # Zip/transpose the current layer; swapping rows/columns
                                    ¹N<è # Get the `N-1`'th layer of the input
                                    ø # Zip/transpose; swapping rows/columns
                                    J # Join all inner lists (the columns) together
                                    C # And convert it from binary to integer
                                    ‚ # Pair it with the current layer's columns we're mapping
                                    ø # Zip/transpose; to pair each integer with a layer's columns
                                    ε } # Map over these pairs:
                                    ` # Push both values of the pair separately to the stack
                                    ._ # Rotate the column the integer amount of times
                                    ø # Zip/transpose the rows/columns of the current layer back
                                    } # Close the if-statement
                                    N¹g<Êi # If this is not the last layer (layer-index-1 != amount_of_layers):
                                    ¹N>è # Get the `N+1`'th layer of the input
                                    J # Join all inner lists (the rows) together
                                    C # And convert it from binary to integer
                                    ‚ # Pair it with the current layer's rows we're mapping
                                    ø # Zip/transpose; to pair each integer with a layer's rows
                                    ε # Map over these pairs:
                                    ` # Push both values of the pair separately to the stack
                                    ._ # Rotate the row the integer amount of times
                                    # (implicitly output the result after the layer-mapping is done)





                                    share|improve this answer











                                    $endgroup$
















                                      1












                                      1








                                      1





                                      $begingroup$


                                      05AB1E, 41 39 bytes



                                      εNĀiø¹N<èøJC‚øε`._}ø}N¹g<Êi¹N>èJC‚øε`._


                                      This feels way too long.. Can definitely be golfed some more.



                                      Try it online or verify all test cases.



                                      Explanation:





                                      ε                    # Map each layer in the (implicit) input to:
                                      # (`N` is the layer-index of this map)
                                      NĀi # If it is not the first layer:
                                      ø # Zip/transpose the current layer; swapping rows/columns
                                      ¹N<è # Get the `N-1`'th layer of the input
                                      ø # Zip/transpose; swapping rows/columns
                                      J # Join all inner lists (the columns) together
                                      C # And convert it from binary to integer
                                      ‚ # Pair it with the current layer's columns we're mapping
                                      ø # Zip/transpose; to pair each integer with a layer's columns
                                      ε } # Map over these pairs:
                                      ` # Push both values of the pair separately to the stack
                                      ._ # Rotate the column the integer amount of times
                                      ø # Zip/transpose the rows/columns of the current layer back
                                      } # Close the if-statement
                                      N¹g<Êi # If this is not the last layer (layer-index-1 != amount_of_layers):
                                      ¹N>è # Get the `N+1`'th layer of the input
                                      J # Join all inner lists (the rows) together
                                      C # And convert it from binary to integer
                                      ‚ # Pair it with the current layer's rows we're mapping
                                      ø # Zip/transpose; to pair each integer with a layer's rows
                                      ε # Map over these pairs:
                                      ` # Push both values of the pair separately to the stack
                                      ._ # Rotate the row the integer amount of times
                                      # (implicitly output the result after the layer-mapping is done)





                                      share|improve this answer











                                      $endgroup$




                                      05AB1E, 41 39 bytes



                                      εNĀiø¹N<èøJC‚øε`._}ø}N¹g<Êi¹N>èJC‚øε`._


                                      This feels way too long.. Can definitely be golfed some more.



                                      Try it online or verify all test cases.



                                      Explanation:





                                      ε                    # Map each layer in the (implicit) input to:
                                      # (`N` is the layer-index of this map)
                                      NĀi # If it is not the first layer:
                                      ø # Zip/transpose the current layer; swapping rows/columns
                                      ¹N<è # Get the `N-1`'th layer of the input
                                      ø # Zip/transpose; swapping rows/columns
                                      J # Join all inner lists (the columns) together
                                      C # And convert it from binary to integer
                                      ‚ # Pair it with the current layer's columns we're mapping
                                      ø # Zip/transpose; to pair each integer with a layer's columns
                                      ε } # Map over these pairs:
                                      ` # Push both values of the pair separately to the stack
                                      ._ # Rotate the column the integer amount of times
                                      ø # Zip/transpose the rows/columns of the current layer back
                                      } # Close the if-statement
                                      N¹g<Êi # If this is not the last layer (layer-index-1 != amount_of_layers):
                                      ¹N>è # Get the `N+1`'th layer of the input
                                      J # Join all inner lists (the rows) together
                                      C # And convert it from binary to integer
                                      ‚ # Pair it with the current layer's rows we're mapping
                                      ø # Zip/transpose; to pair each integer with a layer's rows
                                      ε # Map over these pairs:
                                      ` # Push both values of the pair separately to the stack
                                      ._ # Rotate the row the integer amount of times
                                      # (implicitly output the result after the layer-mapping is done)






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Jan 22 at 10:10

























                                      answered Jan 22 at 9:56









                                      Kevin CruijssenKevin Cruijssen

                                      40.1k563206




                                      40.1k563206























                                          0












                                          $begingroup$


                                          Wolfram Language (Mathematica), 138 131 125 123 bytes



                                          t=Map@Thread
                                          m=MapThread[r=RotateLeft,#,2]&
                                          b=(a=ArrayPad)[Map@Fold[#+##&]/@#,1]~r~#2~a~-1&
                                          g=m@{t@m@{t@#,t@#~b~-1},#~b~1}&


                                          Try it online!





                                          • Map[Thread] is equivalent to Transpose[a, {1,3,2}], which transposes the columns and rows.


                                          • Fold[#+##&] is shorter than IntegerDigits[#,2] for converting from binary.






                                          share|improve this answer











                                          $endgroup$


















                                            0












                                            $begingroup$


                                            Wolfram Language (Mathematica), 138 131 125 123 bytes



                                            t=Map@Thread
                                            m=MapThread[r=RotateLeft,#,2]&
                                            b=(a=ArrayPad)[Map@Fold[#+##&]/@#,1]~r~#2~a~-1&
                                            g=m@{t@m@{t@#,t@#~b~-1},#~b~1}&


                                            Try it online!





                                            • Map[Thread] is equivalent to Transpose[a, {1,3,2}], which transposes the columns and rows.


                                            • Fold[#+##&] is shorter than IntegerDigits[#,2] for converting from binary.






                                            share|improve this answer











                                            $endgroup$
















                                              0












                                              0








                                              0





                                              $begingroup$


                                              Wolfram Language (Mathematica), 138 131 125 123 bytes



                                              t=Map@Thread
                                              m=MapThread[r=RotateLeft,#,2]&
                                              b=(a=ArrayPad)[Map@Fold[#+##&]/@#,1]~r~#2~a~-1&
                                              g=m@{t@m@{t@#,t@#~b~-1},#~b~1}&


                                              Try it online!





                                              • Map[Thread] is equivalent to Transpose[a, {1,3,2}], which transposes the columns and rows.


                                              • Fold[#+##&] is shorter than IntegerDigits[#,2] for converting from binary.






                                              share|improve this answer











                                              $endgroup$




                                              Wolfram Language (Mathematica), 138 131 125 123 bytes



                                              t=Map@Thread
                                              m=MapThread[r=RotateLeft,#,2]&
                                              b=(a=ArrayPad)[Map@Fold[#+##&]/@#,1]~r~#2~a~-1&
                                              g=m@{t@m@{t@#,t@#~b~-1},#~b~1}&


                                              Try it online!





                                              • Map[Thread] is equivalent to Transpose[a, {1,3,2}], which transposes the columns and rows.


                                              • Fold[#+##&] is shorter than IntegerDigits[#,2] for converting from binary.







                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited Jan 27 at 17:38

























                                              answered Jan 27 at 1:50









                                              lirtosiastlirtosiast

                                              18.2k438109




                                              18.2k438109






























                                                  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%2f178984%2fbinary-self-rotation%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







                                                  Popular posts from this blog

                                                  android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                                                  SQL update select statement

                                                  'app-layout' is not a known element: how to share Component with different Modules