Initial Commit

This commit is contained in:
Jose Caban
2025-11-30 20:28:10 -05:00
commit e9ac699e67
209 changed files with 39737 additions and 0 deletions

107
2022/Day17CSharp/Program.cs Normal file
View File

@@ -0,0 +1,107 @@
// 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<Point> FilledSpaces { get; set; }
public int ChamberWidth { get; private set; }
public WindDirection[] WindDirections { get; private set; }
public Chamber(int chamberWidth, string windfile)
{
FilledSpaces = new HashSet<Point>();
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("+");
}
}