diff --git a/AoC.sln b/AoC.sln index 1567efaf2e829a3cd96654a1b142acb6a679c361..3a8e8e2868d5528410be373fc6c3e26cea94fd70 100644 --- a/AoC.sln +++ b/AoC.sln @@ -11,6 +11,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AoC2", "AoC2", "{79F9A7C9-3 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AoC2", "AoC2\AoC2\AoC2.csproj", "{AD8879E5-3089-4B71-8362-3FC26E23242A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AoC2Test", "AoC2\AoC2Test\AoC2Test.csproj", "{66C828CF-6E1D-4C99-A967-216911D0FF0D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -28,9 +30,14 @@ Global {AD8879E5-3089-4B71-8362-3FC26E23242A}.Debug|Any CPU.Build.0 = Debug|Any CPU {AD8879E5-3089-4B71-8362-3FC26E23242A}.Release|Any CPU.ActiveCfg = Release|Any CPU {AD8879E5-3089-4B71-8362-3FC26E23242A}.Release|Any CPU.Build.0 = Release|Any CPU + {66C828CF-6E1D-4C99-A967-216911D0FF0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {66C828CF-6E1D-4C99-A967-216911D0FF0D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {66C828CF-6E1D-4C99-A967-216911D0FF0D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {66C828CF-6E1D-4C99-A967-216911D0FF0D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {06B4648E-79A0-4C94-926D-CEBF46E1155B} = {A56EF563-B7A2-484C-999F-BB48F1FFCCAF} {AD8879E5-3089-4B71-8362-3FC26E23242A} = {79F9A7C9-3CEE-4A0C-8F55-4E8A0D44AF79} + {66C828CF-6E1D-4C99-A967-216911D0FF0D} = {79F9A7C9-3CEE-4A0C-8F55-4E8A0D44AF79} EndGlobalSection EndGlobal diff --git a/AoC2/AoC2.sln b/AoC2/AoC2.sln index e0c823b8bbcd42a94c0a516b0f61cda2f4461a59..a95423d81a9cd8da5783cd7f6ce8910476908ad0 100644 --- a/AoC2/AoC2.sln +++ b/AoC2/AoC2.sln @@ -2,6 +2,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AoC2", "AoC2\AoC2.csproj", "{4DF86EDF-0EC4-4A64-A010-80D16BA62089}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AoC2Test", "AoC2Test\AoC2Test.csproj", "{DE0D9B80-3857-4F38-A9AD-4168CD633F6F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -12,5 +14,9 @@ Global {4DF86EDF-0EC4-4A64-A010-80D16BA62089}.Debug|Any CPU.Build.0 = Debug|Any CPU {4DF86EDF-0EC4-4A64-A010-80D16BA62089}.Release|Any CPU.ActiveCfg = Release|Any CPU {4DF86EDF-0EC4-4A64-A010-80D16BA62089}.Release|Any CPU.Build.0 = Release|Any CPU + {DE0D9B80-3857-4F38-A9AD-4168CD633F6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DE0D9B80-3857-4F38-A9AD-4168CD633F6F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DE0D9B80-3857-4F38-A9AD-4168CD633F6F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DE0D9B80-3857-4F38-A9AD-4168CD633F6F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/AoC2/AoC2/Program.cs b/AoC2/AoC2/Program.cs index 33e352478852b4c74d090bfc977f6343a0588352..c7da39adb21e6085560225fa04101d49e6388a46 100644 --- a/AoC2/AoC2/Program.cs +++ b/AoC2/AoC2/Program.cs @@ -1,8 +1,8 @@ namespace AoC2; -internal readonly record struct Bag(int Red, int Green, int Blue); +public readonly record struct Bag(int Red, int Green, int Blue); -internal class Game +public class Game { // Max amount for each private readonly int _red; @@ -12,7 +12,7 @@ internal class Game public int Id { get; } public int PowerOfCubes => _red * _green * _blue; - internal Game(string line) + public Game(string line) { Id = int.Parse(line.Split(":")[0].Split(" ")[1]); @@ -32,7 +32,7 @@ internal class Game public bool PossibleWithBag(in Bag bag) => bag.Red >= _red && bag.Green >= _green && bag.Blue >= _blue; } -internal static class Program +public static class Program { public static void Main() { diff --git a/AoC2/AoC2Test/AoC2Test.csproj b/AoC2/AoC2Test/AoC2Test.csproj new file mode 100644 index 0000000000000000000000000000000000000000..24f9b22e80454ec4816f302d5292d48bd7a6d654 --- /dev/null +++ b/AoC2/AoC2Test/AoC2Test.csproj @@ -0,0 +1,27 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <TargetFramework>net6.0</TargetFramework> + <Nullable>enable</Nullable> + + <IsPackable>false</IsPackable> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0"/> + <PackageReference Include="xunit" Version="2.4.1"/> + <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> + <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> + <PrivateAssets>all</PrivateAssets> + </PackageReference> + <PackageReference Include="coverlet.collector" Version="3.1.0"> + <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> + <PrivateAssets>all</PrivateAssets> + </PackageReference> + </ItemGroup> + + <ItemGroup> + <ProjectReference Include="..\AoC2\AoC2.csproj" /> + </ItemGroup> + +</Project> diff --git a/AoC2/AoC2Test/Tests.cs b/AoC2/AoC2Test/Tests.cs new file mode 100644 index 0000000000000000000000000000000000000000..5941e2f00e834a98bc7c298f9f7f122708c79936 --- /dev/null +++ b/AoC2/AoC2Test/Tests.cs @@ -0,0 +1,43 @@ +using System.Collections.Generic; +using System.Linq; +using AoC2; +using Xunit; + +namespace AoC2Test; + +// Tests should not be written like this... Maybe next day +// For now, good enough to test CI +public class Tests +{ + private const string input = @"Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green +Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue +Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red +Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red +Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green"; + + private readonly Bag _bag; + private readonly IEnumerable<Game> _games; + + public Tests() + { + _bag = new Bag(12, 13, 14); + _games = input.Split("\n") + .Select(line => new Game(line)); + } + + [Fact] + public void Day2Part1_Examples_Pass() + { + var sum = _games.Where(game => game.PossibleWithBag(_bag)) + .Sum(game => game.Id); + + Assert.Equal(8, sum); + } + + [Fact] + public void Day2Part2_Examples_Pass() + { + long power = _games.Sum(game => game.PowerOfCubes); + Assert.Equal(2286, power); + } +} \ No newline at end of file diff --git a/AoC2/AoC2Test/input.txt b/AoC2/AoC2Test/input.txt new file mode 100644 index 0000000000000000000000000000000000000000..1cd7d3319fcdcb73311d80ce1bf26275b5159d55 --- /dev/null +++ b/AoC2/AoC2Test/input.txt @@ -0,0 +1,5 @@ +Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green +Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue +Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red +Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red +Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green \ No newline at end of file