namespace TransformationalTheory.Assignment1 {
    class Program {
        // Music is in modulo 12
        public const int ModUniverse = 12;
        // Two twelve-tone operators: T and I
        public const int NumTTOperators = 2;
        // Set dimensions of the matrix based on the above values
        public const int Rows = ModUniverse * NumTTOperators;
        public const int Columns = Rows;
        public const int Halfway = Rows / 2;
        public enum Operator {
            T, I
        }
        static void Main(string[] args) {
            // Create and set the matrix
            string[,] matrix = new string[Rows, Columns];
            for (int m = 0; m < Rows; m++) {
                for (int n = 0; n < Columns; n++) {
                    if (m < Halfway) {
                        if (n < Halfway) {
                            matrix[m, n] = TmTn(m, n);
                        } else {
                            matrix[m, n] = TmIn(m, n);
                        }
                    } else {
                        if (n < Halfway) {
                            matrix[m, n] = ImTn(m, n);
                        } else {
                            matrix[m, n] = ImIn(m, n);
                        }
                    }
                }
            }
            // Write to a file
            using (System.IO.StreamWriter file =
                    new System.IO.StreamWriter(@"C:\Users\Nick\Desktop\Assignment1.html")) {
                file.WriteLine("<table>");
                for (int m = 0; m < Rows; m++) {
                    file.Write("<tr>");
                    for (int n = 0; n < Columns; n++) {
                        file.Write("<td>" + matrix[m, n] + "</td>");
                    }
                    file.WriteLine("</tr>");
                }
                file.Write("</table>");
            }
        }
        public static string TmTn(int m, int n) {
            return Compose(Operator.T, AddMod(m, n));
        }
        public static string ImTn(int m, int n) {
            return Compose(Operator.I, AddMod(m, n));
        }
        public static string TmIn(int m, int n) {
            return Compose(Operator.I, SubtractMod(n, m));
        }
        public static string ImIn(int m, int n) {
            return Compose(Operator.T, SubtractMod(n, m));
        }
        public static string Compose(Operator a, int b) {
            return string.Format("{0}<sub>{1}</sub>", a, b);
        }
        public static int AddMod(int m, int n) {
            return (m + n) % ModUniverse;
        }
        public static int SubtractMod(int n, int m) {
            return ((n - m) + ModUniverse) % ModUniverse;
        }
    }
}