Add day 7

This commit is contained in:
2022-12-08 15:51:52 +01:00
parent 489ecc6d8d
commit 5d6835b2e6
3 changed files with 1281 additions and 2 deletions

1244
Days/Day7.cs Normal file

File diff suppressed because it is too large Load Diff

20
EnumerableExtensions.cs Normal file
View File

@@ -0,0 +1,20 @@
namespace AdventOfCode;
public static class EnumerableExtensions
{
public static IEnumerable<TSource> Flatten<TSource>(this TSource root, Func<TSource, IEnumerable<TSource>> flattener)
{
var toVisit = new Stack<TSource>();
toVisit.Push(root);
while (toVisit.TryPop(out var node))
{
yield return node;
foreach (var child in flattener(node))
{
toVisit.Push(child);
}
}
}
}

View File

@@ -16,7 +16,22 @@ var selectedDay = AnsiConsole.Prompt(select);
AnsiConsole.MarkupLine($"[cyan]Running [yellow]{selectedDay}[/]...[/]\n");
AnsiConsole.MarkupLine("[cyan]Part [yellow]1[/] result:[/]");
selectedDay.RunPart1();
try
{
selectedDay.RunPart1();
}
catch (Exception e)
{
AnsiConsole.WriteException(e);
}
AnsiConsole.MarkupLine("\n[cyan]Part [yellow]2[/] result:[/]");
selectedDay.RunPart2();
try
{
selectedDay.RunPart2();
}
catch (Exception e)
{
AnsiConsole.WriteException(e);
}