title: Can shift, rotate, and flip operations on a 2D matrix be combined into a single operation?
body: <p>Say I have a n by n matrix that has each cell as either a 0 or a 1. There is a list of commands that feed into a program. These commands specify an operation (shift, rotate, flip) and a value x, to specify the magnitude of the operation. The operation will only move cells with a 1 in it. A "UP 3" operation would cause all cells with "1" to shift up by 3.</p>
  
  <p>In the case where there are multiple operations that must be sequentially applied to the matrix, for optimization, what I can do is combine contiguous operations of the same type. As in (up, down, left, right) would all be the same type (shift). CW and CCW rotations would be the same type. And Flip in the x or y directions would be the same type. I can combine multiple operations of the same type if they happen one after another. (i.e. UP 3, DOWN 2 -> results in a net UP 1). I want to know if there is a way to do a single "net" operation by combining operations of <strong>different</strong> types.</p>
  
  <p>So I want to know, in my operations list, if I have for example, 1 UP, 1 CW, 3 RIGHT, 1 Y FLIP, 2 DOWN.</p>
  
  <p>Instead of doing the above 6 instructions in 6 "moves", is there a mathematical/programming way to combine those into <strong>a single</strong> instruction for a square n by n matrix?</p>
  
  <p>Must be do-able in C.</p>