public static class Program
public static void Main()
Console.WriteLine("ThreeByThree_Rotate90");
tests.ThreeByThree_Rotate90();
Console.WriteLine("\r\n\r\nThreeByThree_Rotate180");
tests.ThreeByThree_Rotate180();
Console.WriteLine("\r\n\r\nChallange");
public static class ArrayRotation
public static int[,] Rotate(int degrees, int[,] input)
var iterations = degrees / 90;
var xWidth = input.GetLength(0);
var yWidth = input.GetLength(1);
var output = new int[yWidth, xWidth];
output = new int[yWidth, xWidth];
var currentXToPopulate = 0;
for (var xIndex = xWidth - 1; xIndex >= 0; xIndex--)
for (var yIndex = 0; yIndex < yWidth; yIndex++)
output[yIndex, currentXToPopulate] = input[xIndex, yIndex];
public void ThreeByThree_Rotate90()
var output = ArrayRotation.Rotate(90, _input);
Assert.That(output, Is.EqualTo(new[,]
public void ThreeByThree_Rotate180()
var output = ArrayRotation.Rotate(180, _input);
Assert.That(output, Is.EqualTo(new[,]
public void Challange(int degrees)
Console.WriteLine("\r\nRotating by " + degrees + " degrees");
{1, 2, 3, 4, 5, 6, 7, 8, 9, 0},
{0, 9, 8, 7, 6, 5, 4, 3, 2, 1},
{1, 3, 5, 7, 9, 2, 4, 6, 8, 0},
{0, 8, 6, 4, 2, 9, 7, 5, 3, 1},
{0, 1, 2, 3, 4, 5, 4, 3, 2, 1},
{9, 8, 7, 6, 5, 6, 7, 8, 9, 0},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
{9, 8, 7, 6, 7, 8, 9, 8, 7, 6},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
var output = ArrayRotation.Rotate(degrees, input);
public static void PrettyPrint(int[,] array)
for (int x = 0; x < array.GetLength(0); x += 1)
for (int y = 0; y < array.GetLength(1); y += 1)
Console.Write(array[x, y] + ", ");