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

View File

@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AdventCommon
{
public abstract class ParsedInput
{
public virtual object? GetContext() { return null; }
public abstract bool ParseLine(string line, object? context = null);
public virtual long GetPart01() { return 0; }
public virtual long GetPart02() { return 0; }
public ParsedInput(string fileName)
{
var input = new AdventCommon.PuzzleInput(fileName);
foreach (var line in input.Lines)
{
if (!ParseLine(line, GetContext()))
{
throw new Exception("Line not formatted as expected");
}
}
}
}
}

View File

@@ -0,0 +1,35 @@
namespace AdventCommon
{
public class PuzzleInput
{
public PuzzleInput(string fileName, bool ignoreEmptyLines = true)
{
using (StreamReader reader = System.IO.File.OpenText(fileName))
{
while (!reader.EndOfStream)
{
string? line = reader.ReadLine();
if (line == null) { throw new InvalidDataException(); }
if (ignoreEmptyLines && String.IsNullOrWhiteSpace(line)) continue;
Lines.Add(line);
}
}
}
public List<string> Lines { get; private set; } = new List<string>();
public void Print()
{
for (int j = 0; j < Lines.Count; j++)
{
for (int i = 0; i < Lines[j].Length; i++)
{
Console.Write(Lines[j][i]);
}
Console.WriteLine();
}
}
}
}