add Year to Day class
This commit is contained in:
parent
f54e134416
commit
789247aedf
|
@ -2,16 +2,16 @@
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
public static bool UseTestInput { get; set; }
|
||||
|
||||
public static int Year { get; set; }
|
||||
|
||||
public int Year { get; }
|
||||
public int DayNumber { get; }
|
||||
public string PuzzleName { get; }
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
<ProjectReference Include="..\AOC2019\AOC2019.csproj" />
|
||||
<ProjectReference Include="..\AOC2020\AOC2020.csproj" />
|
||||
<ProjectReference Include="..\AOC2021\AOC2021.csproj" />
|
||||
<ProjectReference Include="..\AOC2022\AOC2022.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -35,32 +35,6 @@ public class Test2019
|
|||
//[DataRow(typeof(Day25), "", "")]
|
||||
public void TestAllDays(Type dayType, string part1, string part2)
|
||||
{
|
||||
Day.Year = 2019;
|
||||
|
||||
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");
|
||||
Common.CheckDay(dayType, part1, part2);
|
||||
}
|
||||
}
|
|
@ -33,29 +33,6 @@ public class Test2020
|
|||
[DataRow(typeof(Day25), "11707042", "")]
|
||||
public void CheckAllDays(Type dayType, string part1, string part2)
|
||||
{
|
||||
Day.Year = 2020;
|
||||
|
||||
// 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");
|
||||
Common.CheckDay(dayType, part1, part2);
|
||||
}
|
||||
}
|
|
@ -50,33 +50,7 @@ public class Test2021
|
|||
[DataRow(typeof(Day25), "417", "")]
|
||||
public void CheckAllDays(Type dayType, string part1, string part2)
|
||||
{
|
||||
Day.Year = 2021;
|
||||
|
||||
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");
|
||||
Common.CheckDay(dayType, part1, part2);
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
|
@ -106,33 +80,8 @@ public class Test2021
|
|||
[DataRow(typeof(Day25), "58", "")]
|
||||
public void CheckTestInputs(Type dayType, string part1, string part2)
|
||||
{
|
||||
Day.Year = 2021;
|
||||
Day.UseTestInput = true;
|
||||
|
||||
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");
|
||||
Common.CheckDay(dayType, part1, part2);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ public sealed class Day01 : Day
|
|||
{
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ public sealed class Day02 : Day
|
|||
{
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ public sealed class Day03 : Day
|
|||
private readonly IEnumerable<(int, int)> _intersections;
|
||||
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();
|
||||
_intersections = _wires[0].Keys.Intersect(_wires[1].Keys);
|
||||
|
|
|
@ -4,7 +4,7 @@ public sealed class Day04 : Day
|
|||
{
|
||||
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();
|
||||
_start = range[0];
|
||||
|
|
|
@ -5,7 +5,7 @@ public sealed class Day05 : Day
|
|||
private readonly IEnumerable<int> _tape;
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ public sealed class Day06 : Day
|
|||
{
|
||||
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]);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ public sealed class Day07 : Day
|
|||
{
|
||||
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());
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ public sealed class Day08 : Day
|
|||
{
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ public sealed class Day09 : Day
|
|||
{
|
||||
private readonly IntCodeVM _vm;
|
||||
|
||||
public Day09() : base(9, "Sensor Boost")
|
||||
public Day09() : base(2019, 9, "Sensor Boost")
|
||||
{
|
||||
_vm = new(Input.First());
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ public sealed class Day10 : Day
|
|||
private (int x, int y) _best = (x: -1, y: -1);
|
||||
private int _bestCanSee;
|
||||
|
||||
public Day10() : base(10, "Monitoring Station")
|
||||
public Day10() : base(2019, 10, "Monitoring Station")
|
||||
{
|
||||
_asteroids = Input
|
||||
.Select((r, y) => r.Select((c, x) => (x, y, isAsteroid: c == '#')).ToArray())
|
||||
|
|
|
@ -6,7 +6,7 @@ public sealed class Day11 : Day
|
|||
private Direction _heading;
|
||||
private long _x, _y;
|
||||
|
||||
public Day11() : base(11, "Space Police")
|
||||
public Day11() : base(2019, 11, "Space Police")
|
||||
{
|
||||
_vm = new(Input.First());
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public sealed class Day11 : Day
|
|||
var 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;
|
||||
Turn(_vm.Result);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ public sealed class Day12 : Day
|
|||
private readonly List<Position> _moons;
|
||||
private int _step;
|
||||
|
||||
public Day12() : base(12, "The N-Body Problem")
|
||||
public Day12() : base(2019, 12, "The N-Body Problem")
|
||||
{
|
||||
_moons = Input
|
||||
.Select(moon =>
|
||||
|
|
|
@ -5,7 +5,7 @@ public sealed class Day13 : Day
|
|||
private readonly Dictionary<(int x, int y), int> _board;
|
||||
private readonly IntCodeVM _vm;
|
||||
|
||||
public Day13() : base(13, "Care Package")
|
||||
public Day13() : base(2019, 13, "Care Package")
|
||||
{
|
||||
_vm = new(Input.First());
|
||||
_board = new Dictionary<(int, int), int>();
|
||||
|
|
|
@ -6,7 +6,7 @@ public sealed class Day14 : Day
|
|||
|
||||
private Dictionary<string, long> _available;
|
||||
|
||||
public Day14() : base(14, "Space Stoichiometry")
|
||||
public Day14() : base(2019, 14, "Space Stoichiometry")
|
||||
{
|
||||
_reactions = Input
|
||||
.Select(Reaction.Parse)
|
||||
|
|
|
@ -5,7 +5,7 @@ public sealed class Day15 : Day
|
|||
private readonly bool _verbose = false;
|
||||
private readonly IntCodeVM _vm;
|
||||
|
||||
public Day15() : base(15, "Oxygen System")
|
||||
public Day15() : base(2019, 15, "Oxygen System")
|
||||
{
|
||||
_vm = new(Input.First());
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ public sealed class Day16 : Day
|
|||
private static readonly int[] BasePattern = { 0, 1, 0, -1 };
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ public sealed class Day17 : Day
|
|||
{
|
||||
private readonly IntCodeVM _vm;
|
||||
|
||||
public Day17() : base(17, "Set and Forget")
|
||||
public Day17() : base(2019, 17, "Set and Forget")
|
||||
{
|
||||
_vm = new(Input.First());
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
public sealed class Day18 : Day
|
||||
{
|
||||
public Day18() : base(18, "Many-Worlds Interpretation")
|
||||
public Day18() : base(2019, 18, "Many-Worlds Interpretation")
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ public sealed class Day19 : Day
|
|||
private readonly long[,] _grid;
|
||||
private readonly IntCodeVM _vm;
|
||||
|
||||
public Day19() : base(19, "Tractor Beam")
|
||||
public Day19() : base(2019, 19, "Tractor Beam")
|
||||
{
|
||||
_vm = new(Input.First());
|
||||
_grid = new long[50, 50];
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
public sealed class Day20 : Day
|
||||
{
|
||||
public Day20() : base(20, "Donut Maze")
|
||||
public Day20() : base(2019, 20, "Donut Maze")
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ public sealed class Day21 : Day
|
|||
{
|
||||
private readonly IntCodeVM _vm;
|
||||
|
||||
public Day21() : base(21, "Springdroid Adventure")
|
||||
public Day21() : base(2019, 21, "Springdroid Adventure")
|
||||
{
|
||||
_vm = new(Input.First());
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
public sealed class Day22 : Day
|
||||
{
|
||||
public Day22() : base(22, "Slam Shuffle")
|
||||
public Day22() : base(2019, 22, "Slam Shuffle")
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ namespace AOC2019;
|
|||
|
||||
public sealed class Day23 : Day
|
||||
{
|
||||
public Day23() : base(23, "Category Six")
|
||||
public Day23() : base(2019, 23, "Category Six")
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
public sealed class Day24 : Day
|
||||
{
|
||||
public Day24() : base(24, "Planet of Discord")
|
||||
public Day24() : base(2019, 24, "Planet of Discord")
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
public sealed class Day25 : Day
|
||||
{
|
||||
public Day25() : base(25, "Cryostasis")
|
||||
public Day25() : base(2019, 25, "Cryostasis")
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -1,21 +1,15 @@
|
|||
Day.Year = 2019;
|
||||
|
||||
var days =
|
||||
Assembly.GetExecutingAssembly().GetTypes()
|
||||
.Where(t => t.BaseType == typeof(Day))
|
||||
.Select(t => Activator.CreateInstance(t) as Day)
|
||||
.OrderBy(d => d?.DayNumber);
|
||||
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($"{dayNum} invalid or not yet implemented");
|
||||
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();
|
||||
foreach (var d in days) d.AllParts();
|
||||
}
|
|
@ -7,7 +7,7 @@ public sealed class Day01 : Day
|
|||
{
|
||||
private readonly ImmutableHashSet<int> _entries;
|
||||
|
||||
public Day01() : base(1, "Report Repair") =>
|
||||
public Day01() : base(2020, 1, "Report Repair") =>
|
||||
_entries = Input.Select(int.Parse).ToImmutableHashSet();
|
||||
|
||||
public override string Part1()
|
||||
|
|
|
@ -7,7 +7,7 @@ public sealed class Day02 : Day
|
|||
{
|
||||
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();
|
||||
|
||||
public override string Part1() =>
|
||||
|
|
|
@ -8,7 +8,7 @@ public sealed class Day03 : Day
|
|||
private readonly string[] _grid;
|
||||
private readonly int _width;
|
||||
|
||||
public Day03() : base(3, "Toboggan Trajectory")
|
||||
public Day03() : base(2020, 3, "Toboggan Trajectory")
|
||||
{
|
||||
_grid = Input.ToArray();
|
||||
_width = _grid[0].Length;
|
||||
|
|
|
@ -7,9 +7,9 @@ public sealed class Day04 : Day
|
|||
{
|
||||
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>();
|
||||
foreach (var line in Input)
|
||||
|
|
|
@ -7,7 +7,7 @@ public sealed class Day05 : Day
|
|||
{
|
||||
private readonly ImmutableHashSet<int> _ids;
|
||||
|
||||
public Day05() : base(5, "Binary Boarding") =>
|
||||
public Day05() : base(2020, 5, "Binary Boarding") =>
|
||||
_ids = Input
|
||||
.Select(s =>
|
||||
Convert.ToInt32(s.Replace('F', '0').Replace('B', '1').Replace('L', '0').Replace('R', '1'), 2))
|
||||
|
|
|
@ -8,7 +8,7 @@ public sealed class Day06 : Day
|
|||
private readonly int _countPart1;
|
||||
private readonly int _countPart2;
|
||||
|
||||
public Day06() : base(6, "Custom Customs")
|
||||
public Day06() : base(2020, 6, "Custom Customs")
|
||||
{
|
||||
var alphabet = "abcedfghijklmnopqrstuvwxyz".ToCharArray();
|
||||
_countPart1 = 0;
|
||||
|
|
|
@ -7,7 +7,7 @@ public sealed class Day07 : Day
|
|||
{
|
||||
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
|
||||
.Select(rule =>
|
||||
{
|
||||
|
|
|
@ -9,7 +9,7 @@ public sealed class Day08 : Day
|
|||
private int _accumulator;
|
||||
private int _currentInstruction;
|
||||
|
||||
public Day08() : base(8, "Handheld Halting") =>
|
||||
public Day08() : base(2020, 8, "Handheld Halting") =>
|
||||
_instructions = Input.Select(ParseLine).ToArray();
|
||||
|
||||
private static (string, int) ParseLine(string line)
|
||||
|
|
|
@ -8,7 +8,7 @@ public sealed class Day09 : Day
|
|||
private readonly long[] _list;
|
||||
private long _part1;
|
||||
|
||||
public Day09() : base(9, "Encoding Error") =>
|
||||
public Day09() : base(2020, 9, "Encoding Error") =>
|
||||
_list = Input.Select(long.Parse).ToArray();
|
||||
|
||||
public override string Part1()
|
||||
|
|
|
@ -8,7 +8,7 @@ public sealed class Day10 : Day
|
|||
private readonly int[] _adapters;
|
||||
private readonly long[] _memo;
|
||||
|
||||
public Day10() : base(10, "Adapter Array")
|
||||
public Day10() : base(2020, 10, "Adapter Array")
|
||||
{
|
||||
var parsed = Input.Select(int.Parse).ToArray();
|
||||
// add socket and device to the list
|
||||
|
@ -42,7 +42,7 @@ public sealed class Day10 : Day
|
|||
case 3:
|
||||
threes++;
|
||||
break;
|
||||
default: throw new Exception("something went wrong");
|
||||
default: throw new("something went wrong");
|
||||
}
|
||||
|
||||
return $"{ones * threes}";
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace AOC2020;
|
|||
/// </summary>
|
||||
public sealed class Day11 : Day
|
||||
{
|
||||
public Day11() : base(11, "Seating System")
|
||||
public Day11() : base(2020, 11, "Seating System")
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace AOC2020;
|
|||
/// </summary>
|
||||
public sealed class Day12 : Day
|
||||
{
|
||||
public Day12() : base(12, "Rain Risk")
|
||||
public Day12() : base(2020, 12, "Rain Risk")
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ public sealed class Day13 : Day
|
|||
private readonly long _earliest;
|
||||
private readonly string[] _fullSchedule;
|
||||
|
||||
public Day13() : base(13, "Shuttle Search")
|
||||
public Day13() : base(2020, 13, "Shuttle Search")
|
||||
{
|
||||
_earliest = long.Parse(Input.First());
|
||||
_fullSchedule = Input.Last().Split(',');
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace AOC2020;
|
|||
/// </summary>
|
||||
public sealed class Day14 : Day
|
||||
{
|
||||
public Day14() : base(14, "Docking Data")
|
||||
public Day14() : base(2020, 14, "Docking Data")
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ public sealed class Day15 : Day
|
|||
private int _current;
|
||||
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();
|
||||
_turns = new int[30_000_000];
|
||||
|
|
|
@ -8,7 +8,7 @@ public sealed class Day16 : Day
|
|||
private readonly Dictionary<string, List<Range>> _rules;
|
||||
private readonly List<List<int>> _tickets;
|
||||
|
||||
public Day16() : base(16, "Ticket Translation")
|
||||
public Day16() : base(2020, 16, "Ticket Translation")
|
||||
{
|
||||
_tickets = new();
|
||||
_rules = new();
|
||||
|
|
|
@ -9,7 +9,7 @@ public sealed class Day17 : Day
|
|||
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();
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ public sealed class Day18 : Day
|
|||
{
|
||||
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();
|
||||
|
||||
private static long Calculate(string expr, Func<char, int> precedence)
|
||||
|
|
|
@ -9,7 +9,7 @@ public sealed class Day19 : Day
|
|||
private readonly Dictionary<string, string[][]> _rules;
|
||||
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))
|
||||
.Select(l => l.Split(':'))
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace AOC2020;
|
|||
/// </summary>
|
||||
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)
|
||||
{
|
||||
if (!connections.ContainsKey(p1)) connections.Add(p1, new List<PuzzlePiece>());
|
||||
if (!connections.ContainsKey(p2)) connections.Add(p2, new List<PuzzlePiece>());
|
||||
if (!connections.ContainsKey(p1)) connections.Add(p1, new());
|
||||
if (!connections.ContainsKey(p2)) connections.Add(p2, new());
|
||||
connections[p1].Add(p2);
|
||||
connections[p2].Add(p1);
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ public sealed class Day20 : Day
|
|||
{
|
||||
var id = long.Parse(pieceWithId[0][5..^1]);
|
||||
var piece = pieceWithId[1..].Select(x => x.ToCharArray()).ToArray();
|
||||
return new PuzzlePiece(id, piece);
|
||||
return new(id, piece);
|
||||
}
|
||||
|
||||
private PuzzlePiece(long id, char[][] piece)
|
||||
|
@ -203,14 +203,14 @@ public sealed class Day20 : Day
|
|||
Id = id;
|
||||
_piece = piece;
|
||||
|
||||
_topSide = new Lazy<string>(() => new string(piece[0]));
|
||||
RightSide = new Lazy<string>(() => new string(piece.Select(line => line[^1]).ToArray()));
|
||||
BottomSide = new Lazy<string>(() => new string(piece[^1].Reverse().ToArray()));
|
||||
_leftSide = new Lazy<string>(() => new string(piece.Select(line => line[0]).Reverse().ToArray()));
|
||||
Sides = new Lazy<string[]>(() => new[]
|
||||
_topSide = new(() => new(piece[0]));
|
||||
RightSide = new(() => new(piece.Select(line => line[^1]).ToArray()));
|
||||
BottomSide = new(() => new(piece[^1].Reverse().ToArray()));
|
||||
_leftSide = new(() => new(piece.Select(line => line[0]).Reverse().ToArray()));
|
||||
Sides = new(() => new[]
|
||||
{ _topSide.Value, RightSide.Value, BottomSide.Value, _leftSide.Value });
|
||||
SidesWithFlippedPaired = new Lazy<(string, string)[]>(() => CalculateSidesWithFlipped(this));
|
||||
AllSidesWithFlipped = new Lazy<HashSet<string>>(() => CalculateAllSidesWithFlipped(this));
|
||||
SidesWithFlippedPaired = new(() => CalculateSidesWithFlipped(this));
|
||||
AllSidesWithFlipped = new(() => CalculateAllSidesWithFlipped(this));
|
||||
}
|
||||
|
||||
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 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) =>
|
||||
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)
|
||||
{
|
||||
|
@ -246,10 +246,10 @@ public sealed class Day20 : Day
|
|||
private static (string, string)[] CalculateSidesWithFlipped(PuzzlePiece piece) =>
|
||||
new (string, string)[]
|
||||
{
|
||||
(piece._topSide.Value, new string(piece._topSide.Value.Reverse().ToArray())),
|
||||
(piece.RightSide.Value, new string(piece.RightSide.Value.Reverse().ToArray())),
|
||||
(piece.BottomSide.Value, new string(piece.BottomSide.Value.Reverse().ToArray())),
|
||||
(piece._leftSide.Value, new string(piece._leftSide.Value.Reverse().ToArray())),
|
||||
(piece._topSide.Value, new(piece._topSide.Value.Reverse().ToArray())),
|
||||
(piece.RightSide.Value, new(piece.RightSide.Value.Reverse().ToArray())),
|
||||
(piece.BottomSide.Value, new(piece.BottomSide.Value.Reverse().ToArray())),
|
||||
(piece._leftSide.Value, new(piece._leftSide.Value.Reverse().ToArray())),
|
||||
};
|
||||
|
||||
private static HashSet<string> CalculateAllSidesWithFlipped(PuzzlePiece piece) =>
|
||||
|
|
|
@ -8,7 +8,7 @@ public sealed class Day21 : Day
|
|||
private readonly IEnumerable<(string[] Allergens, string[] Ingredients)> _parsedFoods;
|
||||
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 "))
|
||||
.Select(split => (Allergens: split[1].Split(", "), Ingredients: split[0].Split(' ')));
|
||||
|
|
|
@ -8,7 +8,7 @@ public sealed class Day22 : Day
|
|||
private readonly Queue<int> _deck1 = new();
|
||||
private readonly Queue<int> _deck2 = new();
|
||||
|
||||
public Day22() : base(22, "Crab Combat")
|
||||
public Day22() : base(2020, 22, "Crab Combat")
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public sealed class Day22 : Day
|
|||
if (seen1.Contains(deck1Hash) || seen2.Contains(deck2Hash))
|
||||
{
|
||||
// player1 wins
|
||||
return (deck1, new Queue<int>());
|
||||
return (deck1, new());
|
||||
}
|
||||
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) =>
|
||||
Play(new Queue<int>(enumerable1), new Queue<int>(enumerable2), recursive);
|
||||
Play(new(enumerable1), new(enumerable2), recursive);
|
||||
|
||||
private static int CalculateScore(Queue<int> deck) =>
|
||||
deck.Reverse().Zip(Enumerable.Range(1, deck.Count), (a, b) => a * b).Sum();
|
||||
|
|
|
@ -10,7 +10,7 @@ public sealed class Day23 : Day
|
|||
private readonly long[] _move;
|
||||
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();
|
||||
_current = _initialCups.First();
|
||||
|
|
|
@ -17,7 +17,7 @@ public sealed class Day24 : Day
|
|||
|
||||
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
|
||||
.Select(Tile.FromLine)
|
||||
|
@ -72,7 +72,7 @@ public sealed class Day24 : Day
|
|||
direction = "";
|
||||
}
|
||||
|
||||
return new Tile { Location = location };
|
||||
return new() { Location = location };
|
||||
}
|
||||
|
||||
public static Tile operator +(Tile t, (int q, int r, int s) direction) =>
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace AOC2020;
|
|||
/// </summary>
|
||||
public sealed class Day25 : Day
|
||||
{
|
||||
public Day25() : base(25, "Combo Breaker")
|
||||
public Day25() : base(2020, 25, "Combo Breaker")
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
Day.Year = 2020;
|
||||
|
||||
var days = Assembly.GetExecutingAssembly().GetTypes()
|
||||
var days = Assembly.GetExecutingAssembly().GetTypes()
|
||||
.Where(t => t.BaseType == typeof(Day))
|
||||
.Select(t => (Activator.CreateInstance(t) as Day)!)
|
||||
.OrderBy(d => d.DayNumber);
|
||||
|
@ -14,4 +12,4 @@ if (args.Length == 1 && int.TryParse(args[0], out var dayNum))
|
|||
else
|
||||
{
|
||||
foreach (var d in days) d.AllParts();
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ public sealed class Day01 : Day
|
|||
{
|
||||
private readonly List<int> _readings;
|
||||
|
||||
public Day01() : base(1, "Sonar Sweep")
|
||||
public Day01() : base(2021, 1, "Sonar Sweep")
|
||||
{
|
||||
_readings = Input.Select(int.Parse).ToList();
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
/// </summary>
|
||||
public sealed class Day02 : Day
|
||||
{
|
||||
public Day02() : base(2, "Dive!")
|
||||
public Day02() : base(2021, 2, "Dive!")
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ public sealed class Day03 : Day
|
|||
{
|
||||
private readonly List<string> _report;
|
||||
|
||||
public Day03() : base(3, "Binary Diagnostic")
|
||||
public Day03() : base(2021, 3, "Binary Diagnostic")
|
||||
{
|
||||
_report = Input.ToList();
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ public sealed class Day04 : Day
|
|||
private readonly List<List<int>> _boards;
|
||||
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();
|
||||
_boards = new();
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
/// </summary>
|
||||
public sealed class Day05 : Day
|
||||
{
|
||||
public Day05() : base(5, "Hydrothermal Venture")
|
||||
public Day05() : base(2021, 5, "Hydrothermal Venture")
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ public sealed class Day06 : Day
|
|||
{
|
||||
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();
|
||||
Dictionary<long, long> counts = new();
|
||||
|
|
|
@ -7,7 +7,7 @@ public sealed class Day07 : Day
|
|||
{
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ public sealed class Day08 : Day
|
|||
private static readonly List<char[]> PossibleMappings =
|
||||
"abcdefg".ToCharArray().Permute().Select(m => m.ToArray()).ToList();
|
||||
|
||||
public Day08() : base(8, "Seven Segment Search")
|
||||
public Day08() : base(2021, 8, "Seven Segment Search")
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ public sealed class Day09 : Day
|
|||
private readonly List<(int x, int y)> _lowPoints;
|
||||
private readonly List<string> _map;
|
||||
|
||||
public Day09() : base(9, "Smoke Basin")
|
||||
public Day09() : base(2021, 9, "Smoke Basin")
|
||||
{
|
||||
_part1Sum = 0;
|
||||
_lowPoints = new();
|
||||
|
|
|
@ -32,7 +32,7 @@ public sealed class Day10 : Day
|
|||
private readonly long _score1;
|
||||
private readonly List<long> _scores2 = new();
|
||||
|
||||
public Day10() : base(10, "Syntax Scoring")
|
||||
public Day10() : base(2021, 10, "Syntax Scoring")
|
||||
{
|
||||
_score1 = 0L;
|
||||
foreach (var line in Input)
|
||||
|
|
|
@ -9,7 +9,7 @@ public sealed class Day11 : Day
|
|||
private readonly int _flashesAfter100, _totalTurns;
|
||||
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();
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ public sealed class Day12 : Day
|
|||
{
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -10,7 +10,7 @@ public sealed class Day13 : Day
|
|||
private List<(int x, int y)> _dots;
|
||||
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();
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ public sealed class Day14 : Day
|
|||
private readonly string _template;
|
||||
private readonly Dictionary<string, string> _substitutionPairs;
|
||||
|
||||
public Day14() : base(14, "Extended Polymerization")
|
||||
public Day14() : base(2021, 14, "Extended Polymerization")
|
||||
{
|
||||
_template = Input.First();
|
||||
_substitutionPairs = Input.Skip(2).Select(l => l.Split(" -> ")).ToDictionary(k => k[0], v => v[1]);
|
||||
|
|
|
@ -19,7 +19,7 @@ public sealed class Day15 : Day
|
|||
private readonly Dictionary<(int x, int y), Node> _grid;
|
||||
private readonly int _width;
|
||||
|
||||
public Day15() : base(15, "Chiton")
|
||||
public Day15() : base(2021, 15, "Chiton")
|
||||
{
|
||||
_grid = Input
|
||||
.SelectMany((line, y) =>
|
||||
|
|
|
@ -7,7 +7,7 @@ public sealed class Day16 : Day
|
|||
{
|
||||
private readonly Packet _packet;
|
||||
|
||||
public Day16() : base(16, "Packet Decoder")
|
||||
public Day16() : base(2021, 16, "Packet Decoder")
|
||||
{
|
||||
var bits = string.Join(string.Empty,
|
||||
Input.First().Select(c => Convert.ToString(Convert.ToInt32(c.ToString(), 16), 2).PadLeft(4, '0')));
|
||||
|
|
|
@ -7,7 +7,7 @@ public sealed class Day17 : Day
|
|||
{
|
||||
private readonly List<int> _target;
|
||||
|
||||
public Day17() : base(17, "Trick Shot")
|
||||
public Day17() : base(2021, 17, "Trick Shot")
|
||||
{
|
||||
_target = Input.First()
|
||||
.Split(' ', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)
|
||||
|
|
|
@ -7,7 +7,7 @@ public sealed class Day18 : Day
|
|||
{
|
||||
private readonly List<string> _fishes;
|
||||
|
||||
public Day18() : base(18, "Snailfish")
|
||||
public Day18() : base(2021, 18, "Snailfish")
|
||||
{
|
||||
_fishes = Input.ToList();
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ public sealed class Day19 : Day
|
|||
private readonly List<HashSet<Vector3>> _scans;
|
||||
private List<HashSet<Vector3>> _scanners = new();
|
||||
|
||||
public Day19() : base(19, "Beacon Scanner")
|
||||
public Day19() : base(2021, 19, "Beacon Scanner")
|
||||
{
|
||||
_scans = Input
|
||||
.Aggregate(new List<HashSet<Vector3>>(), (list, line) =>
|
||||
|
|
|
@ -8,7 +8,7 @@ public sealed class Day20 : Day
|
|||
private readonly ImmutableArray<bool> _enhancementAlgorithm;
|
||||
private readonly Image _initialImage;
|
||||
|
||||
public Day20() : base(20, "Trench Map")
|
||||
public Day20() : base(2021, 20, "Trench Map")
|
||||
{
|
||||
_enhancementAlgorithm = Input.First().Select(ch => ch == '#').ToImmutableArray();
|
||||
_initialImage = Parse(Input.Skip(2).ToList());
|
||||
|
|
|
@ -11,7 +11,7 @@ public sealed class Day21 : Day
|
|||
private int _rollCount;
|
||||
private ulong _player1Victories, _player2Victories;
|
||||
|
||||
public Day21() : base(21, "Dirac Dice")
|
||||
public Day21() : base(2021, 21, "Dirac Dice")
|
||||
{
|
||||
var s = Input
|
||||
.Select(l => l.Split(": ")[1])
|
||||
|
|
|
@ -7,7 +7,7 @@ public sealed class Day22 : Day
|
|||
{
|
||||
private readonly List<Instruction> _instructions = new();
|
||||
|
||||
public Day22() : base(22, "Reactor Reboot")
|
||||
public Day22() : base(2021, 22, "Reactor Reboot")
|
||||
{
|
||||
foreach (var line in Input)
|
||||
{
|
||||
|
|
|
@ -7,7 +7,7 @@ public sealed class Day23 : Day
|
|||
{
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ public sealed class Day24 : Day
|
|||
{
|
||||
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 pairs = Enumerable.Range(0, 14)
|
||||
|
|
|
@ -7,7 +7,7 @@ public sealed class Day25 : Day
|
|||
{
|
||||
private readonly char[][] _cucumbers;
|
||||
|
||||
public Day25() : base(25, "Sea Cucumber")
|
||||
public Day25() : base(2021, 25, "Sea Cucumber")
|
||||
{
|
||||
_cucumbers = Input.Select(l => l.ToCharArray()).ToArray();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
Day.Year = 2021;
|
||||
|
||||
var days = Assembly.GetExecutingAssembly().GetTypes()
|
||||
var days = Assembly.GetExecutingAssembly().GetTypes()
|
||||
.Where(t => t.BaseType == typeof(Day))
|
||||
.Select(t => (Activator.CreateInstance(t) as Day)!)
|
||||
.OrderBy(d => d.DayNumber);
|
||||
|
|
|
@ -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>
|
|
@ -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 "";
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
|
@ -10,6 +10,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AOC.Common", "AOC.Common\AO
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AOC.Test", "AOC.Test\AOC.Test.csproj", "{8A2E8FC3-BC6B-4C7D-B7B2-C949DB484C88}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AOC2022", "AOC2022\AOC2022.csproj", "{AF6D6164-420C-45B6-BCF3-1729D7374986}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
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}.Release|Any CPU.ActiveCfg = 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
|
||||
EndGlobal
|
||||
|
|
Loading…
Reference in New Issue