using System; namespace _2021___Day_02 { class Program { static void Main(string[] args) { int counter = 0; string line; string[] fileBuffer = new string[1000]; // Read the file and display it line by line. System.IO.StreamReader file = new System.IO.StreamReader(@"../../../../Input.in"); while ((line = file.ReadLine()) != null) { fileBuffer[counter] = line; counter++; } file.Close(); int fwdPos = 0; int depth = 0; for (int i = 0; i < fileBuffer.Length; i++) { string[] substrings = fileBuffer[i].Split(" "); switch (substrings[0]) { case "forward": fwdPos += int.Parse(substrings[1]); break; case "down": depth += int.Parse(substrings[1]); break; case "up": depth -= int.Parse(substrings[1]); break; default: break; } } Console.WriteLine("Depth: " + depth.ToString()); Console.WriteLine("Forward: " + fwdPos.ToString()); Console.WriteLine("Product of both: " + (fwdPos * depth).ToString()); fwdPos = 0; depth = 0; int aim = 0; for (int i = 0; i < fileBuffer.Length; i++) { string[] substrings = fileBuffer[i].Split(" "); switch (substrings[0]) { case "forward": fwdPos += int.Parse(substrings[1]); depth += (int.Parse(substrings[1]) * aim); break; case "down": aim += int.Parse(substrings[1]); break; case "up": aim -= int.Parse(substrings[1]); break; default: break; } } Console.WriteLine("Depth: " + depth.ToString()); Console.WriteLine("Forward: " + fwdPos.ToString()); Console.WriteLine("Product of both: " + (fwdPos * depth).ToString()); } } }