// See https://aka.ms/new-console-template for more information using System.Drawing; using System.Net.Http.Headers; using System.Runtime.CompilerServices; var exampleChamber = new Chamber(7, "example-input.txt"); var puzzleChamber = new Chamber(7, "puzzle-input.txt"); abstract class Shape { } // Chamber bottom right is 0,0. Y points up. 0,0 is a "block" class Chamber { public enum WindDirection { Left, Right, None } public HashSet FilledSpaces { get; set; } public int ChamberWidth { get; private set; } public WindDirection[] WindDirections { get; private set; } public Chamber(int chamberWidth, string windfile) { FilledSpaces = new HashSet(); ChamberWidth = chamberWidth; using (StreamReader reader = System.IO.File.OpenText(windfile)) { while (!reader.EndOfStream) { var line = reader.ReadLine(); if (line == null) throw new InvalidDataException(); WindDirections = new WindDirection[line.Length]; for (int i = 0; i < WindDirections.Length; i++) { if (line[i] == '<') WindDirections[i] = WindDirection.Left; else if (line[i] == '>') WindDirections[i] = WindDirection.Right; else throw new InvalidDataException(); } } } if (WindDirections == null) throw new InvalidDataException(); } public Rectangle Bounds { get { Point min = new Point(1,1), max = new Point(1,1); foreach (var item in FilledSpaces) { min.X = int.Min(min.X, item.X); min.Y = int.Min(min.Y, item.Y); max.X = int.Max(max.X, item.X); max.Y = int.Max(max.Y, item.Y); } return new Rectangle(0, 0, max.X - min.X, max.Y - min.Y); } } public void Draw() { var bounds = Bounds; int maxY = bounds.Height; for (int j = maxY; j > 0; j--) { Console.Write("|"); for (int i = 1; i <= ChamberWidth; i++) { if (FilledSpaces.Contains(new Point(i,j))) { Console.Write('#'); } else { Console.Write('.'); } } Console.WriteLine("|"); } Console.Write("+"); for (int i = 1; i <= ChamberWidth; i++) { Console.Write("-"); } Console.WriteLine("+"); } }