ben
/
aoc
1
0
Fork 0

add Year to Day class

This commit is contained in:
Ben Harris 2022-10-27 12:36:21 -04:00
parent f54e134416
commit 789247aedf
90 changed files with 234 additions and 226 deletions

View File

@ -2,16 +2,16 @@
public abstract class Day public abstract class Day
{ {
protected Day(int dayNumber, string puzzleName) protected Day(int year, int day, string puzzleName)
{ {
DayNumber = dayNumber; Year = year;
DayNumber = day;
PuzzleName = puzzleName; PuzzleName = puzzleName;
} }
public static bool UseTestInput { get; set; } public static bool UseTestInput { get; set; }
public static int Year { get; set; } public int Year { get; }
public int DayNumber { get; } public int DayNumber { get; }
public string PuzzleName { get; } public string PuzzleName { get; }

View File

@ -25,6 +25,7 @@
<ProjectReference Include="..\AOC2019\AOC2019.csproj" /> <ProjectReference Include="..\AOC2019\AOC2019.csproj" />
<ProjectReference Include="..\AOC2020\AOC2020.csproj" /> <ProjectReference Include="..\AOC2020\AOC2020.csproj" />
<ProjectReference Include="..\AOC2021\AOC2021.csproj" /> <ProjectReference Include="..\AOC2021\AOC2021.csproj" />
<ProjectReference Include="..\AOC2022\AOC2022.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

33
AOC.Test/Common.cs Normal file
View File

@ -0,0 +1,33 @@
namespace AOC.Test;
public static class Common
{
public static void CheckDay(Type dayType, string part1, string part2)
{
var s = Stopwatch.StartNew();
var day = Activator.CreateInstance(dayType) as Day;
s.Stop();
Assert.IsNotNull(day, "failed to instantiate day object");
Assert.IsTrue(File.Exists(day.FileName), $"File.Exists(day.FileName) {day.FileName}");
Console.Write($"{day.Year} Day {day.DayNumber,2}: {day.PuzzleName,-25} ");
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed in constructor");
// part 1
s.Reset();
s.Start();
var part1Actual = day.Part1().ToString();
s.Stop();
Console.Write($"Part 1: {part1Actual,-25} ");
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed");
Assert.AreEqual(part1, part1Actual, $"Incorrect answer for Day {day.DayNumber} Part1");
// part 2
s.Reset();
s.Start();
var part2Actual = day.Part2().ToString();
s.Stop();
Console.Write($"Part 2: {part2Actual,-25} ");
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed");
Assert.AreEqual(part2, part2Actual, $"Incorrect answer for Day {day.DayNumber} Part2");
}
}

View File

@ -35,32 +35,6 @@ public class Test2019
//[DataRow(typeof(Day25), "", "")] //[DataRow(typeof(Day25), "", "")]
public void TestAllDays(Type dayType, string part1, string part2) public void TestAllDays(Type dayType, string part1, string part2)
{ {
Day.Year = 2019; Common.CheckDay(dayType, part1, part2);
var s = Stopwatch.StartNew();
var day = Activator.CreateInstance(dayType) as Day;
s.Stop();
Assert.IsNotNull(day, "failed to instantiate day object");
Assert.IsTrue(File.Exists(day!.FileName));
Console.Write($"Day {day.DayNumber,2}: {day.PuzzleName,-15} ");
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed in constructor");
// part 1
s.Reset();
s.Start();
var part1Actual = day.Part1();
s.Stop();
Console.Write($"Part 1: {part1Actual,-15} ");
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed");
Assert.AreEqual(part1, part1Actual, $"Incorrect answer for Day {day.DayNumber} Part1");
// part 2
s.Reset();
s.Start();
var part2Actual = day.Part2();
s.Stop();
Console.Write($"Part 2: {part2Actual,-15} ");
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed");
Assert.AreEqual(part2, part2Actual, $"Incorrect answer for Day {day.DayNumber} Part2");
} }
} }

View File

@ -33,29 +33,6 @@ public class Test2020
[DataRow(typeof(Day25), "11707042", "")] [DataRow(typeof(Day25), "11707042", "")]
public void CheckAllDays(Type dayType, string part1, string part2) public void CheckAllDays(Type dayType, string part1, string part2)
{ {
Day.Year = 2020; Common.CheckDay(dayType, part1, part2);
// create day instance
var s = Stopwatch.StartNew();
var day = Activator.CreateInstance(dayType) as Day;
s.Stop();
Assert.IsNotNull(day, "failed to create day object");
Console.WriteLine($"{s.ScaleMilliseconds()}ms elapsed in constructor");
// part 1
s.Reset();
s.Start();
var part1Actual = day!.Part1();
s.Stop();
Console.WriteLine($"{s.ScaleMilliseconds()}ms elapsed in part1");
Assert.AreEqual(part1, part1Actual, $"Incorrect answer for Day {day.DayNumber} Part1");
// part 2
s.Reset();
s.Start();
var part2Actual = day.Part2();
s.Stop();
Console.WriteLine($"{s.ScaleMilliseconds()}ms elapsed in part2");
Assert.AreEqual(part2, part2Actual, $"Incorrect answer for Day {day.DayNumber} Part2");
} }
} }

View File

@ -50,33 +50,7 @@ public class Test2021
[DataRow(typeof(Day25), "417", "")] [DataRow(typeof(Day25), "417", "")]
public void CheckAllDays(Type dayType, string part1, string part2) public void CheckAllDays(Type dayType, string part1, string part2)
{ {
Day.Year = 2021; Common.CheckDay(dayType, part1, part2);
var s = Stopwatch.StartNew();
var day = Activator.CreateInstance(dayType) as Day;
s.Stop();
Assert.IsNotNull(day, "failed to instantiate day object");
Assert.IsTrue(File.Exists(day.FileName));
Console.Write($"Day {day.DayNumber,2}: {day.PuzzleName,-25} ");
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed in constructor");
// part 1
s.Reset();
s.Start();
var part1Actual = day.Part1().ToString();
s.Stop();
Console.Write($"Part 1: {part1Actual,-25} ");
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed");
Assert.AreEqual(part1, part1Actual, $"Incorrect answer for Day {day.DayNumber} Part1");
// part 2
s.Reset();
s.Start();
var part2Actual = day.Part2().ToString();
s.Stop();
Console.Write($"Part 2: {part2Actual,-25} ");
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed");
Assert.AreEqual(part2, part2Actual, $"Incorrect answer for Day {day.DayNumber} Part2");
} }
[DataTestMethod] [DataTestMethod]
@ -106,33 +80,8 @@ public class Test2021
[DataRow(typeof(Day25), "58", "")] [DataRow(typeof(Day25), "58", "")]
public void CheckTestInputs(Type dayType, string part1, string part2) public void CheckTestInputs(Type dayType, string part1, string part2)
{ {
Day.Year = 2021;
Day.UseTestInput = true; Day.UseTestInput = true;
var s = Stopwatch.StartNew(); Common.CheckDay(dayType, part1, part2);
var day = Activator.CreateInstance(dayType) as Day;
s.Stop();
Assert.IsNotNull(day, "failed to instantiate day object");
Assert.IsTrue(File.Exists(day.FileName));
Console.Write($"Day {day.DayNumber,2}: {day.PuzzleName,-25} ");
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed in constructor");
// part 1
s.Reset();
s.Start();
var part1Actual = day.Part1().ToString();
s.Stop();
Console.Write($"Part 1: {part1Actual,-25} ");
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed");
Assert.AreEqual(part1, part1Actual, $"Incorrect answer for Day {day.DayNumber} Part1");
// part 2
s.Reset();
s.Start();
var part2Actual = day.Part2().ToString();
s.Stop();
Console.Write($"Part 2: {part2Actual,-25} ");
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed");
Assert.AreEqual(part2, part2Actual, $"Incorrect answer for Day {day.DayNumber} Part2");
} }
} }

13
AOC.Test/Test2022.cs Normal file
View File

@ -0,0 +1,13 @@
using AOC2022;
namespace AOC.Test;
[TestClass]
public class Test2022
{
[DataTestMethod]
[DataRow(typeof(Day01), "", "")]
public void CheckAllDays(Type dayType, string part1, string part2)
{
Common.CheckDay(dayType, part1, part2);
}
}

View File

@ -4,7 +4,7 @@ public sealed class Day01 : Day
{ {
private readonly IEnumerable<int> _masses; private readonly IEnumerable<int> _masses;
public Day01() : base(1, "The Tyranny of the Rocket Equation") public Day01() : base(2019, 1, "The Tyranny of the Rocket Equation")
{ {
_masses = Input.Select(int.Parse); _masses = Input.Select(int.Parse);
} }

View File

@ -4,7 +4,7 @@ public sealed class Day02 : Day
{ {
private readonly IEnumerable<int> _input; private readonly IEnumerable<int> _input;
public Day02() : base(2, "1202 Program Alarm") public Day02() : base(2019, 2, "1202 Program Alarm")
{ {
_input = Input.First().Split(',').Select(int.Parse); _input = Input.First().Split(',').Select(int.Parse);
} }

View File

@ -5,7 +5,7 @@ public sealed class Day03 : Day
private readonly IEnumerable<(int, int)> _intersections; private readonly IEnumerable<(int, int)> _intersections;
private readonly List<Dictionary<(int, int), int>> _wires; private readonly List<Dictionary<(int, int), int>> _wires;
public Day03() : base(3, "Crossed Wires") public Day03() : base(2019, 3, "Crossed Wires")
{ {
_wires = Input.Select(ParseWire).ToList(); _wires = Input.Select(ParseWire).ToList();
_intersections = _wires[0].Keys.Intersect(_wires[1].Keys); _intersections = _wires[0].Keys.Intersect(_wires[1].Keys);

View File

@ -4,7 +4,7 @@ public sealed class Day04 : Day
{ {
private readonly int _start, _end; private readonly int _start, _end;
public Day04() : base(4, "Secure Container") public Day04() : base(2019, 4, "Secure Container")
{ {
var range = Input.First().Split('-').Select(int.Parse).ToList(); var range = Input.First().Split('-').Select(int.Parse).ToList();
_start = range[0]; _start = range[0];

View File

@ -5,7 +5,7 @@ public sealed class Day05 : Day
private readonly IEnumerable<int> _tape; private readonly IEnumerable<int> _tape;
private int _output; private int _output;
public Day05() : base(5, "Sunny with a Chance of Asteroids") public Day05() : base(2019, 5, "Sunny with a Chance of Asteroids")
{ {
_tape = Input.First().Split(',').Select(int.Parse); _tape = Input.First().Split(',').Select(int.Parse);
} }

View File

@ -4,7 +4,7 @@ public sealed class Day06 : Day
{ {
private readonly Dictionary<string, string> _input; private readonly Dictionary<string, string> _input;
public Day06() : base(6, "Universal Orbit Map") public Day06() : base(2019, 6, "Universal Orbit Map")
{ {
_input = Input.ToDictionary(i => i.Split(')')[1], i => i.Split(')')[0]); _input = Input.ToDictionary(i => i.Split(')')[1], i => i.Split(')')[0]);
} }

View File

@ -4,7 +4,7 @@ public sealed class Day07 : Day
{ {
private readonly IntCodeVM[] _amplifiers = new IntCodeVM[5]; private readonly IntCodeVM[] _amplifiers = new IntCodeVM[5];
public Day07() : base(7, "Amplification Circuit") public Day07() : base(2019, 7, "Amplification Circuit")
{ {
for (var i = 0; i < 5; i++) _amplifiers[i] = new(Input.First()); for (var i = 0; i < 5; i++) _amplifiers[i] = new(Input.First());
} }

View File

@ -4,7 +4,7 @@ public sealed class Day08 : Day
{ {
private readonly List<List<char>> _photo; private readonly List<List<char>> _photo;
public Day08() : base(8, "Space Image Format") public Day08() : base(2019, 8, "Space Image Format")
{ {
_photo = Input.First().Chunk(25 * 6).Select(s => s.ToList()).ToList(); _photo = Input.First().Chunk(25 * 6).Select(s => s.ToList()).ToList();
} }

View File

@ -4,7 +4,7 @@ public sealed class Day09 : Day
{ {
private readonly IntCodeVM _vm; private readonly IntCodeVM _vm;
public Day09() : base(9, "Sensor Boost") public Day09() : base(2019, 9, "Sensor Boost")
{ {
_vm = new(Input.First()); _vm = new(Input.First());
} }

View File

@ -6,7 +6,7 @@ public sealed class Day10 : Day
private (int x, int y) _best = (x: -1, y: -1); private (int x, int y) _best = (x: -1, y: -1);
private int _bestCanSee; private int _bestCanSee;
public Day10() : base(10, "Monitoring Station") public Day10() : base(2019, 10, "Monitoring Station")
{ {
_asteroids = Input _asteroids = Input
.Select((r, y) => r.Select((c, x) => (x, y, isAsteroid: c == '#')).ToArray()) .Select((r, y) => r.Select((c, x) => (x, y, isAsteroid: c == '#')).ToArray())

View File

@ -6,7 +6,7 @@ public sealed class Day11 : Day
private Direction _heading; private Direction _heading;
private long _x, _y; private long _x, _y;
public Day11() : base(11, "Space Police") public Day11() : base(2019, 11, "Space Police")
{ {
_vm = new(Input.First()); _vm = new(Input.First());
} }
@ -58,7 +58,7 @@ public sealed class Day11 : Day
var haltType = IntCodeVM.HaltType.Waiting; var haltType = IntCodeVM.HaltType.Waiting;
while (haltType == IntCodeVM.HaltType.Waiting) while (haltType == IntCodeVM.HaltType.Waiting)
{ {
haltType = _vm.Run(map.GetValueOrDefault((x: _x, y: _y))); haltType = _vm.Run(map.GetValueOrDefault((_x, _y)));
map[(_x, _y)] = _vm.Result; map[(_x, _y)] = _vm.Result;
Turn(_vm.Result); Turn(_vm.Result);
} }

View File

@ -5,7 +5,7 @@ public sealed class Day12 : Day
private readonly List<Position> _moons; private readonly List<Position> _moons;
private int _step; private int _step;
public Day12() : base(12, "The N-Body Problem") public Day12() : base(2019, 12, "The N-Body Problem")
{ {
_moons = Input _moons = Input
.Select(moon => .Select(moon =>

View File

@ -5,7 +5,7 @@ public sealed class Day13 : Day
private readonly Dictionary<(int x, int y), int> _board; private readonly Dictionary<(int x, int y), int> _board;
private readonly IntCodeVM _vm; private readonly IntCodeVM _vm;
public Day13() : base(13, "Care Package") public Day13() : base(2019, 13, "Care Package")
{ {
_vm = new(Input.First()); _vm = new(Input.First());
_board = new Dictionary<(int, int), int>(); _board = new Dictionary<(int, int), int>();

View File

@ -6,7 +6,7 @@ public sealed class Day14 : Day
private Dictionary<string, long> _available; private Dictionary<string, long> _available;
public Day14() : base(14, "Space Stoichiometry") public Day14() : base(2019, 14, "Space Stoichiometry")
{ {
_reactions = Input _reactions = Input
.Select(Reaction.Parse) .Select(Reaction.Parse)

View File

@ -5,7 +5,7 @@ public sealed class Day15 : Day
private readonly bool _verbose = false; private readonly bool _verbose = false;
private readonly IntCodeVM _vm; private readonly IntCodeVM _vm;
public Day15() : base(15, "Oxygen System") public Day15() : base(2019, 15, "Oxygen System")
{ {
_vm = new(Input.First()); _vm = new(Input.First());
} }

View File

@ -5,7 +5,7 @@ public sealed class Day16 : Day
private static readonly int[] BasePattern = { 0, 1, 0, -1 }; private static readonly int[] BasePattern = { 0, 1, 0, -1 };
private readonly int[] _initialList; private readonly int[] _initialList;
public Day16() : base(16, "Flawed Frequency Transmission") public Day16() : base(2019, 16, "Flawed Frequency Transmission")
{ {
_initialList = Input.First().Select(c => int.Parse($"{c}")).ToArray(); _initialList = Input.First().Select(c => int.Parse($"{c}")).ToArray();
} }

View File

@ -4,7 +4,7 @@ public sealed class Day17 : Day
{ {
private readonly IntCodeVM _vm; private readonly IntCodeVM _vm;
public Day17() : base(17, "Set and Forget") public Day17() : base(2019, 17, "Set and Forget")
{ {
_vm = new(Input.First()); _vm = new(Input.First());
} }

View File

@ -2,7 +2,7 @@
public sealed class Day18 : Day public sealed class Day18 : Day
{ {
public Day18() : base(18, "Many-Worlds Interpretation") public Day18() : base(2019, 18, "Many-Worlds Interpretation")
{ {
} }

View File

@ -5,7 +5,7 @@ public sealed class Day19 : Day
private readonly long[,] _grid; private readonly long[,] _grid;
private readonly IntCodeVM _vm; private readonly IntCodeVM _vm;
public Day19() : base(19, "Tractor Beam") public Day19() : base(2019, 19, "Tractor Beam")
{ {
_vm = new(Input.First()); _vm = new(Input.First());
_grid = new long[50, 50]; _grid = new long[50, 50];

View File

@ -2,7 +2,7 @@
public sealed class Day20 : Day public sealed class Day20 : Day
{ {
public Day20() : base(20, "Donut Maze") public Day20() : base(2019, 20, "Donut Maze")
{ {
} }

View File

@ -4,7 +4,7 @@ public sealed class Day21 : Day
{ {
private readonly IntCodeVM _vm; private readonly IntCodeVM _vm;
public Day21() : base(21, "Springdroid Adventure") public Day21() : base(2019, 21, "Springdroid Adventure")
{ {
_vm = new(Input.First()); _vm = new(Input.First());
} }

View File

@ -2,7 +2,7 @@
public sealed class Day22 : Day public sealed class Day22 : Day
{ {
public Day22() : base(22, "Slam Shuffle") public Day22() : base(2019, 22, "Slam Shuffle")
{ {
} }

View File

@ -2,7 +2,7 @@ namespace AOC2019;
public sealed class Day23 : Day public sealed class Day23 : Day
{ {
public Day23() : base(23, "Category Six") public Day23() : base(2019, 23, "Category Six")
{ {
} }

View File

@ -2,7 +2,7 @@
public sealed class Day24 : Day public sealed class Day24 : Day
{ {
public Day24() : base(24, "Planet of Discord") public Day24() : base(2019, 24, "Planet of Discord")
{ {
} }

View File

@ -2,7 +2,7 @@
public sealed class Day25 : Day public sealed class Day25 : Day
{ {
public Day25() : base(25, "Cryostasis") public Day25() : base(2019, 25, "Cryostasis")
{ {
} }

View File

@ -1,21 +1,15 @@
Day.Year = 2019; var days = Assembly.GetExecutingAssembly().GetTypes()
.Where(t => t.BaseType == typeof(Day))
var days = .Select(t => (Activator.CreateInstance(t) as Day)!)
Assembly.GetExecutingAssembly().GetTypes() .OrderBy(d => d.DayNumber);
.Where(t => t.BaseType == typeof(Day))
.Select(t => Activator.CreateInstance(t) as Day)
.OrderBy(d => d?.DayNumber);
if (args.Length == 1 && int.TryParse(args[0], out var dayNum)) if (args.Length == 1 && int.TryParse(args[0], out var dayNum))
{ {
var day = days.FirstOrDefault(d => d?.DayNumber == dayNum); var day = days.FirstOrDefault(d => d.DayNumber == dayNum);
if (day != null) day.AllParts();
if (day != null) else Console.WriteLine($"Day {dayNum} invalid or not yet implemented");
day.AllParts();
else
Console.WriteLine($"{dayNum} invalid or not yet implemented");
} }
else else
{ {
foreach (var d in days) d?.AllParts(); foreach (var d in days) d.AllParts();
} }

View File

@ -7,7 +7,7 @@ public sealed class Day01 : Day
{ {
private readonly ImmutableHashSet<int> _entries; private readonly ImmutableHashSet<int> _entries;
public Day01() : base(1, "Report Repair") => public Day01() : base(2020, 1, "Report Repair") =>
_entries = Input.Select(int.Parse).ToImmutableHashSet(); _entries = Input.Select(int.Parse).ToImmutableHashSet();
public override string Part1() public override string Part1()

View File

@ -7,7 +7,7 @@ public sealed class Day02 : Day
{ {
private readonly ImmutableList<Password> _passwords; private readonly ImmutableList<Password> _passwords;
public Day02() : base(2, "Password Philosophy") => public Day02() : base(2020, 2, "Password Philosophy") =>
_passwords = Input.Select(p => new Password(p)).ToImmutableList(); _passwords = Input.Select(p => new Password(p)).ToImmutableList();
public override string Part1() => public override string Part1() =>

View File

@ -8,7 +8,7 @@ public sealed class Day03 : Day
private readonly string[] _grid; private readonly string[] _grid;
private readonly int _width; private readonly int _width;
public Day03() : base(3, "Toboggan Trajectory") public Day03() : base(2020, 3, "Toboggan Trajectory")
{ {
_grid = Input.ToArray(); _grid = Input.ToArray();
_width = _grid[0].Length; _width = _grid[0].Length;

View File

@ -7,9 +7,9 @@ public sealed class Day04 : Day
{ {
private readonly List<Passport> _passports; private readonly List<Passport> _passports;
public Day04() : base(4, "Passport Processing") public Day04() : base(2020, 4, "Passport Processing")
{ {
_passports = new List<Passport>(); _passports = new();
var a = new List<string>(); var a = new List<string>();
foreach (var line in Input) foreach (var line in Input)

View File

@ -7,7 +7,7 @@ public sealed class Day05 : Day
{ {
private readonly ImmutableHashSet<int> _ids; private readonly ImmutableHashSet<int> _ids;
public Day05() : base(5, "Binary Boarding") => public Day05() : base(2020, 5, "Binary Boarding") =>
_ids = Input _ids = Input
.Select(s => .Select(s =>
Convert.ToInt32(s.Replace('F', '0').Replace('B', '1').Replace('L', '0').Replace('R', '1'), 2)) Convert.ToInt32(s.Replace('F', '0').Replace('B', '1').Replace('L', '0').Replace('R', '1'), 2))

View File

@ -8,7 +8,7 @@ public sealed class Day06 : Day
private readonly int _countPart1; private readonly int _countPart1;
private readonly int _countPart2; private readonly int _countPart2;
public Day06() : base(6, "Custom Customs") public Day06() : base(2020, 6, "Custom Customs")
{ {
var alphabet = "abcedfghijklmnopqrstuvwxyz".ToCharArray(); var alphabet = "abcedfghijklmnopqrstuvwxyz".ToCharArray();
_countPart1 = 0; _countPart1 = 0;

View File

@ -7,7 +7,7 @@ public sealed class Day07 : Day
{ {
private readonly Dictionary<string, IEnumerable<(int Weight, string Name)?>> _rules; private readonly Dictionary<string, IEnumerable<(int Weight, string Name)?>> _rules;
public Day07() : base(7, "Handy Haversacks") => public Day07() : base(2020, 7, "Handy Haversacks") =>
_rules = Input _rules = Input
.Select(rule => .Select(rule =>
{ {

View File

@ -9,7 +9,7 @@ public sealed class Day08 : Day
private int _accumulator; private int _accumulator;
private int _currentInstruction; private int _currentInstruction;
public Day08() : base(8, "Handheld Halting") => public Day08() : base(2020, 8, "Handheld Halting") =>
_instructions = Input.Select(ParseLine).ToArray(); _instructions = Input.Select(ParseLine).ToArray();
private static (string, int) ParseLine(string line) private static (string, int) ParseLine(string line)

View File

@ -8,7 +8,7 @@ public sealed class Day09 : Day
private readonly long[] _list; private readonly long[] _list;
private long _part1; private long _part1;
public Day09() : base(9, "Encoding Error") => public Day09() : base(2020, 9, "Encoding Error") =>
_list = Input.Select(long.Parse).ToArray(); _list = Input.Select(long.Parse).ToArray();
public override string Part1() public override string Part1()

View File

@ -8,7 +8,7 @@ public sealed class Day10 : Day
private readonly int[] _adapters; private readonly int[] _adapters;
private readonly long[] _memo; private readonly long[] _memo;
public Day10() : base(10, "Adapter Array") public Day10() : base(2020, 10, "Adapter Array")
{ {
var parsed = Input.Select(int.Parse).ToArray(); var parsed = Input.Select(int.Parse).ToArray();
// add socket and device to the list // add socket and device to the list
@ -42,7 +42,7 @@ public sealed class Day10 : Day
case 3: case 3:
threes++; threes++;
break; break;
default: throw new Exception("something went wrong"); default: throw new("something went wrong");
} }
return $"{ones * threes}"; return $"{ones * threes}";

View File

@ -5,7 +5,7 @@ namespace AOC2020;
/// </summary> /// </summary>
public sealed class Day11 : Day public sealed class Day11 : Day
{ {
public Day11() : base(11, "Seating System") public Day11() : base(2020, 11, "Seating System")
{ {
} }

View File

@ -5,7 +5,7 @@ namespace AOC2020;
/// </summary> /// </summary>
public sealed class Day12 : Day public sealed class Day12 : Day
{ {
public Day12() : base(12, "Rain Risk") public Day12() : base(2020, 12, "Rain Risk")
{ {
} }

View File

@ -9,7 +9,7 @@ public sealed class Day13 : Day
private readonly long _earliest; private readonly long _earliest;
private readonly string[] _fullSchedule; private readonly string[] _fullSchedule;
public Day13() : base(13, "Shuttle Search") public Day13() : base(2020, 13, "Shuttle Search")
{ {
_earliest = long.Parse(Input.First()); _earliest = long.Parse(Input.First());
_fullSchedule = Input.Last().Split(','); _fullSchedule = Input.Last().Split(',');

View File

@ -5,7 +5,7 @@ namespace AOC2020;
/// </summary> /// </summary>
public sealed class Day14 : Day public sealed class Day14 : Day
{ {
public Day14() : base(14, "Docking Data") public Day14() : base(2020, 14, "Docking Data")
{ {
} }

View File

@ -9,7 +9,7 @@ public sealed class Day15 : Day
private int _current; private int _current;
private int _i; private int _i;
public Day15() : base(15, "Rambunctious Recitation") public Day15() : base(2020, 15, "Rambunctious Recitation")
{ {
var initial = Input.First().Split(',').Select(int.Parse).ToArray(); var initial = Input.First().Split(',').Select(int.Parse).ToArray();
_turns = new int[30_000_000]; _turns = new int[30_000_000];

View File

@ -8,7 +8,7 @@ public sealed class Day16 : Day
private readonly Dictionary<string, List<Range>> _rules; private readonly Dictionary<string, List<Range>> _rules;
private readonly List<List<int>> _tickets; private readonly List<List<int>> _tickets;
public Day16() : base(16, "Ticket Translation") public Day16() : base(2020, 16, "Ticket Translation")
{ {
_tickets = new(); _tickets = new();
_rules = new(); _rules = new();

View File

@ -9,7 +9,7 @@ public sealed class Day17 : Day
private readonly Dictionary<(int x, int y, int z, int w), char> _plane4 = new(); private readonly Dictionary<(int x, int y, int z, int w), char> _plane4 = new();
public Day17() : base(17, "Conway Cubes") public Day17() : base(2020, 17, "Conway Cubes")
{ {
var input = Input.ToList(); var input = Input.ToList();

View File

@ -7,7 +7,7 @@ public sealed class Day18 : Day
{ {
private readonly List<string> _expressions; private readonly List<string> _expressions;
public Day18() : base(18, "Operation Order") => public Day18() : base(2020, 18, "Operation Order") =>
_expressions = Input.Select(line => line.Replace(" ", "")).ToList(); _expressions = Input.Select(line => line.Replace(" ", "")).ToList();
private static long Calculate(string expr, Func<char, int> precedence) private static long Calculate(string expr, Func<char, int> precedence)

View File

@ -9,7 +9,7 @@ public sealed class Day19 : Day
private readonly Dictionary<string, string[][]> _rules; private readonly Dictionary<string, string[][]> _rules;
private readonly Stack<string> _stack; private readonly Stack<string> _stack;
public Day19() : base(19, "Monster Messages") public Day19() : base(2020, 19, "Monster Messages")
{ {
_rules = Input.TakeWhile(l => !string.IsNullOrWhiteSpace(l)) _rules = Input.TakeWhile(l => !string.IsNullOrWhiteSpace(l))
.Select(l => l.Split(':')) .Select(l => l.Split(':'))

View File

@ -5,7 +5,7 @@ namespace AOC2020;
/// </summary> /// </summary>
public sealed class Day20 : Day public sealed class Day20 : Day
{ {
public Day20() : base(20, "Jurassic Jigsaw") public Day20() : base(2020, 20, "Jurassic Jigsaw")
{ {
} }
@ -53,8 +53,8 @@ public sealed class Day20 : Day
void AddConnection(PuzzlePiece p1, PuzzlePiece p2) void AddConnection(PuzzlePiece p1, PuzzlePiece p2)
{ {
if (!connections.ContainsKey(p1)) connections.Add(p1, new List<PuzzlePiece>()); if (!connections.ContainsKey(p1)) connections.Add(p1, new());
if (!connections.ContainsKey(p2)) connections.Add(p2, new List<PuzzlePiece>()); if (!connections.ContainsKey(p2)) connections.Add(p2, new());
connections[p1].Add(p2); connections[p1].Add(p2);
connections[p2].Add(p1); connections[p2].Add(p1);
} }
@ -195,7 +195,7 @@ public sealed class Day20 : Day
{ {
var id = long.Parse(pieceWithId[0][5..^1]); var id = long.Parse(pieceWithId[0][5..^1]);
var piece = pieceWithId[1..].Select(x => x.ToCharArray()).ToArray(); var piece = pieceWithId[1..].Select(x => x.ToCharArray()).ToArray();
return new PuzzlePiece(id, piece); return new(id, piece);
} }
private PuzzlePiece(long id, char[][] piece) private PuzzlePiece(long id, char[][] piece)
@ -203,14 +203,14 @@ public sealed class Day20 : Day
Id = id; Id = id;
_piece = piece; _piece = piece;
_topSide = new Lazy<string>(() => new string(piece[0])); _topSide = new(() => new(piece[0]));
RightSide = new Lazy<string>(() => new string(piece.Select(line => line[^1]).ToArray())); RightSide = new(() => new(piece.Select(line => line[^1]).ToArray()));
BottomSide = new Lazy<string>(() => new string(piece[^1].Reverse().ToArray())); BottomSide = new(() => new(piece[^1].Reverse().ToArray()));
_leftSide = new Lazy<string>(() => new string(piece.Select(line => line[0]).Reverse().ToArray())); _leftSide = new(() => new(piece.Select(line => line[0]).Reverse().ToArray()));
Sides = new Lazy<string[]>(() => new[] Sides = new(() => new[]
{ _topSide.Value, RightSide.Value, BottomSide.Value, _leftSide.Value }); { _topSide.Value, RightSide.Value, BottomSide.Value, _leftSide.Value });
SidesWithFlippedPaired = new Lazy<(string, string)[]>(() => CalculateSidesWithFlipped(this)); SidesWithFlippedPaired = new(() => CalculateSidesWithFlipped(this));
AllSidesWithFlipped = new Lazy<HashSet<string>>(() => CalculateAllSidesWithFlipped(this)); AllSidesWithFlipped = new(() => CalculateAllSidesWithFlipped(this));
} }
public override bool Equals(object? obj) => obj is PuzzlePiece piece && Id == piece.Id; public override bool Equals(object? obj) => obj is PuzzlePiece piece && Id == piece.Id;
@ -218,10 +218,10 @@ public sealed class Day20 : Day
public override string ToString() => Id.ToString(); public override string ToString() => Id.ToString();
public PuzzlePiece TransformSoTopMatchesWith(string sideToMatch) => public PuzzlePiece TransformSoTopMatchesWith(string sideToMatch) =>
TransformSoSideMatchesWith(new string(sideToMatch.Reverse().ToArray()), p => p._topSide.Value); TransformSoSideMatchesWith(new(sideToMatch.Reverse().ToArray()), p => p._topSide.Value);
public PuzzlePiece TransformSoLeftMatchesWith(string sideToMatch) => public PuzzlePiece TransformSoLeftMatchesWith(string sideToMatch) =>
TransformSoSideMatchesWith(new string(sideToMatch.Reverse().ToArray()), p => p._leftSide.Value); TransformSoSideMatchesWith(new(sideToMatch.Reverse().ToArray()), p => p._leftSide.Value);
private PuzzlePiece TransformSoSideMatchesWith(string sideToMatch, Func<PuzzlePiece, string> getSide) private PuzzlePiece TransformSoSideMatchesWith(string sideToMatch, Func<PuzzlePiece, string> getSide)
{ {
@ -246,10 +246,10 @@ public sealed class Day20 : Day
private static (string, string)[] CalculateSidesWithFlipped(PuzzlePiece piece) => private static (string, string)[] CalculateSidesWithFlipped(PuzzlePiece piece) =>
new (string, string)[] new (string, string)[]
{ {
(piece._topSide.Value, new string(piece._topSide.Value.Reverse().ToArray())), (piece._topSide.Value, new(piece._topSide.Value.Reverse().ToArray())),
(piece.RightSide.Value, new string(piece.RightSide.Value.Reverse().ToArray())), (piece.RightSide.Value, new(piece.RightSide.Value.Reverse().ToArray())),
(piece.BottomSide.Value, new string(piece.BottomSide.Value.Reverse().ToArray())), (piece.BottomSide.Value, new(piece.BottomSide.Value.Reverse().ToArray())),
(piece._leftSide.Value, new string(piece._leftSide.Value.Reverse().ToArray())), (piece._leftSide.Value, new(piece._leftSide.Value.Reverse().ToArray())),
}; };
private static HashSet<string> CalculateAllSidesWithFlipped(PuzzlePiece piece) => private static HashSet<string> CalculateAllSidesWithFlipped(PuzzlePiece piece) =>

View File

@ -8,7 +8,7 @@ public sealed class Day21 : Day
private readonly IEnumerable<(string[] Allergens, string[] Ingredients)> _parsedFoods; private readonly IEnumerable<(string[] Allergens, string[] Ingredients)> _parsedFoods;
private readonly IEnumerable<(string Allergen, string Ingredient)> _dangerousFoods; private readonly IEnumerable<(string Allergen, string Ingredient)> _dangerousFoods;
public Day21() : base(21, "Allergen Assessment") public Day21() : base(2020, 21, "Allergen Assessment")
{ {
_parsedFoods = Input.Select(line => line.TrimEnd(')').Split(" (contains ")) _parsedFoods = Input.Select(line => line.TrimEnd(')').Split(" (contains "))
.Select(split => (Allergens: split[1].Split(", "), Ingredients: split[0].Split(' '))); .Select(split => (Allergens: split[1].Split(", "), Ingredients: split[0].Split(' ')));

View File

@ -8,7 +8,7 @@ public sealed class Day22 : Day
private readonly Queue<int> _deck1 = new(); private readonly Queue<int> _deck1 = new();
private readonly Queue<int> _deck2 = new(); private readonly Queue<int> _deck2 = new();
public Day22() : base(22, "Crab Combat") public Day22() : base(2020, 22, "Crab Combat")
{ {
Reset(); Reset();
} }
@ -47,7 +47,7 @@ public sealed class Day22 : Day
if (seen1.Contains(deck1Hash) || seen2.Contains(deck2Hash)) if (seen1.Contains(deck1Hash) || seen2.Contains(deck2Hash))
{ {
// player1 wins // player1 wins
return (deck1, new Queue<int>()); return (deck1, new());
} }
else else
{ {
@ -85,7 +85,7 @@ public sealed class Day22 : Day
} }
private (Queue<int> deck1, Queue<int> deck2) Play(IEnumerable<int> enumerable1, IEnumerable<int> enumerable2, bool recursive) => private (Queue<int> deck1, Queue<int> deck2) Play(IEnumerable<int> enumerable1, IEnumerable<int> enumerable2, bool recursive) =>
Play(new Queue<int>(enumerable1), new Queue<int>(enumerable2), recursive); Play(new(enumerable1), new(enumerable2), recursive);
private static int CalculateScore(Queue<int> deck) => private static int CalculateScore(Queue<int> deck) =>
deck.Reverse().Zip(Enumerable.Range(1, deck.Count), (a, b) => a * b).Sum(); deck.Reverse().Zip(Enumerable.Range(1, deck.Count), (a, b) => a * b).Sum();

View File

@ -10,7 +10,7 @@ public sealed class Day23 : Day
private readonly long[] _move; private readonly long[] _move;
private long _current; private long _current;
public Day23() : base(23, "Crab Cups") public Day23() : base(2020, 23, "Crab Cups")
{ {
_initialCups = Input.First().Select(c => long.Parse(c.ToString())).ToImmutableList(); _initialCups = Input.First().Select(c => long.Parse(c.ToString())).ToImmutableList();
_current = _initialCups.First(); _current = _initialCups.First();

View File

@ -17,7 +17,7 @@ public sealed class Day24 : Day
private Dictionary<(int q, int r, int s), Tile> _tiles; private Dictionary<(int q, int r, int s), Tile> _tiles;
public Day24() : base(24, "Lobby Layout") public Day24() : base(2020, 24, "Lobby Layout")
{ {
_tiles = Input _tiles = Input
.Select(Tile.FromLine) .Select(Tile.FromLine)
@ -72,7 +72,7 @@ public sealed class Day24 : Day
direction = ""; direction = "";
} }
return new Tile { Location = location }; return new() { Location = location };
} }
public static Tile operator +(Tile t, (int q, int r, int s) direction) => public static Tile operator +(Tile t, (int q, int r, int s) direction) =>

View File

@ -5,7 +5,7 @@ namespace AOC2020;
/// </summary> /// </summary>
public sealed class Day25 : Day public sealed class Day25 : Day
{ {
public Day25() : base(25, "Combo Breaker") public Day25() : base(2020, 25, "Combo Breaker")
{ {
} }

View File

@ -1,6 +1,4 @@
Day.Year = 2020; var days = Assembly.GetExecutingAssembly().GetTypes()
var days = Assembly.GetExecutingAssembly().GetTypes()
.Where(t => t.BaseType == typeof(Day)) .Where(t => t.BaseType == typeof(Day))
.Select(t => (Activator.CreateInstance(t) as Day)!) .Select(t => (Activator.CreateInstance(t) as Day)!)
.OrderBy(d => d.DayNumber); .OrderBy(d => d.DayNumber);
@ -14,4 +12,4 @@ if (args.Length == 1 && int.TryParse(args[0], out var dayNum))
else else
{ {
foreach (var d in days) d.AllParts(); foreach (var d in days) d.AllParts();
} }

View File

@ -7,7 +7,7 @@ public sealed class Day01 : Day
{ {
private readonly List<int> _readings; private readonly List<int> _readings;
public Day01() : base(1, "Sonar Sweep") public Day01() : base(2021, 1, "Sonar Sweep")
{ {
_readings = Input.Select(int.Parse).ToList(); _readings = Input.Select(int.Parse).ToList();
} }

View File

@ -5,7 +5,7 @@
/// </summary> /// </summary>
public sealed class Day02 : Day public sealed class Day02 : Day
{ {
public Day02() : base(2, "Dive!") public Day02() : base(2021, 2, "Dive!")
{ {
} }

View File

@ -7,7 +7,7 @@ public sealed class Day03 : Day
{ {
private readonly List<string> _report; private readonly List<string> _report;
public Day03() : base(3, "Binary Diagnostic") public Day03() : base(2021, 3, "Binary Diagnostic")
{ {
_report = Input.ToList(); _report = Input.ToList();
} }

View File

@ -9,7 +9,7 @@ public sealed class Day04 : Day
private readonly List<List<int>> _boards; private readonly List<List<int>> _boards;
private readonly int _size; private readonly int _size;
public Day04() : base(4, "Giant Squid") public Day04() : base(2021, 4, "Giant Squid")
{ {
_call = Input.First().Split(',').Select(int.Parse).ToList(); _call = Input.First().Split(',').Select(int.Parse).ToList();
_boards = new(); _boards = new();

View File

@ -5,7 +5,7 @@
/// </summary> /// </summary>
public sealed class Day05 : Day public sealed class Day05 : Day
{ {
public Day05() : base(5, "Hydrothermal Venture") public Day05() : base(2021, 5, "Hydrothermal Venture")
{ {
} }

View File

@ -7,7 +7,7 @@ public sealed class Day06 : Day
{ {
private readonly long _p1, _p2; private readonly long _p1, _p2;
public Day06() : base(6, "Lanternfish") public Day06() : base(2021, 6, "Lanternfish")
{ {
var fishes = Input.First().Split(',').Select(long.Parse).ToList(); var fishes = Input.First().Split(',').Select(long.Parse).ToList();
Dictionary<long, long> counts = new(); Dictionary<long, long> counts = new();

View File

@ -7,7 +7,7 @@ public sealed class Day07 : Day
{ {
private readonly List<long> _tape; private readonly List<long> _tape;
public Day07() : base(7, "The Treachery of Whales") public Day07() : base(2021, 7, "The Treachery of Whales")
{ {
_tape = Input.First().Split(',').Select(long.Parse).OrderBy(i => i).ToList(); _tape = Input.First().Split(',').Select(long.Parse).OrderBy(i => i).ToList();
} }

View File

@ -8,7 +8,7 @@ public sealed class Day08 : Day
private static readonly List<char[]> PossibleMappings = private static readonly List<char[]> PossibleMappings =
"abcdefg".ToCharArray().Permute().Select(m => m.ToArray()).ToList(); "abcdefg".ToCharArray().Permute().Select(m => m.ToArray()).ToList();
public Day08() : base(8, "Seven Segment Search") public Day08() : base(2021, 8, "Seven Segment Search")
{ {
} }

View File

@ -11,7 +11,7 @@ public sealed class Day09 : Day
private readonly List<(int x, int y)> _lowPoints; private readonly List<(int x, int y)> _lowPoints;
private readonly List<string> _map; private readonly List<string> _map;
public Day09() : base(9, "Smoke Basin") public Day09() : base(2021, 9, "Smoke Basin")
{ {
_part1Sum = 0; _part1Sum = 0;
_lowPoints = new(); _lowPoints = new();

View File

@ -32,7 +32,7 @@ public sealed class Day10 : Day
private readonly long _score1; private readonly long _score1;
private readonly List<long> _scores2 = new(); private readonly List<long> _scores2 = new();
public Day10() : base(10, "Syntax Scoring") public Day10() : base(2021, 10, "Syntax Scoring")
{ {
_score1 = 0L; _score1 = 0L;
foreach (var line in Input) foreach (var line in Input)

View File

@ -9,7 +9,7 @@ public sealed class Day11 : Day
private readonly int _flashesAfter100, _totalTurns; private readonly int _flashesAfter100, _totalTurns;
private readonly int[][] _octopusField; private readonly int[][] _octopusField;
public Day11() : base(11, "Dumbo Octopus") public Day11() : base(2021, 11, "Dumbo Octopus")
{ {
_octopusField = Input.Select(line => line.Select(c => int.Parse($"{c}")).ToArray()).ToArray(); _octopusField = Input.Select(line => line.Select(c => int.Parse($"{c}")).ToArray()).ToArray();

View File

@ -7,7 +7,7 @@ public sealed class Day12 : Day
{ {
private readonly Dictionary<string, List<string>> _edges = new(); private readonly Dictionary<string, List<string>> _edges = new();
public Day12() : base(12, "Passage Pathing") public Day12() : base(2021, 12, "Passage Pathing")
{ {
foreach (var line in Input) foreach (var line in Input)
{ {

View File

@ -10,7 +10,7 @@ public sealed class Day13 : Day
private List<(int x, int y)> _dots; private List<(int x, int y)> _dots;
private readonly List<(char axis, int index)> _folds; private readonly List<(char axis, int index)> _folds;
public Day13() : base(13, "Transparent Origami") public Day13() : base(2021, 13, "Transparent Origami")
{ {
var s = Input.Split("").ToList(); var s = Input.Split("").ToList();

View File

@ -8,7 +8,7 @@ public sealed class Day14 : Day
private readonly string _template; private readonly string _template;
private readonly Dictionary<string, string> _substitutionPairs; private readonly Dictionary<string, string> _substitutionPairs;
public Day14() : base(14, "Extended Polymerization") public Day14() : base(2021, 14, "Extended Polymerization")
{ {
_template = Input.First(); _template = Input.First();
_substitutionPairs = Input.Skip(2).Select(l => l.Split(" -> ")).ToDictionary(k => k[0], v => v[1]); _substitutionPairs = Input.Skip(2).Select(l => l.Split(" -> ")).ToDictionary(k => k[0], v => v[1]);

View File

@ -19,7 +19,7 @@ public sealed class Day15 : Day
private readonly Dictionary<(int x, int y), Node> _grid; private readonly Dictionary<(int x, int y), Node> _grid;
private readonly int _width; private readonly int _width;
public Day15() : base(15, "Chiton") public Day15() : base(2021, 15, "Chiton")
{ {
_grid = Input _grid = Input
.SelectMany((line, y) => .SelectMany((line, y) =>

View File

@ -7,7 +7,7 @@ public sealed class Day16 : Day
{ {
private readonly Packet _packet; private readonly Packet _packet;
public Day16() : base(16, "Packet Decoder") public Day16() : base(2021, 16, "Packet Decoder")
{ {
var bits = string.Join(string.Empty, var bits = string.Join(string.Empty,
Input.First().Select(c => Convert.ToString(Convert.ToInt32(c.ToString(), 16), 2).PadLeft(4, '0'))); Input.First().Select(c => Convert.ToString(Convert.ToInt32(c.ToString(), 16), 2).PadLeft(4, '0')));

View File

@ -7,7 +7,7 @@ public sealed class Day17 : Day
{ {
private readonly List<int> _target; private readonly List<int> _target;
public Day17() : base(17, "Trick Shot") public Day17() : base(2021, 17, "Trick Shot")
{ {
_target = Input.First() _target = Input.First()
.Split(' ', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries) .Split(' ', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)

View File

@ -7,7 +7,7 @@ public sealed class Day18 : Day
{ {
private readonly List<string> _fishes; private readonly List<string> _fishes;
public Day18() : base(18, "Snailfish") public Day18() : base(2021, 18, "Snailfish")
{ {
_fishes = Input.ToList(); _fishes = Input.ToList();
} }

View File

@ -11,7 +11,7 @@ public sealed class Day19 : Day
private readonly List<HashSet<Vector3>> _scans; private readonly List<HashSet<Vector3>> _scans;
private List<HashSet<Vector3>> _scanners = new(); private List<HashSet<Vector3>> _scanners = new();
public Day19() : base(19, "Beacon Scanner") public Day19() : base(2021, 19, "Beacon Scanner")
{ {
_scans = Input _scans = Input
.Aggregate(new List<HashSet<Vector3>>(), (list, line) => .Aggregate(new List<HashSet<Vector3>>(), (list, line) =>

View File

@ -8,7 +8,7 @@ public sealed class Day20 : Day
private readonly ImmutableArray<bool> _enhancementAlgorithm; private readonly ImmutableArray<bool> _enhancementAlgorithm;
private readonly Image _initialImage; private readonly Image _initialImage;
public Day20() : base(20, "Trench Map") public Day20() : base(2021, 20, "Trench Map")
{ {
_enhancementAlgorithm = Input.First().Select(ch => ch == '#').ToImmutableArray(); _enhancementAlgorithm = Input.First().Select(ch => ch == '#').ToImmutableArray();
_initialImage = Parse(Input.Skip(2).ToList()); _initialImage = Parse(Input.Skip(2).ToList());

View File

@ -11,7 +11,7 @@ public sealed class Day21 : Day
private int _rollCount; private int _rollCount;
private ulong _player1Victories, _player2Victories; private ulong _player1Victories, _player2Victories;
public Day21() : base(21, "Dirac Dice") public Day21() : base(2021, 21, "Dirac Dice")
{ {
var s = Input var s = Input
.Select(l => l.Split(": ")[1]) .Select(l => l.Split(": ")[1])

View File

@ -7,7 +7,7 @@ public sealed class Day22 : Day
{ {
private readonly List<Instruction> _instructions = new(); private readonly List<Instruction> _instructions = new();
public Day22() : base(22, "Reactor Reboot") public Day22() : base(2021, 22, "Reactor Reboot")
{ {
foreach (var line in Input) foreach (var line in Input)
{ {

View File

@ -7,7 +7,7 @@ public sealed class Day23 : Day
{ {
private readonly List<char> _crabs; private readonly List<char> _crabs;
public Day23() : base(23, "Amphipod") public Day23() : base(2021, 23, "Amphipod")
{ {
_crabs = Input.SelectMany(l => l).Where(char.IsLetter).ToList(); _crabs = Input.SelectMany(l => l).Where(char.IsLetter).ToList();
} }

View File

@ -7,7 +7,7 @@ public sealed class Day24 : Day
{ {
private readonly Dictionary<int, (int x, int y)> _keys = new(); private readonly Dictionary<int, (int x, int y)> _keys = new();
public Day24() : base(24, "Arithmetic Logic Unit") public Day24() : base(2021, 24, "Arithmetic Logic Unit")
{ {
var lines = Input.ToList(); var lines = Input.ToList();
var pairs = Enumerable.Range(0, 14) var pairs = Enumerable.Range(0, 14)

View File

@ -7,7 +7,7 @@ public sealed class Day25 : Day
{ {
private readonly char[][] _cucumbers; private readonly char[][] _cucumbers;
public Day25() : base(25, "Sea Cucumber") public Day25() : base(2021, 25, "Sea Cucumber")
{ {
_cucumbers = Input.Select(l => l.ToCharArray()).ToArray(); _cucumbers = Input.Select(l => l.ToCharArray()).ToArray();
} }

View File

@ -1,6 +1,4 @@
Day.Year = 2021; var days = Assembly.GetExecutingAssembly().GetTypes()
var days = Assembly.GetExecutingAssembly().GetTypes()
.Where(t => t.BaseType == typeof(Day)) .Where(t => t.BaseType == typeof(Day))
.Select(t => (Activator.CreateInstance(t) as Day)!) .Select(t => (Activator.CreateInstance(t) as Day)!)
.OrderBy(d => d.DayNumber); .OrderBy(d => d.DayNumber);

29
AOC2022/AOC2022.csproj Normal file
View File

@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<None Update="input2022\*.in">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Using Include="AOC.Common" />
<Using Include="System.Collections.Generic" />
<Using Include="System.Collections.Immutable" />
<Using Include="System.Diagnostics" />
<Using Include="System.Reflection" />
<Using Include="System.Text" />
<Using Include="System.Text.RegularExpressions" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AOC.Common\AOC.Common.csproj" />
</ItemGroup>
</Project>

21
AOC2022/Day01.cs Normal file
View File

@ -0,0 +1,21 @@
namespace AOC2022;
/// <summary>
/// Day 1: <see href="https://adventofcode.com/2022/day/1"/>
/// </summary>
public sealed class Day01 : Day
{
public Day01() : base(2022, 1, "Day 1 Puzzle Name")
{
}
public override object Part1()
{
return "";
}
public override object Part2()
{
return "";
}
}

15
AOC2022/Program.cs Normal file
View File

@ -0,0 +1,15 @@
var days = Assembly.GetExecutingAssembly().GetTypes()
.Where(t => t.BaseType == typeof(Day))
.Select(t => (Activator.CreateInstance(t) as Day)!)
.OrderBy(d => d.DayNumber);
if (args.Length == 1 && int.TryParse(args[0], out var dayNum))
{
var day = days.FirstOrDefault(d => d.DayNumber == dayNum);
if (day != null) day.AllParts();
else Console.WriteLine($"Day {dayNum} invalid or not yet implemented");
}
else
{
foreach (var d in days) d.AllParts();
}

View File

View File

@ -10,6 +10,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AOC.Common", "AOC.Common\AO
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AOC.Test", "AOC.Test\AOC.Test.csproj", "{8A2E8FC3-BC6B-4C7D-B7B2-C949DB484C88}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AOC.Test", "AOC.Test\AOC.Test.csproj", "{8A2E8FC3-BC6B-4C7D-B7B2-C949DB484C88}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AOC2022", "AOC2022\AOC2022.csproj", "{AF6D6164-420C-45B6-BCF3-1729D7374986}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -36,5 +38,9 @@ Global
{8A2E8FC3-BC6B-4C7D-B7B2-C949DB484C88}.Debug|Any CPU.Build.0 = Debug|Any CPU {8A2E8FC3-BC6B-4C7D-B7B2-C949DB484C88}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8A2E8FC3-BC6B-4C7D-B7B2-C949DB484C88}.Release|Any CPU.ActiveCfg = Release|Any CPU {8A2E8FC3-BC6B-4C7D-B7B2-C949DB484C88}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8A2E8FC3-BC6B-4C7D-B7B2-C949DB484C88}.Release|Any CPU.Build.0 = Release|Any CPU {8A2E8FC3-BC6B-4C7D-B7B2-C949DB484C88}.Release|Any CPU.Build.0 = Release|Any CPU
{AF6D6164-420C-45B6-BCF3-1729D7374986}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AF6D6164-420C-45B6-BCF3-1729D7374986}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AF6D6164-420C-45B6-BCF3-1729D7374986}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AF6D6164-420C-45B6-BCF3-1729D7374986}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal