move project to subdirectory and add unit testing
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
day 13 is removed from the test so it doesn't take 4 years
This commit is contained in:
parent
837527d487
commit
cb10768fa1
|
@ -3,7 +3,8 @@ kind: pipeline
|
||||||
name: run
|
name: run
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: run
|
- name: run
|
||||||
image: mcr.microsoft.com/dotnet/sdk:latest
|
image: mcr.microsoft.com/dotnet/sdk:latest
|
||||||
commands:
|
commands:
|
||||||
- dotnet run
|
- dotnet test
|
||||||
|
- dotnet run --project aoc2019/aoc2019.csproj
|
||||||
|
|
16
aoc2019.sln
16
aoc2019.sln
|
@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 16
|
# Visual Studio Version 16
|
||||||
VisualStudioVersion = 16.0.29519.181
|
VisualStudioVersion = 16.0.29519.181
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "aoc2019", "aoc2019.csproj", "{0F1DADD9-2DC3-4035-BE2A-1CC9BBB623A9}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "aoc2019", "aoc2019\aoc2019.csproj", "{D99F8F27-0CF3-4220-95F5-B8F92D02F17D}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "aoc2019.test", "aoc2019.test\aoc2019.test.csproj", "{D168189E-28FC-440F-B64C-02C6D9FBBEE0}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
@ -11,10 +13,14 @@ Global
|
||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{0F1DADD9-2DC3-4035-BE2A-1CC9BBB623A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{D99F8F27-0CF3-4220-95F5-B8F92D02F17D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{0F1DADD9-2DC3-4035-BE2A-1CC9BBB623A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{D99F8F27-0CF3-4220-95F5-B8F92D02F17D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{0F1DADD9-2DC3-4035-BE2A-1CC9BBB623A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{D99F8F27-0CF3-4220-95F5-B8F92D02F17D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{0F1DADD9-2DC3-4035-BE2A-1CC9BBB623A9}.Release|Any CPU.Build.0 = Release|Any CPU
|
{D99F8F27-0CF3-4220-95F5-B8F92D02F17D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{D168189E-28FC-440F-B64C-02C6D9FBBEE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{D168189E-28FC-440F-B64C-02C6D9FBBEE0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{D168189E-28FC-440F-B64C-02C6D9FBBEE0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{D168189E-28FC-440F-B64C-02C6D9FBBEE0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using aoc2019;
|
||||||
|
using aoc2019.lib;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
||||||
|
namespace aoc2019.test
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class Tests
|
||||||
|
{
|
||||||
|
[DataTestMethod]
|
||||||
|
[DataRow(typeof(Day01), "3394106", "5088280")]
|
||||||
|
[DataRow(typeof(Day02), "3085697", "9425")]
|
||||||
|
[DataRow(typeof(Day03), "1195", "91518")]
|
||||||
|
[DataRow(typeof(Day04), "1079", "699")]
|
||||||
|
[DataRow(typeof(Day05), "7692125", "14340395")]
|
||||||
|
[DataRow(typeof(Day06), "145250", "274")]
|
||||||
|
[DataRow(typeof(Day07), "19650", "35961106")]
|
||||||
|
[DataRow(typeof(Day08), "2413", "xxx xx xxx xxxx xxx \r\nx x x x x x x x x \r\nxxx x x x x xxx \r\nx x x xxx x x x \r\nx x x x x x x x \r\nxxx xx x xxxx xxx ")]
|
||||||
|
[DataRow(typeof(Day09), "3409270027", "82760")]
|
||||||
|
[DataRow(typeof(Day10), "260", "608")]
|
||||||
|
[DataRow(typeof(Day11), "2054", " # # ### #### #### ## ## # # ### \r\n # # # # # # # # # # # # # \r\n ## # # # ### # # # #### ### \r\n # # ### # # #### # # # # # \r\n # # # # # # # # # # # # # # \r\n # # # # #### #### # # ## # # ### ")]
|
||||||
|
[DataRow(typeof(Day12), "10635", "583523031727256")]
|
||||||
|
[DataRow(typeof(Day13), "361", "after 7133 moves, the score is: 17590")]
|
||||||
|
[DataRow(typeof(Day14), "397771", "3126714")]
|
||||||
|
[DataRow(typeof(Day15), "280", "400")]
|
||||||
|
[DataRow(typeof(Day16), "90744714", "82994322")]
|
||||||
|
[DataRow(typeof(Day17), "2804", "")]
|
||||||
|
public void TestAllDays(Type dayType, string part1, string part2)
|
||||||
|
{
|
||||||
|
// create day instance
|
||||||
|
var s = Stopwatch.StartNew();
|
||||||
|
var day = (Day) Activator.CreateInstance(dayType);
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
|
||||||
|
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
|
||||||
|
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
|
||||||
|
<PackageReference Include="coverlet.collector" Version="1.3.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\aoc2019\aoc2019.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
|
@ -43,7 +43,7 @@ namespace aoc2019
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract string Part1();
|
public abstract string Part1();
|
||||||
protected abstract string Part2();
|
public abstract string Part2();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,7 +3,7 @@ using System.Linq;
|
||||||
|
|
||||||
namespace aoc2019
|
namespace aoc2019
|
||||||
{
|
{
|
||||||
internal sealed class Day01 : Day
|
public sealed class Day01 : Day
|
||||||
{
|
{
|
||||||
private readonly IEnumerable<int> masses;
|
private readonly IEnumerable<int> masses;
|
||||||
|
|
||||||
|
@ -30,12 +30,12 @@ namespace aoc2019
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part1()
|
public override string Part1()
|
||||||
{
|
{
|
||||||
return $"{masses.Sum(FuelCost)}";
|
return $"{masses.Sum(FuelCost)}";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part2()
|
public override string Part2()
|
||||||
{
|
{
|
||||||
return $"{masses.Sum(FullCost)}";
|
return $"{masses.Sum(FullCost)}";
|
||||||
}
|
}
|
|
@ -3,7 +3,7 @@ using System.Linq;
|
||||||
|
|
||||||
namespace aoc2019
|
namespace aoc2019
|
||||||
{
|
{
|
||||||
internal sealed class Day02 : Day
|
public sealed class Day02 : Day
|
||||||
{
|
{
|
||||||
private readonly IEnumerable<int> input;
|
private readonly IEnumerable<int> input;
|
||||||
|
|
||||||
|
@ -28,12 +28,12 @@ namespace aoc2019
|
||||||
return v[0];
|
return v[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part1()
|
public override string Part1()
|
||||||
{
|
{
|
||||||
return $"{RunIntCode(12, 2)}";
|
return $"{RunIntCode(12, 2)}";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part2()
|
public override string Part2()
|
||||||
{
|
{
|
||||||
for (var i = 0; i < 100; i++)
|
for (var i = 0; i < 100; i++)
|
||||||
for (var j = 0; j < 100; j++)
|
for (var j = 0; j < 100; j++)
|
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||||
|
|
||||||
namespace aoc2019
|
namespace aoc2019
|
||||||
{
|
{
|
||||||
internal sealed class Day03 : Day
|
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;
|
||||||
|
@ -15,12 +15,12 @@ namespace aoc2019
|
||||||
intersections = wires[0].Keys.Intersect(wires[1].Keys);
|
intersections = wires[0].Keys.Intersect(wires[1].Keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part1()
|
public override string Part1()
|
||||||
{
|
{
|
||||||
return $"{intersections.Min(x => Math.Abs(x.Item1) + Math.Abs(x.Item2))}";
|
return $"{intersections.Min(x => Math.Abs(x.Item1) + Math.Abs(x.Item2))}";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part2()
|
public override string Part2()
|
||||||
{
|
{
|
||||||
// add 2 to count (0, 0) on both lines
|
// add 2 to count (0, 0) on both lines
|
||||||
return $"{intersections.Min(x => wires[0][x] + wires[1][x]) + 2}";
|
return $"{intersections.Min(x => wires[0][x] + wires[1][x]) + 2}";
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace aoc2019
|
namespace aoc2019
|
||||||
{
|
{
|
||||||
internal sealed class Day04 : Day
|
public sealed class Day04 : Day
|
||||||
{
|
{
|
||||||
private readonly int end;
|
private readonly int end;
|
||||||
|
|
||||||
|
@ -36,12 +36,12 @@ namespace aoc2019
|
||||||
return IsValid(i) && s.Select(c => s.Count(j => j == c)).Any(c => c == 2);
|
return IsValid(i) && s.Select(c => s.Count(j => j == c)).Any(c => c == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part1()
|
public override string Part1()
|
||||||
{
|
{
|
||||||
return $"{Enumerable.Range(start, end).Count(IsValid)}";
|
return $"{Enumerable.Range(start, end).Count(IsValid)}";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part2()
|
public override string Part2()
|
||||||
{
|
{
|
||||||
return $"{Enumerable.Range(start, end).Count(HasOnePair)}";
|
return $"{Enumerable.Range(start, end).Count(HasOnePair)}";
|
||||||
}
|
}
|
|
@ -3,7 +3,7 @@ using System.Linq;
|
||||||
|
|
||||||
namespace aoc2019
|
namespace aoc2019
|
||||||
{
|
{
|
||||||
internal sealed class Day05 : Day
|
public sealed class Day05 : Day
|
||||||
{
|
{
|
||||||
private readonly IEnumerable<int> tape;
|
private readonly IEnumerable<int> tape;
|
||||||
|
|
||||||
|
@ -63,13 +63,13 @@ namespace aoc2019
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part1()
|
public override string Part1()
|
||||||
{
|
{
|
||||||
RunIntCode(tape.ToList(), 1);
|
RunIntCode(tape.ToList(), 1);
|
||||||
return $"{output}";
|
return $"{output}";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part2()
|
public override string Part2()
|
||||||
{
|
{
|
||||||
RunIntCode(tape.ToList(), 5);
|
RunIntCode(tape.ToList(), 5);
|
||||||
return $"{output}";
|
return $"{output}";
|
|
@ -3,7 +3,7 @@ using System.Linq;
|
||||||
|
|
||||||
namespace aoc2019
|
namespace aoc2019
|
||||||
{
|
{
|
||||||
internal sealed class Day06 : Day
|
public sealed class Day06 : Day
|
||||||
{
|
{
|
||||||
private readonly Dictionary<string, string> input;
|
private readonly Dictionary<string, string> input;
|
||||||
|
|
||||||
|
@ -21,12 +21,12 @@ namespace aoc2019
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part1()
|
public override string Part1()
|
||||||
{
|
{
|
||||||
return $"{input.Keys.Sum(o => GetParents(o).Count - 1)}";
|
return $"{input.Keys.Sum(o => GetParents(o).Count - 1)}";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part2()
|
public override string Part2()
|
||||||
{
|
{
|
||||||
var you = GetParents("YOU");
|
var you = GetParents("YOU");
|
||||||
var san = GetParents("SAN");
|
var san = GetParents("SAN");
|
|
@ -4,7 +4,7 @@ using aoc2019.lib;
|
||||||
|
|
||||||
namespace aoc2019
|
namespace aoc2019
|
||||||
{
|
{
|
||||||
internal sealed class Day07 : Day
|
public sealed class Day07 : Day
|
||||||
{
|
{
|
||||||
private readonly IntCodeVM[] Amplifiers = new IntCodeVM[5];
|
private readonly IntCodeVM[] Amplifiers = new IntCodeVM[5];
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ namespace aoc2019
|
||||||
for (var i = 0; i < 5; i++) Amplifiers[i] = new IntCodeVM(Input.First());
|
for (var i = 0; i < 5; i++) Amplifiers[i] = new IntCodeVM(Input.First());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part1()
|
public override string Part1()
|
||||||
{
|
{
|
||||||
long i, largest = 0;
|
long i, largest = 0;
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ namespace aoc2019
|
||||||
return $"{largest}";
|
return $"{largest}";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part2()
|
public override string Part2()
|
||||||
{
|
{
|
||||||
long i, largest = 0;
|
long i, largest = 0;
|
||||||
|
|
|
@ -5,7 +5,7 @@ using aoc2019.lib;
|
||||||
|
|
||||||
namespace aoc2019
|
namespace aoc2019
|
||||||
{
|
{
|
||||||
internal sealed class Day08 : Day
|
public sealed class Day08 : Day
|
||||||
{
|
{
|
||||||
private readonly List<List<char>> photo;
|
private readonly List<List<char>> photo;
|
||||||
|
|
||||||
|
@ -14,13 +14,13 @@ namespace aoc2019
|
||||||
photo = Input.First().Chunk(25 * 6).Select(s => s.ToList()).ToList();
|
photo = Input.First().Chunk(25 * 6).Select(s => s.ToList()).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part1()
|
public override string Part1()
|
||||||
{
|
{
|
||||||
var l = photo.OrderBy(layer => layer.Count(pixel => pixel == '0')).First();
|
var l = photo.OrderBy(layer => layer.Count(pixel => pixel == '0')).First();
|
||||||
return $"{l.Count(p => p == '1') * l.Count(p => p == '2')}";
|
return $"{l.Count(p => p == '1') * l.Count(p => p == '2')}";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part2()
|
public override string Part2()
|
||||||
{
|
{
|
||||||
return Enumerable.Range(0, 25 * 6)
|
return Enumerable.Range(0, 25 * 6)
|
||||||
.Select(p => Enumerable.Range(0, photo.Count)
|
.Select(p => Enumerable.Range(0, photo.Count)
|
|
@ -3,7 +3,7 @@ using aoc2019.lib;
|
||||||
|
|
||||||
namespace aoc2019
|
namespace aoc2019
|
||||||
{
|
{
|
||||||
internal sealed class Day09 : Day
|
public sealed class Day09 : Day
|
||||||
{
|
{
|
||||||
private readonly IntCodeVM vm;
|
private readonly IntCodeVM vm;
|
||||||
|
|
||||||
|
@ -12,14 +12,14 @@ namespace aoc2019
|
||||||
vm = new IntCodeVM(Input.First());
|
vm = new IntCodeVM(Input.First());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part1()
|
public override string Part1()
|
||||||
{
|
{
|
||||||
vm.Reset();
|
vm.Reset();
|
||||||
vm.Run(1);
|
vm.Run(1);
|
||||||
return $"{vm.output.ToDelimitedString(",")}";
|
return $"{vm.output.ToDelimitedString(",")}";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part2()
|
public override string Part2()
|
||||||
{
|
{
|
||||||
vm.Reset();
|
vm.Reset();
|
||||||
vm.Run(2);
|
vm.Run(2);
|
|
@ -5,7 +5,7 @@ using aoc2019.lib;
|
||||||
|
|
||||||
namespace aoc2019
|
namespace aoc2019
|
||||||
{
|
{
|
||||||
internal sealed class Day10 : Day
|
public sealed class Day10 : Day
|
||||||
{
|
{
|
||||||
private readonly HashSet<(int x, int y)> asteroids;
|
private readonly HashSet<(int x, int y)> asteroids;
|
||||||
private (int x, int y) best = (x: -1, y: -1);
|
private (int x, int y) best = (x: -1, y: -1);
|
||||||
|
@ -21,7 +21,7 @@ namespace aoc2019
|
||||||
.ToHashSet();
|
.ToHashSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part1()
|
public override string Part1()
|
||||||
{
|
{
|
||||||
foreach (var asteroid in asteroids)
|
foreach (var asteroid in asteroids)
|
||||||
{
|
{
|
||||||
|
@ -41,7 +41,7 @@ namespace aoc2019
|
||||||
return $"{bestCanSee}";
|
return $"{bestCanSee}";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part2()
|
public override string Part2()
|
||||||
{
|
{
|
||||||
static IEnumerable<(int x, int y, double angle, double dist)> GetValue(
|
static IEnumerable<(int x, int y, double angle, double dist)> GetValue(
|
||||||
Queue<(int x, int y, double angle, double dist)> q)
|
Queue<(int x, int y, double angle, double dist)> q)
|
|
@ -5,7 +5,7 @@ using aoc2019.lib;
|
||||||
|
|
||||||
namespace aoc2019
|
namespace aoc2019
|
||||||
{
|
{
|
||||||
internal sealed class Day11 : Day
|
public sealed class Day11 : Day
|
||||||
{
|
{
|
||||||
private readonly IntCodeVM vm;
|
private readonly IntCodeVM vm;
|
||||||
private Direction heading;
|
private Direction heading;
|
||||||
|
@ -78,12 +78,12 @@ namespace aoc2019
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part1()
|
public override string Part1()
|
||||||
{
|
{
|
||||||
return $"{PaintShip(0).Count}";
|
return $"{PaintShip(0).Count}";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part2()
|
public override string Part2()
|
||||||
{
|
{
|
||||||
var map = PaintShip(1);
|
var map = PaintShip(1);
|
||||||
var minX = (int) map.Keys.Select(x => x.x).Min();
|
var minX = (int) map.Keys.Select(x => x.x).Min();
|
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||||
|
|
||||||
namespace aoc2019
|
namespace aoc2019
|
||||||
{
|
{
|
||||||
internal sealed class Day12 : Day
|
public sealed class Day12 : Day
|
||||||
{
|
{
|
||||||
private readonly List<Position> moons;
|
private readonly List<Position> moons;
|
||||||
private int step;
|
private int step;
|
||||||
|
@ -48,7 +48,7 @@ namespace aoc2019
|
||||||
step++;
|
step++;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part1()
|
public override string Part1()
|
||||||
{
|
{
|
||||||
while (step < 1000)
|
while (step < 1000)
|
||||||
Step();
|
Step();
|
||||||
|
@ -56,7 +56,7 @@ namespace aoc2019
|
||||||
return $"{moons.Sum(p => p.TotalEnergy)}";
|
return $"{moons.Sum(p => p.TotalEnergy)}";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part2()
|
public override string Part2()
|
||||||
{
|
{
|
||||||
int cycleX = 0, cycleY = 0, cycleZ = 0;
|
int cycleX = 0, cycleY = 0, cycleZ = 0;
|
||||||
|
|
|
@ -5,7 +5,7 @@ using aoc2019.lib;
|
||||||
|
|
||||||
namespace aoc2019
|
namespace aoc2019
|
||||||
{
|
{
|
||||||
internal sealed class Day13 : Day
|
public sealed class Day13 : Day
|
||||||
{
|
{
|
||||||
private readonly Dictionary<(int x, int y), int> board;
|
private readonly Dictionary<(int x, int y), int> board;
|
||||||
|
|
||||||
|
@ -52,14 +52,14 @@ namespace aoc2019
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part1()
|
public override string Part1()
|
||||||
{
|
{
|
||||||
vm.Reset();
|
vm.Reset();
|
||||||
vm.Run();
|
vm.Run();
|
||||||
return $"{vm.output.Where((v, i) => (i + 1) % 3 == 0 && v == 2).Count()}";
|
return $"{vm.output.Where((v, i) => (i + 1) % 3 == 0 && v == 2).Count()}";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part2()
|
public override string Part2()
|
||||||
{
|
{
|
||||||
vm.Reset();
|
vm.Reset();
|
||||||
vm.memory[0] = 2;
|
vm.memory[0] = 2;
|
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||||
|
|
||||||
namespace aoc2019
|
namespace aoc2019
|
||||||
{
|
{
|
||||||
internal sealed class Day14 : Day
|
public sealed class Day14 : Day
|
||||||
{
|
{
|
||||||
private readonly Dictionary<string, Reaction> reactions;
|
private readonly Dictionary<string, Reaction> reactions;
|
||||||
|
|
||||||
|
@ -48,14 +48,14 @@ namespace aoc2019
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part1()
|
public override string Part1()
|
||||||
{
|
{
|
||||||
available = new Dictionary<string, long> {{"ORE", long.MaxValue}};
|
available = new Dictionary<string, long> {{"ORE", long.MaxValue}};
|
||||||
Consume("FUEL", 1);
|
Consume("FUEL", 1);
|
||||||
return $"{long.MaxValue - available["ORE"]}";
|
return $"{long.MaxValue - available["ORE"]}";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part2()
|
public override string Part2()
|
||||||
{
|
{
|
||||||
const long capacity = 1_000_000_000_000;
|
const long capacity = 1_000_000_000_000;
|
||||||
available = new Dictionary<string, long> {{"ORE", capacity}};
|
available = new Dictionary<string, long> {{"ORE", capacity}};
|
|
@ -5,7 +5,7 @@ using aoc2019.lib;
|
||||||
|
|
||||||
namespace aoc2019
|
namespace aoc2019
|
||||||
{
|
{
|
||||||
internal sealed class Day15 : Day
|
public sealed class Day15 : Day
|
||||||
{
|
{
|
||||||
private readonly bool verbose = false;
|
private readonly bool verbose = false;
|
||||||
private readonly IntCodeVM vm;
|
private readonly IntCodeVM vm;
|
||||||
|
@ -15,7 +15,7 @@ namespace aoc2019
|
||||||
vm = new IntCodeVM(Input.First());
|
vm = new IntCodeVM(Input.First());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part1()
|
public override string Part1()
|
||||||
{
|
{
|
||||||
vm.Reset();
|
vm.Reset();
|
||||||
var currentLocation = new Location(0, 0);
|
var currentLocation = new Location(0, 0);
|
||||||
|
@ -109,7 +109,7 @@ namespace aoc2019
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part2()
|
public override string Part2()
|
||||||
{
|
{
|
||||||
var changed = true;
|
var changed = true;
|
||||||
while (changed)
|
while (changed)
|
|
@ -5,7 +5,7 @@ using aoc2019.lib;
|
||||||
|
|
||||||
namespace aoc2019
|
namespace aoc2019
|
||||||
{
|
{
|
||||||
internal sealed class Day16 : Day
|
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;
|
||||||
|
@ -15,7 +15,7 @@ namespace aoc2019
|
||||||
initialList = Input.First().Select(c => int.Parse($"{c}")).ToArray();
|
initialList = Input.First().Select(c => int.Parse($"{c}")).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part1()
|
public override string Part1()
|
||||||
{
|
{
|
||||||
const int phaseCount = 100;
|
const int phaseCount = 100;
|
||||||
var signal0 = initialList.ToArray();
|
var signal0 = initialList.ToArray();
|
||||||
|
@ -29,7 +29,7 @@ namespace aoc2019
|
||||||
.ToArray());
|
.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part2()
|
public override string Part2()
|
||||||
{
|
{
|
||||||
const int phaseCount = 100;
|
const int phaseCount = 100;
|
||||||
var messageOffset = initialList.Take(7).Aggregate((n, i) => n * 10 + i);
|
var messageOffset = initialList.Take(7).Aggregate((n, i) => n * 10 + i);
|
|
@ -5,7 +5,7 @@ using aoc2019.lib;
|
||||||
|
|
||||||
namespace aoc2019
|
namespace aoc2019
|
||||||
{
|
{
|
||||||
internal sealed class Day17 : Day
|
public sealed class Day17 : Day
|
||||||
{
|
{
|
||||||
private const bool Verbose = false;
|
private const bool Verbose = false;
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ namespace aoc2019
|
||||||
vm = new IntCodeVM(Input.First());
|
vm = new IntCodeVM(Input.First());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part1()
|
public override string Part1()
|
||||||
{
|
{
|
||||||
vm.Reset();
|
vm.Reset();
|
||||||
vm.Run();
|
vm.Run();
|
||||||
|
@ -39,7 +39,7 @@ namespace aoc2019
|
||||||
return $"{sum}";
|
return $"{sum}";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Part2()
|
public override string Part2()
|
||||||
{
|
{
|
||||||
//vm.Reset();
|
//vm.Reset();
|
||||||
//vm.memory[0] = 2;
|
//vm.memory[0] = 2;
|
|
@ -1,32 +1,32 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
namespace aoc2019
|
namespace aoc2019
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
private static void Main(string[] args)
|
private static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var days =
|
var days =
|
||||||
Assembly.GetExecutingAssembly().GetTypes()
|
Assembly.GetExecutingAssembly().GetTypes()
|
||||||
.Where(t => t.BaseType == typeof(Day))
|
.Where(t => t.BaseType == typeof(Day))
|
||||||
.Select(t => (Day) Activator.CreateInstance(t))
|
.Select(t => (Day) Activator.CreateInstance(t))
|
||||||
.OrderBy(d => d.DayNumber);
|
.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)
|
if (day != null)
|
||||||
day.AllParts();
|
day.AllParts();
|
||||||
else
|
else
|
||||||
Console.WriteLine($"{dayNum} invalid or not yet implemented");
|
Console.WriteLine($"{dayNum} invalid or not yet implemented");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach (var d in days) d.AllParts();
|
foreach (var d in days) d.AllParts();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,14 +1,14 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Update="input\day*.in">
|
<None Update="input\day*.in">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
Loading…
Reference in New Issue