package coding4fun;

import java.util.Arrays;

/**
 * Write an algorithm to perform a Tetris rotation.
 */
public class Problem24 {
    public static void rotate(char[][] block) {
        char[][] aux = new char[block.length][];
        for (int row = 0; row < block.length; row++) {
            aux[row] = new char[block[row].length];
            for (int col = 0; col < block[row].length; col++) {
                aux[row][col] = block[row][col];
            }
        }

        for (int row = 0; row < block.length; row++) {
            for (int col = 0; col < block[row].length; col++) {
                // TODO
            }
        }
    }

    private static void print(char[][] block) {
        for (char[] chars : block) {
            System.out.println(Arrays.toString(chars));
        }
        System.out.println("-----------------------------------------------------------");
    }

    public static void main(String[] args) {
        char[][] block = new char[][]{
            {' ', ' ', ' '},
            {'*', '*', '*'},
            {' ', '*', ' '},
        };
        print(block);

        rotate(block);
        print(block);

        rotate(block);
        print(block);

        rotate(block);
        print(block);
    }
}

@@ -143,20 +143,24 @@
  static 
-void
+char%5B%5D%5B%5D
  rotate(
@@ -189,32 +189,22 @@
     
-char%5B%5D%5B%5D aux = new char%5B
+int rowSize = 
 bloc
@@ -211,19 +211,16 @@
 k.length
-%5D%5B%5D
 ;%0A      
@@ -225,45 +225,38 @@
     
-for (int row = 0; row %3C
+int colSize =
  block
+%5B0%5D
 .length;
  row
@@ -255,69 +255,138 @@
 gth;
- row++) %7B%0A            aux%5Brow%5D = new char%5Bblock%5Brow%5D.length%5D;
+%0A%0A        // tranpose the matrix%0A        char%5B%5D%5B%5D result = new char%5BcolSize%5D%5BrowSize%5D;%0A        for (int i = 0; i %3C rowSize; i++) %7B
 %0A   
@@ -407,45 +407,29 @@
 int 
-col
+j
  = 0; 
-col %3C block%5Brow%5D.length; col
+j %3C colSize; j
 ++) 
@@ -450,20 +450,19 @@
     
-aux%5Brow%5D%5Bcol
+result%5Bj%5D%5Bi
 %5D = 
@@ -471,16 +471,12 @@
 ock%5B
-row%5D%5Bcol
+i%5D%5Bj
 %5D;%0A 
@@ -494,24 +494,51 @@
 %7D%0A        %7D%0A
+        // reverse the rows
 %0A        for
@@ -547,28 +547,25 @@
 int 
-row
+i
  = 0; 
-row %3C block
+i %3C result
 .len
@@ -569,19 +569,17 @@
 length; 
-row
+i
 ++) %7B%0A  
@@ -601,98 +601,248 @@
 int 
-col
+j
  = 0
-; col %3C block%5Brow%5D.length; col++) %7B%0A                // TODO%0A            %7D%0A        %7D
+, k = result%5Bi%5D.length - 1; j %3C result%5Bi%5D.length / 2; j++, k--) %7B%0A                char tmp = result%5Bi%5D%5Bk%5D;%0A                result%5Bi%5D%5Bk%5D = result%5Bi%5D%5Bj%5D;%0A                result%5Bi%5D%5Bj%5D = tmp;%0A            %7D%0A        %7D%0A%0A        return result;
 %0A   
@@ -1259,14 +1259,14 @@
 ', '
-*
+ 
 ', '
- 
+*
 '%7D,%0A
@@ -1298,32 +1298,40 @@
 block);%0A%0A       
+ block =
  rotate(block);%0A
@@ -1352,32 +1352,40 @@
 block);%0A%0A       
+ block =
  rotate(block);%0A
@@ -1414,16 +1414,24 @@
 %0A       
+ block =
  rotate(

Solve problem 24