Enable running all days at once

I'm kinda bored and wanted to.
This commit is contained in:
2021-12-12 15:28:41 -06:00
parent 5c37fc4129
commit 9e7942a35e
15 changed files with 845 additions and 848 deletions

View File

@ -0,0 +1,11 @@
{
"profiles": {
"All": {
"commandName": "Project",
"commandLineArgs": "all"
},
"Default day": {
"commandName": "Project"
}
}
}

View File

@ -1,8 +1,8 @@
namespace aoc2021
namespace aoc2021;
internal class Day01 : Day
{
internal class Day01
{
internal static void Go()
internal override void Go()
{
Logger.Log("Day 1");
Logger.Log("-----");
@ -66,5 +66,4 @@
Logger.Log($"part2: {numIncreased}");
}
}
}

View File

@ -1,8 +1,8 @@
namespace aoc2021
namespace aoc2021;
internal class Day02 : Day
{
internal class Day02
{
internal static void Go()
internal override void Go()
{
Logger.Log("Day 2");
Logger.Log("-----");
@ -86,5 +86,4 @@ namespace aoc2021
Logger.Log($"part2: h: {pos.h}, d: {pos.d}, result: {pos.h * pos.d}");
}
}
}

View File

@ -1,8 +1,8 @@
namespace aoc2021
namespace aoc2021;
internal class Day03 : Day
{
internal class Day03
{
internal static void Go()
internal override void Go()
{
Logger.Log("Day 3");
Logger.Log("-----");
@ -128,5 +128,4 @@
Logger.Log($"part2: o2*co2 = {o2} * {co2} = {o2 * co2}");
}
}
}

View File

@ -1,10 +1,10 @@
using System.Diagnostics;
using System.Text.RegularExpressions;
namespace aoc2021
namespace aoc2021;
internal class Day05 : Day
{
internal class Day05
{
private static readonly Regex lineRegex = new(@"(?<x1>\d+),(?<y1>\d+) -> (?<x2>\d+),(?<y2>\d+)", RegexOptions.Compiled);
[DebuggerDisplay("{x},{y}")]
@ -41,7 +41,7 @@ namespace aoc2021
}
}
internal static void Go()
internal override void Go()
{
Logger.Log("Day 5");
Logger.Log("-----");
@ -126,5 +126,4 @@ namespace aoc2021
return numPointsGreater;
}
}
}

View File

@ -1,16 +1,16 @@
using System.Diagnostics;
namespace aoc2021
namespace aoc2021;
internal class Day06 : Day
{
internal class Day06
{
[DebuggerDisplay("{State}")]
struct Fish
{
public int State;
}
internal static void Go()
internal override void Go()
{
Logger.Log("Day 6");
Logger.Log("-----");
@ -77,5 +77,4 @@ namespace aoc2021
Logger.Log($"part2: #fish={fishAtState.Values.Sum()}");
}
}
}

View File

@ -1,8 +1,8 @@
namespace aoc2021
namespace aoc2021;
internal class Day07 : Day
{
internal class Day07
{
internal static void Go()
internal override void Go()
{
Logger.Log("Day 7");
Logger.Log("-----");
@ -51,9 +51,8 @@
// summation formula from https://en.wikipedia.org/wiki/Summation
// found by searching "factorial but with addition" because i'm smart like that.
var (minDist, minNum) = Solve(nums, (d) => ((d*d)+d)/2);
var (minDist, minNum) = Solve(nums, (d) => ((d * d) + d) / 2);
Logger.Log($"part2: position: {minNum}, fuel cost: {minDist}");
}
}
}

View File

@ -1,8 +1,8 @@
namespace aoc2021
namespace aoc2021;
internal class Day08 : Day
{
internal class Day08
{
internal static void Go()
internal override void Go()
{
Logger.Log("Day 8");
Logger.Log("-----");
@ -170,5 +170,4 @@
throw new Exception();
}
}
}

View File

@ -1,8 +1,8 @@
namespace aoc2021
namespace aoc2021;
internal class Day09 : Day
{
internal class Day09
{
internal static void Go()
internal override void Go()
{
Logger.Log("Day 9");
Logger.Log("-----");
@ -73,7 +73,7 @@
var basinPoints = GetBasinSize(grid, point.Item1, point.Item2);
basins.Add(basinPoints.Distinct().Count() + 1);
}
var top3Mult = basins.OrderByDescending(x => x).Take(3).Aggregate(1, (x,y) => x * y);
var top3Mult = basins.OrderByDescending(x => x).Take(3).Aggregate(1, (x, y) => x * y);
Logger.Log($"part2: {top3Mult}");
}
@ -124,5 +124,4 @@
return grid[i, j] > val;
}
}
}

View File

@ -1,8 +1,8 @@
namespace aoc2021
namespace aoc2021;
internal class Day10 : Day
{
internal class Day10
{
internal static void Go()
internal override void Go()
{
Logger.Log("Day 10");
Logger.Log("-----");
@ -138,5 +138,4 @@
Logger.Log($"part2: {final}");
}
}
}

View File

@ -1,8 +1,8 @@
namespace aoc2021;
internal class Day11
internal class Day11 : Day
{
internal static void Go()
internal override void Go()
{
Logger.Log("Day 11");
Logger.Log("-----");

View File

@ -1,8 +1,8 @@
namespace aoc2021;
internal class Day12
internal class Day12 : Day
{
internal static void Go()
internal override void Go()
{
Logger.Log("Day 12");
Logger.Log("-----");

6
src/Day.cs Normal file
View File

@ -0,0 +1,6 @@
namespace aoc2021;
internal abstract class Day
{
internal abstract void Go();
}

View File

@ -1,8 +1,8 @@
namespace aoc2021;
internal class DayTemplate
internal class DayTemplate : Day
{
internal static void Go()
internal override void Go()
{
Logger.Log("Day #");
Logger.Log("-----");

View File

@ -1,47 +1,36 @@
using aoc2021;
var arg = args.FirstOrDefault();
switch (arg)
if (arg == "all")
{
case "1":
aoc2021.Day01.Go();
break;
var types = System.Reflection.Assembly
.GetExecutingAssembly()
.GetTypes()
.Where(t => t.IsSubclassOf(typeof(Day)) && !t.IsAbstract && t.Name != "DayTemplate")
.OrderBy(t => t.Name);
case "2":
aoc2021.Day02.Go();
break;
case "3":
aoc2021.Day03.Go();
break;
case "5":
aoc2021.Day05.Go();
break;
case "6":
aoc2021.Day06.Go();
break;
case "7":
aoc2021.Day07.Go();
break;
case "8":
aoc2021.Day08.Go();
break;
case "9":
aoc2021.Day09.Go();
break;
case "10":
aoc2021.Day10.Go();
break;
case "11":
aoc2021.Day11.Go();
break;
default:
aoc2021.Day12.Go();
break;
foreach (var type in types)
{
var day = (Day)Activator.CreateInstance(type)!;
day.Go();
}
}
else
{
Day day = arg switch
{
"1" => new Day01(),
"2" => new Day02(),
"3" => new Day03(),
//"4" => new Day04(),
"5" => new Day05(),
"6" => new Day06(),
"7" => new Day07(),
"8" => new Day08(),
"9" => new Day09(),
"10" => new Day10(),
"11" => new Day11(),
_ => new Day12(),
};
day.Go();
}