Advertisement
Guest User

day8

a guest
Dec 8th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.10 KB | None | 0 0
  1.         private static bool[,] grid;
  2.  
  3.         private static bool[] tmpRow;
  4.         private static bool[] tmpColumn;
  5.  
  6.         static void Main(string[] args)
  7.         {
  8.             grid = new bool[50,6];
  9.             tmpRow = new bool[50];
  10.             tmpColumn = new bool[6];
  11.             string[] lines = File.ReadAllLines("C:/input.txt");
  12.  
  13.             for(int i = 0; i < lines.Length; i++)
  14.             {
  15.                 string[] commands = lines[i].Split(' ');
  16.                 if (commands[0] == "rect")
  17.                 {
  18.                     string[] wh = commands[1].Split('x');
  19.                     int w = int.Parse(wh[0]);
  20.                     int h = int.Parse(wh[1]);
  21.                     Rect(w, h);
  22.                 }
  23.                 else
  24.                 {
  25.                     if(commands[1] == "row")
  26.                     {
  27.                         int rowId = int.Parse(commands[2].Split('=')[1]);
  28.                         int rcount = int.Parse(commands[4]);
  29.                         RotateRow(rowId, rcount);
  30.                     }
  31.                     else
  32.                     {
  33.                         int columnId = int.Parse(commands[2].Split('=')[1]);
  34.                         int ccount = int.Parse(commands[4]);
  35.                         RotateColumn(columnId, ccount);
  36.                     }
  37.                 }
  38.             }
  39.  
  40.             int result = 0;
  41.             for(int x = 0; x < 50; x++)
  42.             {
  43.                 for(int y = 0; y < 6; y++)
  44.                 {
  45.                     if(grid[x,y])
  46.                     {
  47.                         result++;
  48.                     }
  49.                 }
  50.             }
  51.  
  52.             Console.WriteLine("Done");
  53.             Console.WriteLine(result);
  54.             Console.ReadKey();
  55.         }
  56.  
  57.         public static void Rect(int width, int height)
  58.         {
  59.             for(int x = 0; x < width; x++)
  60.             {
  61.                 for(int y = 0; y < height; y ++)
  62.                 {
  63.                     grid[x, y] = true;
  64.                 }
  65.             }
  66.         }
  67.  
  68.         public static void RotateRow(int rowId, int count)
  69.         {
  70.             if(count == 50)
  71.             {
  72.                 return;
  73.             }
  74.             count = count % 50;
  75.             int offset = 50 - count;
  76.             for(int i = 0; i <50; i++)
  77.             {
  78.                 tmpRow[i] = grid[offset, rowId];
  79.                 offset++;
  80.                 offset = offset % 50;
  81.             }
  82.             for(int i = 0; i < 50; i++)
  83.             {
  84.                 grid[i, rowId] = tmpRow[i];
  85.             }
  86.         }
  87.  
  88.         public static void RotateColumn(int columnId, int count)
  89.         {
  90.             if (count == 6)
  91.             {
  92.                 return;
  93.             }
  94.             count = count % 6;
  95.             int offset = 6 - count;
  96.             for (int i = 0; i < 6; i++)
  97.             {
  98.                 tmpColumn[i] = grid[columnId, offset];
  99.                 offset++;
  100.                 offset = offset % 6;
  101.             }
  102.             for (int i = 0; i < 6; i++)
  103.             {
  104.                 grid[columnId, i] = tmpColumn[i];
  105.             }
  106.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement