private static readonly char[] base16Values = new char[16]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
private static int[] _matrix = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25};
private const int rows = 5;
private const int columns = 5;
public static void Main()
char[] maxCharIntBase2 = new char[33];
string result = traversal(_matrix, rows, columns);
Console.WriteLine(result);
string itoa(int value, int numericBase)
if (numericBase < 2 || numericBase > 16)
Console.WriteLine("Attempted to convert an int to a string with a numeric base less than 2 or greater than 16");
maxCharIntBase2[--i] = base16Values[-(value % numericBase)];
value = -(value / numericBase);
maxCharIntBase2[--i] = base16Values[value % numericBase];
maxCharIntBase2[--i] = '-';
return new string (maxCharIntBase2, i, 33 - i);
string traversal(int[] matrix, int rows, int columns)
if (matrix == null || matrix.Length <= 0 || rows == 0 || columns == 0 || matrix.Length < rows * columns)
Console.WriteLine("Attempted to do the traversal of an empty matrix or with a rows or columns equal or less than 0 or asking for more values than matrix length");
string[] output = new string[rows * columns];
output[0] = itoa(matrix[0], 10);
Vector2 direction = columns > 1 ? Vector2.Right : Vector2.Down;
for (int i = 1; i < output.Length; i++)
if (direction == Vector2.Right)
if (++x >= columns - 1 - r)
direction = Vector2.Down;
else if (direction == Vector2.Down)
direction = Vector2.Left;
else if (direction == Vector2.Left)
else if (direction == Vector2.Up)
direction = Vector2.Right;
output[i] = itoa(matrix[x + (y * columns)], 10);
return string.Join(", ", output);
public Vector2(float x, float y)
public Vector2(float x, float y, float z)
private readonly static Vector2 left = new Vector2(-1, 0);
private readonly static Vector2 down = new Vector2(0, -1);
private readonly static Vector2 up = new Vector2(0, 1);
private readonly static Vector2 one = new Vector2(1, 1);
private readonly static Vector2 zero = new Vector2(0, 0);
private readonly static Vector2 right = new Vector2(1, 0);
public static Vector2 Left
public static Vector2 Down
public static Vector2 One
public static Vector2 Zero
public static Vector2 Right
public void Set(float x, float y, float z)
public override int GetHashCode()
return x.GetHashCode() + y.GetHashCode();
public override string ToString()
string temp = "(" + (x.ToString() + ", " + y.ToString()) + ")";
public static Vector2 operator +(Vector2 v1, Vector2 v2)
return new Vector2(v1.x + v2.x, v1.y + v2.y);
public static Vector2 operator -(Vector2 v1, Vector2 v2)
return new Vector2(v1.x - v2.x, v1.y - v2.y);
public static Vector2 operator *(Vector2 v1, Vector2 v2)
return new Vector2(v1.x * v2.x, v1.y * v2.y);
public static Vector2 operator *(float d, Vector2 v1)
return new Vector2(v1.x * d, v1.y * d);
public static Vector2 operator *(Vector2 v1, float d)
return new Vector2(v1.x * d, v1.y * d);
public static Vector2 operator /(Vector2 v1, Vector2 v2)
return new Vector2(v1.x / v2.x, v1.y / v2.y);
public static Vector2 operator /(Vector2 v1, float d)
return new Vector2(v1.x / d, v1.y / d);
public static bool operator ==(Vector2 a, Vector2 b)
public static bool operator !=(Vector2 a, Vector2 b)
public override bool Equals(object other)
if (other == null || !(other is Vector2))
Vector2 vector = (Vector2)other;
ret = (x == vector.x && y == vector.y);