Code cleanup
This commit is contained in:
33
.editorconfig
Normal file
33
.editorconfig
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
|
||||||
|
[*]
|
||||||
|
|
||||||
|
# Microsoft .NET properties
|
||||||
|
csharp_indent_braces = false
|
||||||
|
csharp_new_line_before_members_in_object_initializers = false
|
||||||
|
csharp_new_line_before_open_brace = accessors,anonymous_methods,control_blocks,events,indexers,lambdas,local_functions,methods,properties,types
|
||||||
|
csharp_preferred_modifier_order = private, public, protected, internal, file, new, readonly, abstract, virtual, sealed, static, override, extern, unsafe, volatile, async, required:suggestion
|
||||||
|
csharp_prefer_braces = true:none
|
||||||
|
csharp_preserve_single_line_blocks = true
|
||||||
|
csharp_style_var_elsewhere = false:suggestion
|
||||||
|
csharp_style_var_for_built_in_types = false:suggestion
|
||||||
|
csharp_style_var_when_type_is_apparent = false:suggestion
|
||||||
|
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:none
|
||||||
|
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:none
|
||||||
|
dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:none
|
||||||
|
|
||||||
|
# ReSharper properties
|
||||||
|
resharper_accessor_owner_body = accessors_with_block_body
|
||||||
|
resharper_blank_lines_after_block_statements = 0
|
||||||
|
resharper_csharp_max_line_length = 195
|
||||||
|
resharper_csharp_remove_blank_lines_near_braces_in_code = false
|
||||||
|
resharper_instance_members_qualify_declared_in = base_class
|
||||||
|
resharper_keep_existing_declaration_block_arrangement = false
|
||||||
|
resharper_max_array_initializer_elements_on_line = 2
|
||||||
|
resharper_max_initializer_elements_on_line = 2
|
||||||
|
resharper_parentheses_non_obvious_operations = none, multiplicative, additive, arithmetic, shift, bitwise_and, bitwise_exclusive_or, bitwise_inclusive_or, bitwise
|
||||||
|
resharper_parentheses_redundancy_style = remove
|
||||||
|
resharper_parentheses_same_type_operations = true
|
||||||
|
resharper_place_simple_embedded_statement_on_same_line = true
|
||||||
|
resharper_trailing_comma_in_multiline_lists = true
|
||||||
|
resharper_wrap_array_initializer_style = chop_always
|
||||||
|
resharper_wrap_object_and_collection_initializer_style = chop_always
|
||||||
5
.idea/.idea.AdventOfCode/.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
.idea/.idea.AdventOfCode/.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<state>
|
||||||
|
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||||
|
</state>
|
||||||
|
</component>
|
||||||
7
AdventOfCode.sln.DotSettings
Normal file
7
AdventOfCode.sln.DotSettings
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BFS/@EntryIndexedValue">BFS</s:String>
|
||||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ID/@EntryIndexedValue">ID</s:String>
|
||||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=VM/@EntryIndexedValue">VM</s:String>
|
||||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=VX/@EntryIndexedValue">VX</s:String>
|
||||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=VY/@EntryIndexedValue">VY</s:String>
|
||||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypesAndNamespaces/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /></s:String></wpf:ResourceDictionary>
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2017.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2017.Tests
|
|
||||||
{
|
|
||||||
public class Day01_Tests
|
public class Day01_Tests
|
||||||
{
|
{
|
||||||
#region ResolvePart1
|
#region ResolvePart1
|
||||||
@@ -9,9 +7,9 @@ namespace AdventOfCode2017.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test1()
|
public void ResolvePart1__Test1()
|
||||||
{
|
{
|
||||||
Day01 day01 = new Day01();
|
Day01 day01 = new();
|
||||||
|
|
||||||
string result = day01.ResolvePart1(new string[] { "1122", });
|
string result = day01.ResolvePart1(new[] { "1122", });
|
||||||
|
|
||||||
Assert.Equal("3", result);
|
Assert.Equal("3", result);
|
||||||
}
|
}
|
||||||
@@ -19,9 +17,9 @@ namespace AdventOfCode2017.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test2()
|
public void ResolvePart1__Test2()
|
||||||
{
|
{
|
||||||
Day01 day01 = new Day01();
|
Day01 day01 = new();
|
||||||
|
|
||||||
string result = day01.ResolvePart1(new string[] { "1111", });
|
string result = day01.ResolvePart1(new[] { "1111", });
|
||||||
|
|
||||||
Assert.Equal("4", result);
|
Assert.Equal("4", result);
|
||||||
}
|
}
|
||||||
@@ -29,9 +27,9 @@ namespace AdventOfCode2017.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test3()
|
public void ResolvePart1__Test3()
|
||||||
{
|
{
|
||||||
Day01 day01 = new Day01();
|
Day01 day01 = new();
|
||||||
|
|
||||||
string result = day01.ResolvePart1(new string[] { "1234", });
|
string result = day01.ResolvePart1(new[] { "1234", });
|
||||||
|
|
||||||
Assert.Equal("0", result);
|
Assert.Equal("0", result);
|
||||||
}
|
}
|
||||||
@@ -39,9 +37,9 @@ namespace AdventOfCode2017.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test4()
|
public void ResolvePart1__Test4()
|
||||||
{
|
{
|
||||||
Day01 day01 = new Day01();
|
Day01 day01 = new();
|
||||||
|
|
||||||
string result = day01.ResolvePart1(new string[] { "91212129", });
|
string result = day01.ResolvePart1(new[] { "91212129", });
|
||||||
|
|
||||||
Assert.Equal("9", result);
|
Assert.Equal("9", result);
|
||||||
}
|
}
|
||||||
@@ -53,9 +51,9 @@ namespace AdventOfCode2017.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test1()
|
public void ResolvePart2__Test1()
|
||||||
{
|
{
|
||||||
Day01 day01 = new Day01();
|
Day01 day01 = new();
|
||||||
|
|
||||||
string result = day01.ResolvePart2(new string[] { "1212", });
|
string result = day01.ResolvePart2(new[] { "1212", });
|
||||||
|
|
||||||
Assert.Equal("6", result);
|
Assert.Equal("6", result);
|
||||||
}
|
}
|
||||||
@@ -63,9 +61,9 @@ namespace AdventOfCode2017.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test2()
|
public void ResolvePart2__Test2()
|
||||||
{
|
{
|
||||||
Day01 day01 = new Day01();
|
Day01 day01 = new();
|
||||||
|
|
||||||
string result = day01.ResolvePart2(new string[] { "1221", });
|
string result = day01.ResolvePart2(new[] { "1221", });
|
||||||
|
|
||||||
Assert.Equal("0", result);
|
Assert.Equal("0", result);
|
||||||
}
|
}
|
||||||
@@ -73,9 +71,9 @@ namespace AdventOfCode2017.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test3()
|
public void ResolvePart2__Test3()
|
||||||
{
|
{
|
||||||
Day01 day01 = new Day01();
|
Day01 day01 = new();
|
||||||
|
|
||||||
string result = day01.ResolvePart2(new string[] { "123425", });
|
string result = day01.ResolvePart2(new[] { "123425", });
|
||||||
|
|
||||||
Assert.Equal("4", result);
|
Assert.Equal("4", result);
|
||||||
}
|
}
|
||||||
@@ -83,9 +81,9 @@ namespace AdventOfCode2017.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test4()
|
public void ResolvePart2__Test4()
|
||||||
{
|
{
|
||||||
Day01 day01 = new Day01();
|
Day01 day01 = new();
|
||||||
|
|
||||||
string result = day01.ResolvePart2(new string[] { "123123", });
|
string result = day01.ResolvePart2(new[] { "123123", });
|
||||||
|
|
||||||
Assert.Equal("12", result);
|
Assert.Equal("12", result);
|
||||||
}
|
}
|
||||||
@@ -93,13 +91,12 @@ namespace AdventOfCode2017.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test5()
|
public void ResolvePart2__Test5()
|
||||||
{
|
{
|
||||||
Day01 day01 = new Day01();
|
Day01 day01 = new();
|
||||||
|
|
||||||
string result = day01.ResolvePart2(new string[] { "12131415", });
|
string result = day01.ResolvePart2(new[] { "12131415", });
|
||||||
|
|
||||||
Assert.Equal("4", result);
|
Assert.Equal("4", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion ResolvePart2
|
#endregion ResolvePart2
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,15 +1,13 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2017.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2017.Tests
|
|
||||||
{
|
|
||||||
public class Day02_Tests
|
public class Day02_Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test()
|
public void ResolvePart1__Test()
|
||||||
{
|
{
|
||||||
Day02 day02 = new Day02();
|
Day02 day02 = new();
|
||||||
|
|
||||||
string result = day02.ResolvePart1(new string[] {
|
string result = day02.ResolvePart1(new[] {
|
||||||
"5 1 9 5",
|
"5 1 9 5",
|
||||||
"7 5 3",
|
"7 5 3",
|
||||||
"2 4 6 8",
|
"2 4 6 8",
|
||||||
@@ -21,9 +19,9 @@ namespace AdventOfCode2017.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test()
|
public void ResolvePart2__Test()
|
||||||
{
|
{
|
||||||
Day02 day02 = new Day02();
|
Day02 day02 = new();
|
||||||
|
|
||||||
string result = day02.ResolvePart2(new string[] {
|
string result = day02.ResolvePart2(new[] {
|
||||||
"5 9 2 8",
|
"5 9 2 8",
|
||||||
"9 4 7 3",
|
"9 4 7 3",
|
||||||
"3 8 6 5",
|
"3 8 6 5",
|
||||||
@@ -32,4 +30,3 @@ namespace AdventOfCode2017.Tests
|
|||||||
Assert.Equal("9", result);
|
Assert.Equal("9", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
1
AdventOfCode2017.Tests/Usings.cs
Normal file
1
AdventOfCode2017.Tests/Usings.cs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
global using Xunit;
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
namespace AdventOfCode2017
|
namespace AdventOfCode2017;
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
--- Day 1: Inverse Captcha ---
|
--- Day 1: Inverse Captcha ---
|
||||||
@@ -77,4 +76,3 @@
|
|||||||
return value.ToString();
|
return value.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AdventOfCode2017
|
namespace AdventOfCode2017;
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
--- Day 2: Corruption Checksum ---
|
--- Day 2: Corruption Checksum ---
|
||||||
@@ -60,7 +56,7 @@ namespace AdventOfCode2017
|
|||||||
foreach(string input in inputs)
|
foreach(string input in inputs)
|
||||||
{
|
{
|
||||||
int[] row = input
|
int[] row = input
|
||||||
.Split(new string[] { " ", " " }, StringSplitOptions.RemoveEmptyEntries)
|
.Split(new[] { " ", " " }, StringSplitOptions.RemoveEmptyEntries)
|
||||||
.Select(cell => Convert.ToInt32(cell))
|
.Select(cell => Convert.ToInt32(cell))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
int max = row.Max();
|
int max = row.Max();
|
||||||
@@ -76,7 +72,7 @@ namespace AdventOfCode2017
|
|||||||
foreach (string input in inputs)
|
foreach (string input in inputs)
|
||||||
{
|
{
|
||||||
int[] row = input
|
int[] row = input
|
||||||
.Split(new string[] { " ", " " }, StringSplitOptions.RemoveEmptyEntries)
|
.Split(new[] { " ", " " }, StringSplitOptions.RemoveEmptyEntries)
|
||||||
.Select(cell => Convert.ToInt32(cell))
|
.Select(cell => Convert.ToInt32(cell))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
@@ -96,4 +92,3 @@ namespace AdventOfCode2017
|
|||||||
return checksum.ToString();
|
return checksum.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
using System;
|
namespace AdventOfCode2017;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AdventOfCode2017
|
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
--- Day 3: Spiral Memory ---
|
--- Day 3: Spiral Memory ---
|
||||||
@@ -44,4 +38,3 @@ namespace AdventOfCode2017
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
namespace AdventOfCode2017
|
namespace AdventOfCode2017;
|
||||||
{
|
|
||||||
public interface IDay
|
public interface IDay
|
||||||
{
|
{
|
||||||
string ResolvePart1(string[] inputs);
|
string ResolvePart1(string[] inputs);
|
||||||
string ResolvePart2(string[] inputs);
|
string ResolvePart2(string[] inputs);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace AdventOfCode2017
|
namespace AdventOfCode2017;
|
||||||
{
|
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
private static void Main(string[] args)
|
private static void Main()
|
||||||
{
|
{
|
||||||
int currentDayNumber = 3;
|
int currentDayNumber = 3;
|
||||||
IDay currentDay = null;
|
IDay currentDay = null;
|
||||||
@@ -17,7 +17,7 @@ namespace AdventOfCode2017
|
|||||||
case 3: currentDay = new Day03(); break;
|
case 3: currentDay = new Day03(); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] linesDay = File.ReadAllLines(string.Format("inputs/Day{0:00}.txt", currentDayNumber));
|
string[] linesDay = File.ReadAllLines($"inputs/Day{currentDayNumber:00}.txt");
|
||||||
string resultPart1 = currentDay.ResolvePart1(linesDay);
|
string resultPart1 = currentDay.ResolvePart1(linesDay);
|
||||||
Console.WriteLine("Day{1:00} Result Part1: {0}", resultPart1, currentDayNumber);
|
Console.WriteLine("Day{1:00} Result Part1: {0}", resultPart1, currentDayNumber);
|
||||||
string resultPart2 = currentDay.ResolvePart2(linesDay);
|
string resultPart2 = currentDay.ResolvePart2(linesDay);
|
||||||
@@ -26,4 +26,3 @@ namespace AdventOfCode2017
|
|||||||
Console.Read();
|
Console.Read();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2018.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2018.Tests
|
|
||||||
{
|
|
||||||
public class ChronoLicenceNode_Tests
|
public class ChronoLicenceNode_Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void BuildFromIntStream__Test()
|
public void BuildFromIntStream__Test()
|
||||||
{
|
{
|
||||||
Day08 day = new Day08();
|
IntStream values = new("2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2");
|
||||||
|
|
||||||
IntStream values = new IntStream("2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2");
|
|
||||||
ChronoLicenceNode result = ChronoLicenceNode.BuildFromIntStream(values);
|
ChronoLicenceNode result = ChronoLicenceNode.BuildFromIntStream(values);
|
||||||
|
|
||||||
Assert.Equal(2, result.Childs.Count);
|
Assert.Equal(2, result.Childs.Count);
|
||||||
@@ -18,19 +14,18 @@ namespace AdventOfCode2018.Tests
|
|||||||
Assert.Equal(1, result.Metadata[1]);
|
Assert.Equal(1, result.Metadata[1]);
|
||||||
Assert.Equal(2, result.Metadata[2]);
|
Assert.Equal(2, result.Metadata[2]);
|
||||||
|
|
||||||
Assert.Equal(0, result.Childs[0].Childs.Count);
|
Assert.Empty(result.Childs[0].Childs);
|
||||||
Assert.Equal(3, result.Childs[0].Metadata.Count);
|
Assert.Equal(3, result.Childs[0].Metadata.Count);
|
||||||
Assert.Equal(10, result.Childs[0].Metadata[0]);
|
Assert.Equal(10, result.Childs[0].Metadata[0]);
|
||||||
Assert.Equal(11, result.Childs[0].Metadata[1]);
|
Assert.Equal(11, result.Childs[0].Metadata[1]);
|
||||||
Assert.Equal(12, result.Childs[0].Metadata[2]);
|
Assert.Equal(12, result.Childs[0].Metadata[2]);
|
||||||
|
|
||||||
Assert.Equal(1, result.Childs[1].Childs.Count);
|
Assert.Single(result.Childs[1].Childs);
|
||||||
Assert.Equal(1, result.Childs[1].Metadata.Count);
|
Assert.Single(result.Childs[1].Metadata);
|
||||||
Assert.Equal(2, result.Childs[1].Metadata[0]);
|
Assert.Equal(2, result.Childs[1].Metadata[0]);
|
||||||
|
|
||||||
Assert.Equal(0, result.Childs[1].Childs[0].Childs.Count);
|
Assert.Empty(result.Childs[1].Childs[0].Childs);
|
||||||
Assert.Equal(1, result.Childs[1].Childs[0].Metadata.Count);
|
Assert.Single(result.Childs[1].Childs[0].Metadata);
|
||||||
Assert.Equal(99, result.Childs[1].Childs[0].Metadata[0]);
|
Assert.Equal(99, result.Childs[1].Childs[0].Metadata[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2018.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2018.Tests
|
|
||||||
{
|
|
||||||
public class ChronoPoint_Tests
|
public class ChronoPoint_Tests
|
||||||
{
|
{
|
||||||
#region FromString
|
#region FromString
|
||||||
@@ -61,4 +59,3 @@ namespace AdventOfCode2018.Tests
|
|||||||
|
|
||||||
#endregion ManhattanDistance
|
#endregion ManhattanDistance
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2018.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2018.Tests
|
|
||||||
{
|
|
||||||
public class Claim_Tests
|
public class Claim_Tests
|
||||||
{
|
{
|
||||||
#region FromString
|
#region FromString
|
||||||
@@ -66,7 +64,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
|
|
||||||
bool result = Day03.Claim.Overlaps(claim1, claim2);
|
bool result = Day03.Claim.Overlaps(claim1, claim2);
|
||||||
|
|
||||||
Assert.Equal(false, result);
|
Assert.False(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -77,7 +75,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
|
|
||||||
bool result = Day03.Claim.Overlaps(claim1, claim2);
|
bool result = Day03.Claim.Overlaps(claim1, claim2);
|
||||||
|
|
||||||
Assert.Equal(false, result);
|
Assert.False(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -88,9 +86,8 @@ namespace AdventOfCode2018.Tests
|
|||||||
|
|
||||||
bool result = Day03.Claim.Overlaps(claim1, claim2);
|
bool result = Day03.Claim.Overlaps(claim1, claim2);
|
||||||
|
|
||||||
Assert.Equal(true, result);
|
Assert.True(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Overlaps
|
#endregion Overlaps
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2018.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2018.Tests
|
|
||||||
{
|
|
||||||
public class Day01_Tests
|
public class Day01_Tests
|
||||||
{
|
{
|
||||||
#region ResolvePart1
|
#region ResolvePart1
|
||||||
@@ -9,9 +7,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test1()
|
public void ResolvePart1__Test1()
|
||||||
{
|
{
|
||||||
Day01 day01 = new Day01();
|
Day01 day01 = new();
|
||||||
|
|
||||||
string result = day01.ResolvePart1(new string[] { "+1", "-2", "+3", "+1", });
|
string result = day01.ResolvePart1(new[] { "+1", "-2", "+3", "+1", });
|
||||||
|
|
||||||
Assert.Equal("3", result);
|
Assert.Equal("3", result);
|
||||||
}
|
}
|
||||||
@@ -19,9 +17,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test2()
|
public void ResolvePart1__Test2()
|
||||||
{
|
{
|
||||||
Day01 day01 = new Day01();
|
Day01 day01 = new();
|
||||||
|
|
||||||
string result = day01.ResolvePart1(new string[] { "+1", "+1", "+1", });
|
string result = day01.ResolvePart1(new[] { "+1", "+1", "+1", });
|
||||||
|
|
||||||
Assert.Equal("3", result);
|
Assert.Equal("3", result);
|
||||||
}
|
}
|
||||||
@@ -29,9 +27,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test3()
|
public void ResolvePart1__Test3()
|
||||||
{
|
{
|
||||||
Day01 day01 = new Day01();
|
Day01 day01 = new();
|
||||||
|
|
||||||
string result = day01.ResolvePart1(new string[] { "+1", "+1", "-2", });
|
string result = day01.ResolvePart1(new[] { "+1", "+1", "-2", });
|
||||||
|
|
||||||
Assert.Equal("0", result);
|
Assert.Equal("0", result);
|
||||||
}
|
}
|
||||||
@@ -39,9 +37,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test4()
|
public void ResolvePart1__Test4()
|
||||||
{
|
{
|
||||||
Day01 day01 = new Day01();
|
Day01 day01 = new();
|
||||||
|
|
||||||
string result = day01.ResolvePart1(new string[] { "-1", "-2", "-3", });
|
string result = day01.ResolvePart1(new[] { "-1", "-2", "-3", });
|
||||||
|
|
||||||
Assert.Equal("-6", result);
|
Assert.Equal("-6", result);
|
||||||
}
|
}
|
||||||
@@ -53,9 +51,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test1()
|
public void ResolvePart2__Test1()
|
||||||
{
|
{
|
||||||
Day01 day01 = new Day01();
|
Day01 day01 = new();
|
||||||
|
|
||||||
string result = day01.ResolvePart2(new string[] { "+1", "-2", "+3", "+1", });
|
string result = day01.ResolvePart2(new[] { "+1", "-2", "+3", "+1", });
|
||||||
|
|
||||||
Assert.Equal("2", result);
|
Assert.Equal("2", result);
|
||||||
}
|
}
|
||||||
@@ -63,9 +61,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test2()
|
public void ResolvePart2__Test2()
|
||||||
{
|
{
|
||||||
Day01 day01 = new Day01();
|
Day01 day01 = new();
|
||||||
|
|
||||||
string result = day01.ResolvePart2(new string[] { "+1", "-1", });
|
string result = day01.ResolvePart2(new[] { "+1", "-1", });
|
||||||
|
|
||||||
Assert.Equal("0", result);
|
Assert.Equal("0", result);
|
||||||
}
|
}
|
||||||
@@ -73,9 +71,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test3()
|
public void ResolvePart2__Test3()
|
||||||
{
|
{
|
||||||
Day01 day01 = new Day01();
|
Day01 day01 = new();
|
||||||
|
|
||||||
string result = day01.ResolvePart2(new string[] { "+3", "+3", "+4", "-2", "-4", });
|
string result = day01.ResolvePart2(new[] { "+3", "+3", "+4", "-2", "-4", });
|
||||||
|
|
||||||
Assert.Equal("10", result);
|
Assert.Equal("10", result);
|
||||||
}
|
}
|
||||||
@@ -83,9 +81,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test4()
|
public void ResolvePart2__Test4()
|
||||||
{
|
{
|
||||||
Day01 day01 = new Day01();
|
Day01 day01 = new();
|
||||||
|
|
||||||
string result = day01.ResolvePart2(new string[] { "-6", "+3", "+8", "+5", "-6", });
|
string result = day01.ResolvePart2(new[] { "-6", "+3", "+8", "+5", "-6", });
|
||||||
|
|
||||||
Assert.Equal("5", result);
|
Assert.Equal("5", result);
|
||||||
}
|
}
|
||||||
@@ -93,13 +91,12 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test5()
|
public void ResolvePart2__Test5()
|
||||||
{
|
{
|
||||||
Day01 day01 = new Day01();
|
Day01 day01 = new();
|
||||||
|
|
||||||
string result = day01.ResolvePart2(new string[] { "+7", "+7", "-2", "-7", "-4", });
|
string result = day01.ResolvePart2(new[] { "+7", "+7", "-2", "-7", "-4", });
|
||||||
|
|
||||||
Assert.Equal("14", result);
|
Assert.Equal("14", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion ResolvePart2
|
#endregion ResolvePart2
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,15 +1,13 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2018.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2018.Tests
|
|
||||||
{
|
|
||||||
public class Day02_Tests
|
public class Day02_Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test1()
|
public void ResolvePart1__Test1()
|
||||||
{
|
{
|
||||||
Day02 day02 = new Day02();
|
Day02 day02 = new();
|
||||||
|
|
||||||
string result = day02.ResolvePart1(new string[] {
|
string result = day02.ResolvePart1(new[] {
|
||||||
"abcdef",
|
"abcdef",
|
||||||
"bababc",
|
"bababc",
|
||||||
"abbcde",
|
"abbcde",
|
||||||
@@ -25,9 +23,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test()
|
public void ResolvePart2__Test()
|
||||||
{
|
{
|
||||||
Day02 day02 = new Day02();
|
Day02 day02 = new();
|
||||||
|
|
||||||
string result = day02.ResolvePart2(new string[] {
|
string result = day02.ResolvePart2(new[] {
|
||||||
"abcde",
|
"abcde",
|
||||||
"fghij",
|
"fghij",
|
||||||
"klmno",
|
"klmno",
|
||||||
@@ -40,4 +38,3 @@ namespace AdventOfCode2018.Tests
|
|||||||
Assert.Equal("fgij", result);
|
Assert.Equal("fgij", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,15 +1,13 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2018.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2018.Tests
|
|
||||||
{
|
|
||||||
public class Day03_Tests
|
public class Day03_Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test()
|
public void ResolvePart1__Test()
|
||||||
{
|
{
|
||||||
Day03 day03 = new Day03();
|
Day03 day03 = new();
|
||||||
|
|
||||||
string result = day03.ResolvePart1(new string[] {
|
string result = day03.ResolvePart1(new[] {
|
||||||
"#1 @ 1,3: 4x4",
|
"#1 @ 1,3: 4x4",
|
||||||
"#2 @ 3,1: 4x4",
|
"#2 @ 3,1: 4x4",
|
||||||
"#3 @ 5,5: 2x2",
|
"#3 @ 5,5: 2x2",
|
||||||
@@ -21,9 +19,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test()
|
public void ResolvePart2__Test()
|
||||||
{
|
{
|
||||||
Day03 day03 = new Day03();
|
Day03 day03 = new();
|
||||||
|
|
||||||
string result = day03.ResolvePart2(new string[] {
|
string result = day03.ResolvePart2(new[] {
|
||||||
"#1 @ 1,3: 4x4",
|
"#1 @ 1,3: 4x4",
|
||||||
"#2 @ 3,1: 4x4",
|
"#2 @ 3,1: 4x4",
|
||||||
"#3 @ 5,5: 2x2",
|
"#3 @ 5,5: 2x2",
|
||||||
@@ -32,4 +30,3 @@ namespace AdventOfCode2018.Tests
|
|||||||
Assert.Equal("3", result);
|
Assert.Equal("3", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,15 +1,13 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2018.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2018.Tests
|
|
||||||
{
|
|
||||||
public class Day04_Tests
|
public class Day04_Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__BaseStatement()
|
public void ResolvePart1__BaseStatement()
|
||||||
{
|
{
|
||||||
Day04 day04 = new Day04();
|
Day04 day04 = new();
|
||||||
|
|
||||||
string result = day04.ResolvePart1(new string[] {
|
string result = day04.ResolvePart1(new[] {
|
||||||
"[1518-11-01 00:00] Guard #10 begins shift",
|
"[1518-11-01 00:00] Guard #10 begins shift",
|
||||||
"[1518-11-01 00:05] falls asleep",
|
"[1518-11-01 00:05] falls asleep",
|
||||||
"[1518-11-01 00:25] wakes up",
|
"[1518-11-01 00:25] wakes up",
|
||||||
@@ -35,9 +33,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__BaseStatementUnsorted()
|
public void ResolvePart1__BaseStatementUnsorted()
|
||||||
{
|
{
|
||||||
Day04 day04 = new Day04();
|
Day04 day04 = new();
|
||||||
|
|
||||||
string result = day04.ResolvePart1(new string[] {
|
string result = day04.ResolvePart1(new[] {
|
||||||
"[1518-11-04 00:36] falls asleep",
|
"[1518-11-04 00:36] falls asleep",
|
||||||
"[1518-11-04 00:46] wakes up",
|
"[1518-11-04 00:46] wakes up",
|
||||||
"[1518-11-05 00:03] Guard #99 begins shift",
|
"[1518-11-05 00:03] Guard #99 begins shift",
|
||||||
@@ -64,9 +62,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__BaseStatement()
|
public void ResolvePart2__BaseStatement()
|
||||||
{
|
{
|
||||||
Day04 day04 = new Day04();
|
Day04 day04 = new();
|
||||||
|
|
||||||
string result = day04.ResolvePart2(new string[] {
|
string result = day04.ResolvePart2(new[] {
|
||||||
"[1518-11-01 00:00] Guard #10 begins shift",
|
"[1518-11-01 00:00] Guard #10 begins shift",
|
||||||
"[1518-11-01 00:05] falls asleep",
|
"[1518-11-01 00:05] falls asleep",
|
||||||
"[1518-11-01 00:25] wakes up",
|
"[1518-11-01 00:25] wakes up",
|
||||||
@@ -92,9 +90,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__BaseStatementUnsorted()
|
public void ResolvePart2__BaseStatementUnsorted()
|
||||||
{
|
{
|
||||||
Day04 day04 = new Day04();
|
Day04 day04 = new();
|
||||||
|
|
||||||
string result = day04.ResolvePart2(new string[] {
|
string result = day04.ResolvePart2(new[] {
|
||||||
"[1518-11-04 00:36] falls asleep",
|
"[1518-11-04 00:36] falls asleep",
|
||||||
"[1518-11-04 00:46] wakes up",
|
"[1518-11-04 00:46] wakes up",
|
||||||
"[1518-11-05 00:03] Guard #99 begins shift",
|
"[1518-11-05 00:03] Guard #99 begins shift",
|
||||||
@@ -117,4 +115,3 @@ namespace AdventOfCode2018.Tests
|
|||||||
Assert.Equal("4455", result);
|
Assert.Equal("4455", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,15 +1,13 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2018.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2018.Tests
|
|
||||||
{
|
|
||||||
public class Day05_Tests
|
public class Day05_Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test()
|
public void ResolvePart1__Test()
|
||||||
{
|
{
|
||||||
Day05 day05 = new Day05();
|
Day05 day05 = new();
|
||||||
|
|
||||||
string result = day05.ResolvePart1(new string[] { "dabAcCaCBAcCcaDA" });
|
string result = day05.ResolvePart1(new[] { "dabAcCaCBAcCcaDA" });
|
||||||
|
|
||||||
Assert.Equal("10", result);
|
Assert.Equal("10", result);
|
||||||
}
|
}
|
||||||
@@ -17,9 +15,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test()
|
public void ResolvePart2__Test()
|
||||||
{
|
{
|
||||||
Day05 day05 = new Day05();
|
Day05 day05 = new();
|
||||||
|
|
||||||
string result = day05.ResolvePart2(new string[] { "dabAcCaCBAcCcaDA" });
|
string result = day05.ResolvePart2(new[] { "dabAcCaCBAcCcaDA" });
|
||||||
|
|
||||||
Assert.Equal("4", result);
|
Assert.Equal("4", result);
|
||||||
}
|
}
|
||||||
@@ -29,7 +27,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ReducePolymer__Remove_cC()
|
public void ReducePolymer__Remove_cC()
|
||||||
{
|
{
|
||||||
Day05 day05 = new Day05();
|
Day05 day05 = new();
|
||||||
|
|
||||||
string result = day05.ReducePolymer("dabAcCaCBA");
|
string result = day05.ReducePolymer("dabAcCaCBA");
|
||||||
|
|
||||||
@@ -39,7 +37,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ReducePolymer__Remove_cC_AtEnd()
|
public void ReducePolymer__Remove_cC_AtEnd()
|
||||||
{
|
{
|
||||||
Day05 day05 = new Day05();
|
Day05 day05 = new();
|
||||||
|
|
||||||
string result = day05.ReducePolymer("dabAcC");
|
string result = day05.ReducePolymer("dabAcC");
|
||||||
|
|
||||||
@@ -49,7 +47,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ReducePolymer__Remove_Only_cC()
|
public void ReducePolymer__Remove_Only_cC()
|
||||||
{
|
{
|
||||||
Day05 day05 = new Day05();
|
Day05 day05 = new();
|
||||||
|
|
||||||
string result = day05.ReducePolymer("cC");
|
string result = day05.ReducePolymer("cC");
|
||||||
|
|
||||||
@@ -59,7 +57,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ReducePolymer__Remove_cC_AtStart()
|
public void ReducePolymer__Remove_cC_AtStart()
|
||||||
{
|
{
|
||||||
Day05 day05 = new Day05();
|
Day05 day05 = new();
|
||||||
|
|
||||||
string result = day05.ReducePolymer("cCAAAA");
|
string result = day05.ReducePolymer("cCAAAA");
|
||||||
|
|
||||||
@@ -69,7 +67,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ReducePolymer__Remove_Aa()
|
public void ReducePolymer__Remove_Aa()
|
||||||
{
|
{
|
||||||
Day05 day05 = new Day05();
|
Day05 day05 = new();
|
||||||
|
|
||||||
string result = day05.ReducePolymer("dabAaCBA");
|
string result = day05.ReducePolymer("dabAaCBA");
|
||||||
|
|
||||||
@@ -79,7 +77,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ReducePolymer__Remove_cCc()
|
public void ReducePolymer__Remove_cCc()
|
||||||
{
|
{
|
||||||
Day05 day05 = new Day05();
|
Day05 day05 = new();
|
||||||
|
|
||||||
string result = day05.ReducePolymer("dabCBAcCcaDA");
|
string result = day05.ReducePolymer("dabCBAcCcaDA");
|
||||||
|
|
||||||
@@ -89,7 +87,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ReducePolymer__Irreductible()
|
public void ReducePolymer__Irreductible()
|
||||||
{
|
{
|
||||||
Day05 day05 = new Day05();
|
Day05 day05 = new();
|
||||||
|
|
||||||
string result = day05.ReducePolymer("dabCBAcaDA");
|
string result = day05.ReducePolymer("dabCBAcaDA");
|
||||||
|
|
||||||
@@ -103,7 +101,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void FullyReducePolymer__Test()
|
public void FullyReducePolymer__Test()
|
||||||
{
|
{
|
||||||
Day05 day05 = new Day05();
|
Day05 day05 = new();
|
||||||
|
|
||||||
string result = day05.FullyReducePolymer("dabAcCaCBAcCcaDA");
|
string result = day05.FullyReducePolymer("dabAcCaCBAcCcaDA");
|
||||||
|
|
||||||
@@ -117,7 +115,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void RemoveUnitTypeFromPolymer__Remove_a()
|
public void RemoveUnitTypeFromPolymer__Remove_a()
|
||||||
{
|
{
|
||||||
Day05 day05 = new Day05();
|
Day05 day05 = new();
|
||||||
|
|
||||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'a');
|
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'a');
|
||||||
|
|
||||||
@@ -127,7 +125,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void RemoveUnitTypeFromPolymer__Remove_b()
|
public void RemoveUnitTypeFromPolymer__Remove_b()
|
||||||
{
|
{
|
||||||
Day05 day05 = new Day05();
|
Day05 day05 = new();
|
||||||
|
|
||||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'b');
|
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'b');
|
||||||
|
|
||||||
@@ -137,7 +135,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void RemoveUnitTypeFromPolymer__Remove_c()
|
public void RemoveUnitTypeFromPolymer__Remove_c()
|
||||||
{
|
{
|
||||||
Day05 day05 = new Day05();
|
Day05 day05 = new();
|
||||||
|
|
||||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'c');
|
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'c');
|
||||||
|
|
||||||
@@ -147,7 +145,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void RemoveUnitTypeFromPolymer__Remove_d()
|
public void RemoveUnitTypeFromPolymer__Remove_d()
|
||||||
{
|
{
|
||||||
Day05 day05 = new Day05();
|
Day05 day05 = new();
|
||||||
|
|
||||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'd');
|
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'd');
|
||||||
|
|
||||||
@@ -157,7 +155,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void RemoveUnitTypeFromPolymer__Remove_A()
|
public void RemoveUnitTypeFromPolymer__Remove_A()
|
||||||
{
|
{
|
||||||
Day05 day05 = new Day05();
|
Day05 day05 = new();
|
||||||
|
|
||||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'A');
|
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'A');
|
||||||
|
|
||||||
@@ -167,7 +165,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void RemoveUnitTypeFromPolymer__Remove_B()
|
public void RemoveUnitTypeFromPolymer__Remove_B()
|
||||||
{
|
{
|
||||||
Day05 day05 = new Day05();
|
Day05 day05 = new();
|
||||||
|
|
||||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'B');
|
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'B');
|
||||||
|
|
||||||
@@ -177,7 +175,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void RemoveUnitTypeFromPolymer__Remove_C()
|
public void RemoveUnitTypeFromPolymer__Remove_C()
|
||||||
{
|
{
|
||||||
Day05 day05 = new Day05();
|
Day05 day05 = new();
|
||||||
|
|
||||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'C');
|
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'C');
|
||||||
|
|
||||||
@@ -187,7 +185,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void RemoveUnitTypeFromPolymer__Remove_D()
|
public void RemoveUnitTypeFromPolymer__Remove_D()
|
||||||
{
|
{
|
||||||
Day05 day05 = new Day05();
|
Day05 day05 = new();
|
||||||
|
|
||||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'D');
|
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'D');
|
||||||
|
|
||||||
@@ -196,4 +194,3 @@ namespace AdventOfCode2018.Tests
|
|||||||
|
|
||||||
#endregion RemoveUnitTypeFromPolymer
|
#endregion RemoveUnitTypeFromPolymer
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,16 +1,13 @@
|
|||||||
using System.Collections.Generic;
|
namespace AdventOfCode2018.Tests;
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace AdventOfCode2018.Tests
|
|
||||||
{
|
|
||||||
public class Day06_Tests
|
public class Day06_Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test()
|
public void ResolvePart1__Test()
|
||||||
{
|
{
|
||||||
Day06 day06 = new Day06();
|
Day06 day06 = new();
|
||||||
|
|
||||||
string result = day06.ResolvePart1(new string[] {
|
string result = day06.ResolvePart1(new[] {
|
||||||
"1, 1",
|
"1, 1",
|
||||||
"1, 6",
|
"1, 6",
|
||||||
"8, 3",
|
"8, 3",
|
||||||
@@ -25,9 +22,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test()
|
public void ResolvePart2__Test()
|
||||||
{
|
{
|
||||||
Day06 day06 = new Day06 { DistanceThresold = 32, };
|
Day06 day06 = new() { DistanceThresold = 32, };
|
||||||
|
|
||||||
string result = day06.ResolvePart2(new string[] {
|
string result = day06.ResolvePart2(new[] {
|
||||||
"1, 1",
|
"1, 1",
|
||||||
"1, 6",
|
"1, 6",
|
||||||
"8, 3",
|
"8, 3",
|
||||||
@@ -39,4 +36,3 @@ namespace AdventOfCode2018.Tests
|
|||||||
Assert.Equal("16", result);
|
Assert.Equal("16", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,15 +1,13 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2018.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2018.Tests
|
|
||||||
{
|
|
||||||
public class Day07_Tests
|
public class Day07_Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test()
|
public void ResolvePart1__Test()
|
||||||
{
|
{
|
||||||
Day07 day07 = new Day07();
|
Day07 day07 = new();
|
||||||
|
|
||||||
string result = day07.ResolvePart1(new string[] {
|
string result = day07.ResolvePart1(new[] {
|
||||||
"Step C must be finished before step A can begin.",
|
"Step C must be finished before step A can begin.",
|
||||||
"Step C must be finished before step F can begin.",
|
"Step C must be finished before step F can begin.",
|
||||||
"Step A must be finished before step B can begin.",
|
"Step A must be finished before step B can begin.",
|
||||||
@@ -25,9 +23,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test()
|
public void ResolvePart2__Test()
|
||||||
{
|
{
|
||||||
Day07 day07 = new Day07 { BaseCost = 0, NumberOfWorkers = 2 };
|
Day07 day07 = new() { BaseCost = 0, NumberOfWorkers = 2 };
|
||||||
|
|
||||||
string result = day07.ResolvePart2(new string[] {
|
string result = day07.ResolvePart2(new[] {
|
||||||
"Step C must be finished before step A can begin.",
|
"Step C must be finished before step A can begin.",
|
||||||
"Step C must be finished before step F can begin.",
|
"Step C must be finished before step F can begin.",
|
||||||
"Step A must be finished before step B can begin.",
|
"Step A must be finished before step B can begin.",
|
||||||
@@ -40,4 +38,3 @@ namespace AdventOfCode2018.Tests
|
|||||||
Assert.Equal("15", result);
|
Assert.Equal("15", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,15 +1,13 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2018.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2018.Tests
|
|
||||||
{
|
|
||||||
public class Day08_Tests
|
public class Day08_Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test()
|
public void ResolvePart1__Test()
|
||||||
{
|
{
|
||||||
Day08 day = new Day08();
|
Day08 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] { "2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2", });
|
string result = day.ResolvePart1(new[] { "2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2", });
|
||||||
|
|
||||||
Assert.Equal("138", result);
|
Assert.Equal("138", result);
|
||||||
}
|
}
|
||||||
@@ -17,11 +15,10 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test()
|
public void ResolvePart2__Test()
|
||||||
{
|
{
|
||||||
Day08 day = new Day08();
|
Day08 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] { "2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2", });
|
string result = day.ResolvePart2(new[] { "2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2", });
|
||||||
|
|
||||||
Assert.Equal("66", result);
|
Assert.Equal("66", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,15 +1,13 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2018.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2018.Tests
|
|
||||||
{
|
|
||||||
public class Day09_Tests
|
public class Day09_Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test1()
|
public void ResolvePart1__Test1()
|
||||||
{
|
{
|
||||||
Day09 day = new Day09();
|
Day09 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] { "9 players; last marble is worth 25 points" });
|
string result = day.ResolvePart1(new[] { "9 players; last marble is worth 25 points" });
|
||||||
|
|
||||||
Assert.Equal("32", result);
|
Assert.Equal("32", result);
|
||||||
}
|
}
|
||||||
@@ -17,9 +15,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test2()
|
public void ResolvePart1__Test2()
|
||||||
{
|
{
|
||||||
Day09 day = new Day09();
|
Day09 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] { "10 players; last marble is worth 1618 points" });
|
string result = day.ResolvePart1(new[] { "10 players; last marble is worth 1618 points" });
|
||||||
|
|
||||||
Assert.Equal("8317", result);
|
Assert.Equal("8317", result);
|
||||||
}
|
}
|
||||||
@@ -27,9 +25,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test3()
|
public void ResolvePart1__Test3()
|
||||||
{
|
{
|
||||||
Day09 day = new Day09();
|
Day09 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] { "13 players; last marble is worth 7999 points" });
|
string result = day.ResolvePart1(new[] { "13 players; last marble is worth 7999 points" });
|
||||||
|
|
||||||
Assert.Equal("146373", result);
|
Assert.Equal("146373", result);
|
||||||
}
|
}
|
||||||
@@ -37,9 +35,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test4()
|
public void ResolvePart1__Test4()
|
||||||
{
|
{
|
||||||
Day09 day = new Day09();
|
Day09 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] { "17 players; last marble is worth 1104 points" });
|
string result = day.ResolvePart1(new[] { "17 players; last marble is worth 1104 points" });
|
||||||
|
|
||||||
Assert.Equal("2764", result);
|
Assert.Equal("2764", result);
|
||||||
}
|
}
|
||||||
@@ -47,9 +45,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test5()
|
public void ResolvePart1__Test5()
|
||||||
{
|
{
|
||||||
Day09 day = new Day09();
|
Day09 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] { "21 players; last marble is worth 6111 points" });
|
string result = day.ResolvePart1(new[] { "21 players; last marble is worth 6111 points" });
|
||||||
|
|
||||||
Assert.Equal("54718", result);
|
Assert.Equal("54718", result);
|
||||||
}
|
}
|
||||||
@@ -57,11 +55,10 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test6()
|
public void ResolvePart1__Test6()
|
||||||
{
|
{
|
||||||
Day09 day = new Day09();
|
Day09 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] { "30 players; last marble is worth 5807 points" });
|
string result = day.ResolvePart1(new[] { "30 players; last marble is worth 5807 points" });
|
||||||
|
|
||||||
Assert.Equal("37305", result);
|
Assert.Equal("37305", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,16 +1,15 @@
|
|||||||
using System;
|
using System;
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace AdventOfCode2018.Tests
|
namespace AdventOfCode2018.Tests;
|
||||||
{
|
|
||||||
public class Day10_Tests
|
public class Day10_Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test()
|
public void ResolvePart1__Test()
|
||||||
{
|
{
|
||||||
Day10 day = new Day10 { Width = 12, Height = 10 };
|
Day10 day = new() { Width = 12, Height = 10 };
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"position=< 9, 1> velocity=< 0, 2>",
|
"position=< 9, 1> velocity=< 0, 2>",
|
||||||
"position=< 7, 0> velocity=<-1, 0>",
|
"position=< 7, 0> velocity=<-1, 0>",
|
||||||
"position=< 3, -2> velocity=<-1, 1>",
|
"position=< 3, -2> velocity=<-1, 1>",
|
||||||
@@ -60,9 +59,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test()
|
public void ResolvePart2__Test()
|
||||||
{
|
{
|
||||||
Day10 day = new Day10();
|
Day10 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] {
|
string result = day.ResolvePart2(new[] {
|
||||||
"position=< 9, 1> velocity=< 0, 2>",
|
"position=< 9, 1> velocity=< 0, 2>",
|
||||||
"position=< 7, 0> velocity=<-1, 0>",
|
"position=< 7, 0> velocity=<-1, 0>",
|
||||||
"position=< 3, -2> velocity=<-1, 1>",
|
"position=< 3, -2> velocity=<-1, 1>",
|
||||||
@@ -99,4 +98,3 @@ namespace AdventOfCode2018.Tests
|
|||||||
Assert.Equal("3", result);
|
Assert.Equal("3", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2018.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2018.Tests
|
|
||||||
{
|
|
||||||
public class Day11_Tests
|
public class Day11_Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -60,17 +58,16 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test1()
|
public void ResolvePart2__Test1()
|
||||||
{
|
{
|
||||||
Day11 day = new Day11();
|
Day11 day = new();
|
||||||
string result = day.ResolvePart2(new string[] { "18" });
|
string result = day.ResolvePart2(new[] { "18" });
|
||||||
Assert.Equal("90,269,16", result);
|
Assert.Equal("90,269,16", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test2()
|
public void ResolvePart2__Test2()
|
||||||
{
|
{
|
||||||
Day11 day = new Day11();
|
Day11 day = new();
|
||||||
string result = day.ResolvePart2(new string[] { "42" });
|
string result = day.ResolvePart2(new[] { "42" });
|
||||||
Assert.Equal("232,251,12", result);
|
Assert.Equal("232,251,12", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,15 +1,13 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2018.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2018.Tests
|
|
||||||
{
|
|
||||||
public class Day12_Tests
|
public class Day12_Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test()
|
public void ResolvePart1__Test()
|
||||||
{
|
{
|
||||||
Day12 day = new Day12();
|
Day12 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[]
|
string result = day.ResolvePart1(new[]
|
||||||
{
|
{
|
||||||
"initial state: #..#.#..##......###...###",
|
"initial state: #..#.#..##......###...###",
|
||||||
"",
|
"",
|
||||||
@@ -32,4 +30,3 @@ namespace AdventOfCode2018.Tests
|
|||||||
Assert.Equal("325", result);
|
Assert.Equal("325", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,15 +1,13 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2018.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2018.Tests
|
|
||||||
{
|
|
||||||
public class Day13_Tests
|
public class Day13_Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test1()
|
public void ResolvePart1__Test1()
|
||||||
{
|
{
|
||||||
Day13 day = new Day13();
|
Day13 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"|",
|
"|",
|
||||||
"v",
|
"v",
|
||||||
"|",
|
"|",
|
||||||
@@ -25,9 +23,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test2()
|
public void ResolvePart1__Test2()
|
||||||
{
|
{
|
||||||
Day13 day = new Day13();
|
Day13 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
@"/->-\ ",
|
@"/->-\ ",
|
||||||
@"| | /----\",
|
@"| | /----\",
|
||||||
@"| /-+--+-\ |",
|
@"| /-+--+-\ |",
|
||||||
@@ -42,9 +40,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test()
|
public void ResolvePart2__Test()
|
||||||
{
|
{
|
||||||
Day13 day = new Day13();
|
Day13 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] {
|
string result = day.ResolvePart2(new[] {
|
||||||
@"/>-<\ ",
|
@"/>-<\ ",
|
||||||
@"| | ",
|
@"| | ",
|
||||||
@"| /<+-\",
|
@"| /<+-\",
|
||||||
@@ -57,4 +55,3 @@ namespace AdventOfCode2018.Tests
|
|||||||
Assert.Equal("6,4", result);
|
Assert.Equal("6,4", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2018.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2018.Tests
|
|
||||||
{
|
|
||||||
public class Day14_Tests
|
public class Day14_Tests
|
||||||
{
|
{
|
||||||
#region ResolvePart1
|
#region ResolvePart1
|
||||||
@@ -9,9 +7,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test1()
|
public void ResolvePart1__Test1()
|
||||||
{
|
{
|
||||||
Day14 day = new Day14();
|
Day14 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] { "9", });
|
string result = day.ResolvePart1(new[] { "9", });
|
||||||
|
|
||||||
Assert.Equal("5158916779", result);
|
Assert.Equal("5158916779", result);
|
||||||
}
|
}
|
||||||
@@ -19,9 +17,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test2()
|
public void ResolvePart1__Test2()
|
||||||
{
|
{
|
||||||
Day14 day = new Day14();
|
Day14 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] { "5", });
|
string result = day.ResolvePart1(new[] { "5", });
|
||||||
|
|
||||||
Assert.Equal("0124515891", result);
|
Assert.Equal("0124515891", result);
|
||||||
}
|
}
|
||||||
@@ -29,9 +27,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test3()
|
public void ResolvePart1__Test3()
|
||||||
{
|
{
|
||||||
Day14 day = new Day14();
|
Day14 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] { "18", });
|
string result = day.ResolvePart1(new[] { "18", });
|
||||||
|
|
||||||
Assert.Equal("9251071085", result);
|
Assert.Equal("9251071085", result);
|
||||||
}
|
}
|
||||||
@@ -39,9 +37,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test4()
|
public void ResolvePart1__Test4()
|
||||||
{
|
{
|
||||||
Day14 day = new Day14();
|
Day14 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] { "2018", });
|
string result = day.ResolvePart1(new[] { "2018", });
|
||||||
|
|
||||||
Assert.Equal("5941429882", result);
|
Assert.Equal("5941429882", result);
|
||||||
}
|
}
|
||||||
@@ -53,9 +51,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test1()
|
public void ResolvePart2__Test1()
|
||||||
{
|
{
|
||||||
Day14 day = new Day14();
|
Day14 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] { "51589", });
|
string result = day.ResolvePart2(new[] { "51589", });
|
||||||
|
|
||||||
Assert.Equal("9", result);
|
Assert.Equal("9", result);
|
||||||
}
|
}
|
||||||
@@ -63,9 +61,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test2()
|
public void ResolvePart2__Test2()
|
||||||
{
|
{
|
||||||
Day14 day = new Day14();
|
Day14 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] { "01245", });
|
string result = day.ResolvePart2(new[] { "01245", });
|
||||||
|
|
||||||
Assert.Equal("5", result);
|
Assert.Equal("5", result);
|
||||||
}
|
}
|
||||||
@@ -73,9 +71,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test3()
|
public void ResolvePart2__Test3()
|
||||||
{
|
{
|
||||||
Day14 day = new Day14();
|
Day14 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] { "92510", });
|
string result = day.ResolvePart2(new[] { "92510", });
|
||||||
|
|
||||||
Assert.Equal("18", result);
|
Assert.Equal("18", result);
|
||||||
}
|
}
|
||||||
@@ -83,13 +81,12 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test4()
|
public void ResolvePart2__Test4()
|
||||||
{
|
{
|
||||||
Day14 day = new Day14();
|
Day14 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] { "59414", });
|
string result = day.ResolvePart2(new[] { "59414", });
|
||||||
|
|
||||||
Assert.Equal("2018", result);
|
Assert.Equal("2018", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion ResolvePart2
|
#endregion ResolvePart2
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,13 +1,5 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2018.Tests;
|
||||||
using AdventOfCode2018;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AdventOfCode2018.Tests
|
|
||||||
{
|
|
||||||
public class Day15_Tests
|
public class Day15_Tests
|
||||||
{
|
{
|
||||||
#region ResolvePart1
|
#region ResolvePart1
|
||||||
@@ -15,9 +7,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test1()
|
public void ResolvePart1__Test1()
|
||||||
{
|
{
|
||||||
Day15 day = new Day15();
|
Day15 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"#######",
|
"#######",
|
||||||
"#.G...#",
|
"#.G...#",
|
||||||
"#...EG#",
|
"#...EG#",
|
||||||
@@ -33,9 +25,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test2()
|
public void ResolvePart1__Test2()
|
||||||
{
|
{
|
||||||
Day15 day = new Day15();
|
Day15 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"#######",
|
"#######",
|
||||||
"#G..#E#",
|
"#G..#E#",
|
||||||
"#E#E.E#",
|
"#E#E.E#",
|
||||||
@@ -51,9 +43,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test3()
|
public void ResolvePart1__Test3()
|
||||||
{
|
{
|
||||||
Day15 day = new Day15();
|
Day15 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"#######",
|
"#######",
|
||||||
"#E..EG#",
|
"#E..EG#",
|
||||||
"#.#G.E#",
|
"#.#G.E#",
|
||||||
@@ -69,9 +61,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test4()
|
public void ResolvePart1__Test4()
|
||||||
{
|
{
|
||||||
Day15 day = new Day15();
|
Day15 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"#######",
|
"#######",
|
||||||
"#E.G#.#",
|
"#E.G#.#",
|
||||||
"#.#G..#",
|
"#.#G..#",
|
||||||
@@ -87,9 +79,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test5()
|
public void ResolvePart1__Test5()
|
||||||
{
|
{
|
||||||
Day15 day = new Day15();
|
Day15 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"#######",
|
"#######",
|
||||||
"#.E...#",
|
"#.E...#",
|
||||||
"#.#..G#",
|
"#.#..G#",
|
||||||
@@ -105,9 +97,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test6()
|
public void ResolvePart1__Test6()
|
||||||
{
|
{
|
||||||
Day15 day = new Day15();
|
Day15 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"#########",
|
"#########",
|
||||||
"#G......#",
|
"#G......#",
|
||||||
"#.E.#...#",
|
"#.E.#...#",
|
||||||
@@ -129,9 +121,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test1()
|
public void ResolvePart2__Test1()
|
||||||
{
|
{
|
||||||
Day15 day = new Day15();
|
Day15 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] {
|
string result = day.ResolvePart2(new[] {
|
||||||
"#######",
|
"#######",
|
||||||
"#.G...#",
|
"#.G...#",
|
||||||
"#...EG#",
|
"#...EG#",
|
||||||
@@ -147,9 +139,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test3()
|
public void ResolvePart2__Test3()
|
||||||
{
|
{
|
||||||
Day15 day = new Day15();
|
Day15 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] {
|
string result = day.ResolvePart2(new[] {
|
||||||
"#######",
|
"#######",
|
||||||
"#E..EG#",
|
"#E..EG#",
|
||||||
"#.#G.E#",
|
"#.#G.E#",
|
||||||
@@ -165,9 +157,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test4()
|
public void ResolvePart2__Test4()
|
||||||
{
|
{
|
||||||
Day15 day = new Day15();
|
Day15 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] {
|
string result = day.ResolvePart2(new[] {
|
||||||
"#######",
|
"#######",
|
||||||
"#E.G#.#",
|
"#E.G#.#",
|
||||||
"#.#G..#",
|
"#.#G..#",
|
||||||
@@ -183,9 +175,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test5()
|
public void ResolvePart2__Test5()
|
||||||
{
|
{
|
||||||
Day15 day = new Day15();
|
Day15 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] {
|
string result = day.ResolvePart2(new[] {
|
||||||
"#######",
|
"#######",
|
||||||
"#.E...#",
|
"#.E...#",
|
||||||
"#.#..G#",
|
"#.#..G#",
|
||||||
@@ -201,9 +193,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test6()
|
public void ResolvePart2__Test6()
|
||||||
{
|
{
|
||||||
Day15 day = new Day15();
|
Day15 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] {
|
string result = day.ResolvePart2(new[] {
|
||||||
"#########",
|
"#########",
|
||||||
"#G......#",
|
"#G......#",
|
||||||
"#.E.#...#",
|
"#.E.#...#",
|
||||||
@@ -220,4 +212,3 @@ namespace AdventOfCode2018.Tests
|
|||||||
|
|
||||||
#endregion ResolvePart2
|
#endregion ResolvePart2
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,16 +1,13 @@
|
|||||||
using AdventOfCode2018;
|
namespace AdventOfCode2018.Tests;
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace AdventOfCode2018.Tests
|
|
||||||
{
|
|
||||||
public class Day23_Tests
|
public class Day23_Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart1__Test()
|
public void ResolvePart1__Test()
|
||||||
{
|
{
|
||||||
Day23 day = new Day23();
|
Day23 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"pos=<0,0,0>, r=4",
|
"pos=<0,0,0>, r=4",
|
||||||
"pos=<1,0,0>, r=1",
|
"pos=<1,0,0>, r=1",
|
||||||
"pos=<4,0,0>, r=3",
|
"pos=<4,0,0>, r=3",
|
||||||
@@ -28,9 +25,9 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvePart2__Test()
|
public void ResolvePart2__Test()
|
||||||
{
|
{
|
||||||
Day23 day = new Day23();
|
Day23 day = new();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] {
|
string result = day.ResolvePart2(new[] {
|
||||||
"pos=<10,12,12>, r=2",
|
"pos=<10,12,12>, r=2",
|
||||||
"pos=<12,14,12>, r=2",
|
"pos=<12,14,12>, r=2",
|
||||||
"pos=<16,12,12>, r=4",
|
"pos=<16,12,12>, r=4",
|
||||||
@@ -42,4 +39,3 @@ namespace AdventOfCode2018.Tests
|
|||||||
Assert.Equal("36", result);
|
Assert.Equal("36", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace AdventOfCode2018.Tests
|
namespace AdventOfCode2018.Tests;
|
||||||
{
|
|
||||||
public class GuardEvent_Tests
|
public class GuardEvent_Tests
|
||||||
{
|
{
|
||||||
#region FromString
|
#region FromString
|
||||||
@@ -25,7 +24,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
{
|
{
|
||||||
GuardEvent guardEvent = GuardEvent.FromString("[1518-11-02 00:40] falls asleep");
|
GuardEvent guardEvent = GuardEvent.FromString("[1518-11-02 00:40] falls asleep");
|
||||||
|
|
||||||
Assert.Equal(null, guardEvent.ID);
|
Assert.Null(guardEvent.ID);
|
||||||
Assert.Equal(11, guardEvent.Date.Month);
|
Assert.Equal(11, guardEvent.Date.Month);
|
||||||
Assert.Equal(2, guardEvent.Date.Day);
|
Assert.Equal(2, guardEvent.Date.Day);
|
||||||
Assert.Equal(0, guardEvent.Date.Hour);
|
Assert.Equal(0, guardEvent.Date.Hour);
|
||||||
@@ -38,7 +37,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
{
|
{
|
||||||
GuardEvent guardEvent = GuardEvent.FromString("[1518-11-03 00:29] wakes up");
|
GuardEvent guardEvent = GuardEvent.FromString("[1518-11-03 00:29] wakes up");
|
||||||
|
|
||||||
Assert.Equal(null, guardEvent.ID);
|
Assert.Null(guardEvent.ID);
|
||||||
Assert.Equal(11, guardEvent.Date.Month);
|
Assert.Equal(11, guardEvent.Date.Month);
|
||||||
Assert.Equal(3, guardEvent.Date.Day);
|
Assert.Equal(3, guardEvent.Date.Day);
|
||||||
Assert.Equal(0, guardEvent.Date.Hour);
|
Assert.Equal(0, guardEvent.Date.Hour);
|
||||||
@@ -53,7 +52,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void FromStringArray__TestBase()
|
public void FromStringArray__TestBase()
|
||||||
{
|
{
|
||||||
List<GuardEvent> guardEvents = GuardEvent.FromStringArray(new string[] {
|
List<GuardEvent> guardEvents = GuardEvent.FromStringArray(new[] {
|
||||||
"[1518-11-01 00:00] Guard #10 begins shift",
|
"[1518-11-01 00:00] Guard #10 begins shift",
|
||||||
"[1518-11-01 00:05] falls asleep",
|
"[1518-11-01 00:05] falls asleep",
|
||||||
"[1518-11-01 00:25] wakes up",
|
"[1518-11-01 00:25] wakes up",
|
||||||
@@ -92,7 +91,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void FromStringArray__TestBaseUnsorted()
|
public void FromStringArray__TestBaseUnsorted()
|
||||||
{
|
{
|
||||||
List<GuardEvent> guardEvents = GuardEvent.FromStringArray(new string[] {
|
List<GuardEvent> guardEvents = GuardEvent.FromStringArray(new[] {
|
||||||
"[1518-11-01 00:00] Guard #10 begins shift",
|
"[1518-11-01 00:00] Guard #10 begins shift",
|
||||||
"[1518-11-01 23:58] Guard #99 begins shift",
|
"[1518-11-01 23:58] Guard #99 begins shift",
|
||||||
"[1518-11-01 00:30] falls asleep",
|
"[1518-11-01 00:30] falls asleep",
|
||||||
@@ -130,4 +129,3 @@ namespace AdventOfCode2018.Tests
|
|||||||
|
|
||||||
#endregion FromStringArray
|
#endregion FromStringArray
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,13 +1,11 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2018.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2018.Tests
|
|
||||||
{
|
|
||||||
public class MarbleGame_Tests
|
public class MarbleGame_Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void PlayGame__Test1()
|
public void PlayGame__Test1()
|
||||||
{
|
{
|
||||||
MarbleGame marbleGame = new MarbleGame();
|
MarbleGame marbleGame = new();
|
||||||
|
|
||||||
marbleGame.PlayGame(9, 25);
|
marbleGame.PlayGame(9, 25);
|
||||||
long highScore = marbleGame.GetHighScore();
|
long highScore = marbleGame.GetHighScore();
|
||||||
@@ -18,7 +16,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void PlayGame__Test2()
|
public void PlayGame__Test2()
|
||||||
{
|
{
|
||||||
MarbleGame marbleGame = new MarbleGame();
|
MarbleGame marbleGame = new();
|
||||||
|
|
||||||
marbleGame.PlayGame(10, 1618);
|
marbleGame.PlayGame(10, 1618);
|
||||||
long highScore = marbleGame.GetHighScore();
|
long highScore = marbleGame.GetHighScore();
|
||||||
@@ -29,7 +27,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void PlayGame__Test3()
|
public void PlayGame__Test3()
|
||||||
{
|
{
|
||||||
MarbleGame marbleGame = new MarbleGame();
|
MarbleGame marbleGame = new();
|
||||||
|
|
||||||
marbleGame.PlayGame(13, 7999);
|
marbleGame.PlayGame(13, 7999);
|
||||||
long highScore = marbleGame.GetHighScore();
|
long highScore = marbleGame.GetHighScore();
|
||||||
@@ -40,7 +38,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void PlayGame__Test4()
|
public void PlayGame__Test4()
|
||||||
{
|
{
|
||||||
MarbleGame marbleGame = new MarbleGame();
|
MarbleGame marbleGame = new();
|
||||||
|
|
||||||
marbleGame.PlayGame(17, 1104);
|
marbleGame.PlayGame(17, 1104);
|
||||||
long highScore = marbleGame.GetHighScore();
|
long highScore = marbleGame.GetHighScore();
|
||||||
@@ -51,7 +49,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void PlayGame__Test5()
|
public void PlayGame__Test5()
|
||||||
{
|
{
|
||||||
MarbleGame marbleGame = new MarbleGame();
|
MarbleGame marbleGame = new();
|
||||||
|
|
||||||
marbleGame.PlayGame(21, 6111);
|
marbleGame.PlayGame(21, 6111);
|
||||||
long highScore = marbleGame.GetHighScore();
|
long highScore = marbleGame.GetHighScore();
|
||||||
@@ -62,7 +60,7 @@ namespace AdventOfCode2018.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void PlayGame__Test6()
|
public void PlayGame__Test6()
|
||||||
{
|
{
|
||||||
MarbleGame marbleGame = new MarbleGame();
|
MarbleGame marbleGame = new();
|
||||||
|
|
||||||
marbleGame.PlayGame(30, 5807);
|
marbleGame.PlayGame(30, 5807);
|
||||||
long highScore = marbleGame.GetHighScore();
|
long highScore = marbleGame.GetHighScore();
|
||||||
@@ -70,4 +68,3 @@ namespace AdventOfCode2018.Tests
|
|||||||
Assert.Equal(37305, highScore);
|
Assert.Equal(37305, highScore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
1
AdventOfCode2018.Tests/Usings.cs
Normal file
1
AdventOfCode2018.Tests/Usings.cs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
global using Xunit;
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace AdventOfCode2018
|
namespace AdventOfCode2018;
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
--- Day 1: Chronal Calibration ---
|
--- Day 1: Chronal Calibration ---
|
||||||
|
|
||||||
@@ -86,7 +85,7 @@ namespace AdventOfCode2018
|
|||||||
public string ResolvePart2(string[] inputs)
|
public string ResolvePart2(string[] inputs)
|
||||||
{
|
{
|
||||||
int accumulator = 0;
|
int accumulator = 0;
|
||||||
List<int> accumulatorHistory = new List<int>();
|
List<int> accumulatorHistory = new();
|
||||||
int? repeatedAccumulator = null;
|
int? repeatedAccumulator = null;
|
||||||
while (repeatedAccumulator == null)
|
while (repeatedAccumulator == null)
|
||||||
{
|
{
|
||||||
@@ -116,4 +115,3 @@ namespace AdventOfCode2018
|
|||||||
return repeatedAccumulator.ToString();
|
return repeatedAccumulator.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace AdventOfCode2018
|
namespace AdventOfCode2018;
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
--- Day 2: Inventory Management System ---
|
--- Day 2: Inventory Management System ---
|
||||||
|
|
||||||
@@ -92,7 +91,7 @@ namespace AdventOfCode2018
|
|||||||
{
|
{
|
||||||
if (id1.Length != id2.Length) { throw new ArgumentException("id1 and id2 parameters must be of same length"); }
|
if (id1.Length != id2.Length) { throw new ArgumentException("id1 and id2 parameters must be of same length"); }
|
||||||
int diffCount = 0;
|
int diffCount = 0;
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new();
|
||||||
for (int i = 0; i < id1.Length; i++)
|
for (int i = 0; i < id1.Length; i++)
|
||||||
{
|
{
|
||||||
if (id1[i] != id2[i]) { diffCount++; }
|
if (id1[i] != id2[i]) { diffCount++; }
|
||||||
@@ -115,4 +114,3 @@ namespace AdventOfCode2018
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace AdventOfCode2018
|
namespace AdventOfCode2018;
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
--- Day 3: No Matter How You Slice It ---
|
--- Day 3: No Matter How You Slice It ---
|
||||||
|
|
||||||
@@ -145,8 +144,8 @@ namespace AdventOfCode2018
|
|||||||
|
|
||||||
public static Claim FromString(string strClaim)
|
public static Claim FromString(string strClaim)
|
||||||
{
|
{
|
||||||
Claim claim = new Claim();
|
Claim claim = new();
|
||||||
string[] parts = strClaim.Split(new string[] { " @ ", ",", ": ", "x", }, StringSplitOptions.None);
|
string[] parts = strClaim.Split(new[] { " @ ", ",", ": ", "x", }, StringSplitOptions.None);
|
||||||
claim.ID = Convert.ToInt32(parts[0].Substring(1));
|
claim.ID = Convert.ToInt32(parts[0].Substring(1));
|
||||||
claim.Left = Convert.ToInt32(parts[1]);
|
claim.Left = Convert.ToInt32(parts[1]);
|
||||||
claim.Top = Convert.ToInt32(parts[2]);
|
claim.Top = Convert.ToInt32(parts[2]);
|
||||||
@@ -176,6 +175,3 @@ namespace AdventOfCode2018
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace AdventOfCode2018
|
namespace AdventOfCode2018;
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
--- Day 4: Repose Record ---
|
--- Day 4: Repose Record ---
|
||||||
|
|
||||||
@@ -131,14 +131,14 @@ namespace AdventOfCode2018
|
|||||||
|
|
||||||
private static Dictionary<int, GuardSleepHistogram> BuildFullHistorgram(List<GuardEvent> guardEvents)
|
private static Dictionary<int, GuardSleepHistogram> BuildFullHistorgram(List<GuardEvent> guardEvents)
|
||||||
{
|
{
|
||||||
Dictionary<int, GuardSleepHistogram> dictFullHistogram = new Dictionary<int, GuardSleepHistogram>();
|
Dictionary<int, GuardSleepHistogram> dictFullHistogram = new();
|
||||||
foreach (IGrouping<int, GuardEvent> group in guardEvents.GroupBy(guardEvent => guardEvent.Date.DayOfYear))
|
foreach (IGrouping<int, GuardEvent> group in guardEvents.GroupBy(guardEvent => guardEvent.Date.DayOfYear))
|
||||||
{
|
{
|
||||||
Dictionary<int, GuardSleepHistogram> dictDayHistogram = new Dictionary<int, GuardSleepHistogram>();
|
Dictionary<int, GuardSleepHistogram> dictDayHistogram = new();
|
||||||
foreach (GuardEvent guardEvent in group)
|
foreach (GuardEvent guardEvent in group)
|
||||||
{
|
{
|
||||||
if (guardEvent.ID == null) { continue; }
|
if (guardEvent.ID == null) { continue; }
|
||||||
GuardSleepHistogram dayGuardHistogram = null;
|
GuardSleepHistogram dayGuardHistogram;
|
||||||
if (dictDayHistogram.ContainsKey((int)guardEvent.ID))
|
if (dictDayHistogram.ContainsKey((int)guardEvent.ID))
|
||||||
{
|
{
|
||||||
dayGuardHistogram = dictDayHistogram[(int)guardEvent.ID];
|
dayGuardHistogram = dictDayHistogram[(int)guardEvent.ID];
|
||||||
@@ -160,7 +160,7 @@ namespace AdventOfCode2018
|
|||||||
|
|
||||||
foreach (GuardSleepHistogram dayGuardHistogram in dictDayHistogram.Values)
|
foreach (GuardSleepHistogram dayGuardHistogram in dictDayHistogram.Values)
|
||||||
{
|
{
|
||||||
GuardSleepHistogram guardHistogram = null;
|
GuardSleepHistogram guardHistogram;
|
||||||
if (dictFullHistogram.ContainsKey(dayGuardHistogram.ID))
|
if (dictFullHistogram.ContainsKey(dayGuardHistogram.ID))
|
||||||
{
|
{
|
||||||
guardHistogram = dictFullHistogram[dayGuardHistogram.ID];
|
guardHistogram = dictFullHistogram[dayGuardHistogram.ID];
|
||||||
@@ -192,8 +192,8 @@ namespace AdventOfCode2018
|
|||||||
|
|
||||||
public static GuardEvent FromString(string strEvent)
|
public static GuardEvent FromString(string strEvent)
|
||||||
{
|
{
|
||||||
GuardEvent guardEvent = new GuardEvent();
|
GuardEvent guardEvent = new();
|
||||||
string[] parts = strEvent.Split(new string[] { "[", "-", " ", ":", "]", "#", }, StringSplitOptions.RemoveEmptyEntries);
|
string[] parts = strEvent.Split(new[] { "[", "-", " ", ":", "]", "#", }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
guardEvent.Date = new DateTime(
|
guardEvent.Date = new DateTime(
|
||||||
Convert.ToInt32(parts[0]),
|
Convert.ToInt32(parts[0]),
|
||||||
Convert.ToInt32(parts[1]),
|
Convert.ToInt32(parts[1]),
|
||||||
@@ -272,4 +272,3 @@ namespace AdventOfCode2018
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace AdventOfCode2018
|
namespace AdventOfCode2018;
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
--- Day 5: Alchemical Reduction ---
|
--- Day 5: Alchemical Reduction ---
|
||||||
|
|
||||||
@@ -55,7 +54,7 @@ namespace AdventOfCode2018
|
|||||||
public string ReducePolymer(string polymer)
|
public string ReducePolymer(string polymer)
|
||||||
{
|
{
|
||||||
if (polymer.Length <= 1) { return polymer; }
|
if (polymer.Length <= 1) { return polymer; }
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new();
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 1; i < polymer.Length; i++)
|
for (i = 1; i < polymer.Length; i++)
|
||||||
@@ -78,7 +77,7 @@ namespace AdventOfCode2018
|
|||||||
|
|
||||||
public string FullyReducePolymer(string input)
|
public string FullyReducePolymer(string input)
|
||||||
{
|
{
|
||||||
string previousPolymer = null;
|
string previousPolymer;
|
||||||
string polymer = input;
|
string polymer = input;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@@ -96,7 +95,7 @@ namespace AdventOfCode2018
|
|||||||
|
|
||||||
public string RemoveUnitTypeFromPolymer(string polymer, char unitType)
|
public string RemoveUnitTypeFromPolymer(string polymer, char unitType)
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new();
|
||||||
unitType = char.ToLower(unitType);
|
unitType = char.ToLower(unitType);
|
||||||
foreach (char c in polymer)
|
foreach (char c in polymer)
|
||||||
{
|
{
|
||||||
@@ -128,4 +127,3 @@ namespace AdventOfCode2018
|
|||||||
return minPolymerLenght.ToString();
|
return minPolymerLenght.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace AdventOfCode2018
|
namespace AdventOfCode2018;
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
--- Day 6: Chronal Coordinates ---
|
--- Day 6: Chronal Coordinates ---
|
||||||
|
|
||||||
@@ -108,7 +107,7 @@ namespace AdventOfCode2018
|
|||||||
public string ResolvePart1(string[] inputs)
|
public string ResolvePart1(string[] inputs)
|
||||||
{
|
{
|
||||||
List<ChronoPoint> points = InputsToPoints(inputs);
|
List<ChronoPoint> points = InputsToPoints(inputs);
|
||||||
Dictionary<int, int> pointsAreas = new Dictionary<int, int>();
|
Dictionary<int, int> pointsAreas = new();
|
||||||
for (int i = 0; i < points.Count; i++)
|
for (int i = 0; i < points.Count; i++)
|
||||||
{
|
{
|
||||||
pointsAreas.Add(i, 0);
|
pointsAreas.Add(i, 0);
|
||||||
@@ -119,7 +118,7 @@ namespace AdventOfCode2018
|
|||||||
int minY = points.Min(p => p.Y) - 1;
|
int minY = points.Min(p => p.Y) - 1;
|
||||||
int maxY = points.Max(p => p.Y) + 1;
|
int maxY = points.Max(p => p.Y) + 1;
|
||||||
|
|
||||||
ChronoPoint samplingPoint = new ChronoPoint();
|
ChronoPoint samplingPoint = new();
|
||||||
for(int i=minX; i <= maxX; i++)
|
for(int i=minX; i <= maxX; i++)
|
||||||
{
|
{
|
||||||
for(int j = minY; j <= maxY; j++)
|
for(int j = minY; j <= maxY; j++)
|
||||||
@@ -172,7 +171,7 @@ namespace AdventOfCode2018
|
|||||||
int maxY = points.Max(p => p.Y) + 1;
|
int maxY = points.Max(p => p.Y) + 1;
|
||||||
|
|
||||||
int areaInRange = 0;
|
int areaInRange = 0;
|
||||||
ChronoPoint samplingPoint = new ChronoPoint();
|
ChronoPoint samplingPoint = new();
|
||||||
for (int i = minX; i <= maxX; i++)
|
for (int i = minX; i <= maxX; i++)
|
||||||
{
|
{
|
||||||
for (int j = minY; j <= maxY; j++)
|
for (int j = minY; j <= maxY; j++)
|
||||||
@@ -206,10 +205,9 @@ namespace AdventOfCode2018
|
|||||||
public static ChronoPoint FromString(string strPoint)
|
public static ChronoPoint FromString(string strPoint)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(strPoint)) { return null; }
|
if (string.IsNullOrEmpty(strPoint)) { return null; }
|
||||||
string[] parts = strPoint.Split(new string[] { ", ", }, StringSplitOptions.RemoveEmptyEntries);
|
string[] parts = strPoint.Split(new[] { ", ", }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
if (parts.Length < 2) { return null; }
|
if (parts.Length < 2) { return null; }
|
||||||
ChronoPoint point = new ChronoPoint
|
ChronoPoint point = new() {
|
||||||
{
|
|
||||||
X = Convert.ToInt32(parts[0]),
|
X = Convert.ToInt32(parts[0]),
|
||||||
Y = Convert.ToInt32(parts[1]),
|
Y = Convert.ToInt32(parts[1]),
|
||||||
};
|
};
|
||||||
@@ -222,4 +220,3 @@ namespace AdventOfCode2018
|
|||||||
return distance;
|
return distance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace AdventOfCode2018
|
namespace AdventOfCode2018;
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
--- Day 7: The Sum of Its Parts ---
|
--- Day 7: The Sum of Its Parts ---
|
||||||
@@ -89,11 +88,11 @@ namespace AdventOfCode2018
|
|||||||
{
|
{
|
||||||
private static Instructions BuildInstructions(string[] inputs, int baseCost)
|
private static Instructions BuildInstructions(string[] inputs, int baseCost)
|
||||||
{
|
{
|
||||||
Instructions instructions = new Instructions();
|
Instructions instructions = new();
|
||||||
foreach (string input in inputs)
|
foreach (string input in inputs)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(input)) { continue; }
|
if (string.IsNullOrEmpty(input)) { continue; }
|
||||||
string[] parts = input.Split(new string[] {
|
string[] parts = input.Split(new[] {
|
||||||
"Step ",
|
"Step ",
|
||||||
" must be finished before step ",
|
" must be finished before step ",
|
||||||
" can begin.",
|
" can begin.",
|
||||||
@@ -114,7 +113,7 @@ namespace AdventOfCode2018
|
|||||||
{
|
{
|
||||||
Instructions instructions = BuildInstructions(inputs, 0);
|
Instructions instructions = BuildInstructions(inputs, 0);
|
||||||
List<InstructionNode> finalInstructions = instructions.SortInstructions();
|
List<InstructionNode> finalInstructions = instructions.SortInstructions();
|
||||||
StringBuilder sbInstructions = new StringBuilder();
|
StringBuilder sbInstructions = new();
|
||||||
foreach (InstructionNode node in finalInstructions)
|
foreach (InstructionNode node in finalInstructions)
|
||||||
{
|
{
|
||||||
sbInstructions.Append(node.NodeID);
|
sbInstructions.Append(node.NodeID);
|
||||||
@@ -137,13 +136,13 @@ namespace AdventOfCode2018
|
|||||||
{
|
{
|
||||||
public string NodeID { get; set; }
|
public string NodeID { get; set; }
|
||||||
|
|
||||||
public List<string> PreviousNodeIDs { get; } = new List<string>();
|
public List<string> PreviousNodeIDs { get; } = new();
|
||||||
|
|
||||||
public int Cost { get; set; }
|
public int Cost { get; set; }
|
||||||
|
|
||||||
public bool Running { get; set; } = false;
|
public bool Running { get; set; }
|
||||||
|
|
||||||
public bool Used { get; set; } = false;
|
public bool Used { get; set; }
|
||||||
|
|
||||||
public bool CanBeUsed(Dictionary<string, InstructionNode> allNodes)
|
public bool CanBeUsed(Dictionary<string, InstructionNode> allNodes)
|
||||||
{
|
{
|
||||||
@@ -155,7 +154,7 @@ namespace AdventOfCode2018
|
|||||||
|
|
||||||
public class Instructions
|
public class Instructions
|
||||||
{
|
{
|
||||||
public Dictionary<string, InstructionNode> Nodes { get; } = new Dictionary<string, InstructionNode>();
|
public Dictionary<string, InstructionNode> Nodes { get; } = new();
|
||||||
|
|
||||||
public InstructionNode GetNode(string nodeID)
|
public InstructionNode GetNode(string nodeID)
|
||||||
{
|
{
|
||||||
@@ -181,14 +180,14 @@ namespace AdventOfCode2018
|
|||||||
|
|
||||||
public List<InstructionNode> SortInstructions()
|
public List<InstructionNode> SortInstructions()
|
||||||
{
|
{
|
||||||
List<InstructionNode> finalNodes = new List<InstructionNode>();
|
List<InstructionNode> finalNodes = new();
|
||||||
|
|
||||||
foreach (InstructionNode node in Nodes.Values)
|
foreach (InstructionNode node in Nodes.Values)
|
||||||
{
|
{
|
||||||
node.Used = false;
|
node.Used = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<InstructionNode> unusedNodes = null;
|
List<InstructionNode> unusedNodes;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
unusedNodes = Nodes.Values
|
unusedNodes = Nodes.Values
|
||||||
@@ -241,7 +240,7 @@ namespace AdventOfCode2018
|
|||||||
node.Used = false;
|
node.Used = false;
|
||||||
node.Running = false;
|
node.Running = false;
|
||||||
}
|
}
|
||||||
List<SimulatedWorker> workers = new List<SimulatedWorker>(numberOfWorkers);
|
List<SimulatedWorker> workers = new(numberOfWorkers);
|
||||||
for (int i = 0; i < numberOfWorkers; i++)
|
for (int i = 0; i < numberOfWorkers; i++)
|
||||||
{
|
{
|
||||||
workers.Add(new SimulatedWorker());
|
workers.Add(new SimulatedWorker());
|
||||||
@@ -282,4 +281,3 @@ namespace AdventOfCode2018
|
|||||||
return totalElapsedTime;
|
return totalElapsedTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace AdventOfCode2018
|
namespace AdventOfCode2018;
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
--- Day 8: Memory Maneuver ---
|
--- Day 8: Memory Maneuver ---
|
||||||
|
|
||||||
@@ -66,7 +65,7 @@ namespace AdventOfCode2018
|
|||||||
{
|
{
|
||||||
public string ResolvePart1(string[] inputs)
|
public string ResolvePart1(string[] inputs)
|
||||||
{
|
{
|
||||||
IntStream values = new IntStream(inputs[0]);
|
IntStream values = new(inputs[0]);
|
||||||
ChronoLicenceNode licenceTree = ChronoLicenceNode.BuildFromIntStream(values);
|
ChronoLicenceNode licenceTree = ChronoLicenceNode.BuildFromIntStream(values);
|
||||||
int result = licenceTree.GetChecksum();
|
int result = licenceTree.GetChecksum();
|
||||||
return result.ToString();
|
return result.ToString();
|
||||||
@@ -74,7 +73,7 @@ namespace AdventOfCode2018
|
|||||||
|
|
||||||
public string ResolvePart2(string[] inputs)
|
public string ResolvePart2(string[] inputs)
|
||||||
{
|
{
|
||||||
IntStream values = new IntStream(inputs[0]);
|
IntStream values = new(inputs[0]);
|
||||||
ChronoLicenceNode licenceTree = ChronoLicenceNode.BuildFromIntStream(values);
|
ChronoLicenceNode licenceTree = ChronoLicenceNode.BuildFromIntStream(values);
|
||||||
int result = licenceTree.GetValue();
|
int result = licenceTree.GetValue();
|
||||||
return result.ToString();
|
return result.ToString();
|
||||||
@@ -83,35 +82,35 @@ namespace AdventOfCode2018
|
|||||||
|
|
||||||
public class IntStream
|
public class IntStream
|
||||||
{
|
{
|
||||||
private int[] values;
|
private int[] _values;
|
||||||
private int index;
|
private int _index;
|
||||||
|
|
||||||
public IntStream(string strValues)
|
public IntStream(string strValues)
|
||||||
{
|
{
|
||||||
values = strValues
|
_values = strValues
|
||||||
.Split(new string[] { " ", }, StringSplitOptions.RemoveEmptyEntries)
|
.Split(new[] { " ", }, StringSplitOptions.RemoveEmptyEntries)
|
||||||
.Select(strVal => Convert.ToInt32(strVal))
|
.Select(strVal => Convert.ToInt32(strVal))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
index = 0;
|
_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Get()
|
public int Get()
|
||||||
{
|
{
|
||||||
int value = values[index];
|
int value = _values[_index];
|
||||||
index++;
|
_index++;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ChronoLicenceNode
|
public class ChronoLicenceNode
|
||||||
{
|
{
|
||||||
public List<ChronoLicenceNode> Childs { get; } = new List<ChronoLicenceNode>();
|
public List<ChronoLicenceNode> Childs { get; } = new();
|
||||||
|
|
||||||
public List<int> Metadata { get; } = new List<int>();
|
public List<int> Metadata { get; } = new();
|
||||||
|
|
||||||
public static ChronoLicenceNode BuildFromIntStream(IntStream stream)
|
public static ChronoLicenceNode BuildFromIntStream(IntStream stream)
|
||||||
{
|
{
|
||||||
ChronoLicenceNode node = new ChronoLicenceNode();
|
ChronoLicenceNode node = new();
|
||||||
int numChilds = stream.Get();
|
int numChilds = stream.Get();
|
||||||
int numMetadata = stream.Get();
|
int numMetadata = stream.Get();
|
||||||
|
|
||||||
@@ -158,4 +157,3 @@ namespace AdventOfCode2018
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace AdventOfCode2018
|
namespace AdventOfCode2018;
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
--- Day 9: Marble Mania ---
|
--- Day 9: Marble Mania ---
|
||||||
|
|
||||||
@@ -80,10 +79,10 @@ namespace AdventOfCode2018
|
|||||||
|
|
||||||
private static string CalculateHighScore(string input, long factor)
|
private static string CalculateHighScore(string input, long factor)
|
||||||
{
|
{
|
||||||
string[] parts = input.Split(new string[] { " players; last marble is worth ", " points" }, StringSplitOptions.RemoveEmptyEntries);
|
string[] parts = input.Split(new[] { " players; last marble is worth ", " points" }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
long numberOfPlayers = Convert.ToInt32(parts[0]);
|
long numberOfPlayers = Convert.ToInt32(parts[0]);
|
||||||
long lastMarble = Convert.ToInt32(parts[1]) * factor;
|
long lastMarble = Convert.ToInt32(parts[1]) * factor;
|
||||||
MarbleGame marbleGame = new MarbleGame();
|
MarbleGame marbleGame = new();
|
||||||
marbleGame.PlayGame(numberOfPlayers, lastMarble);
|
marbleGame.PlayGame(numberOfPlayers, lastMarble);
|
||||||
long result = marbleGame.GetHighScore();
|
long result = marbleGame.GetHighScore();
|
||||||
return result.ToString();
|
return result.ToString();
|
||||||
@@ -99,21 +98,21 @@ namespace AdventOfCode2018
|
|||||||
|
|
||||||
public class MarbleGame
|
public class MarbleGame
|
||||||
{
|
{
|
||||||
public Dictionary<long, long> Scores { get; } = new Dictionary<long, long>();
|
public Dictionary<long, long> Scores { get; } = new();
|
||||||
|
|
||||||
private Marble firstMarble;
|
private Marble _firstMarble;
|
||||||
private Marble currentMarble;
|
private Marble _currentMarble;
|
||||||
private long currentPlayer = 0;
|
private long _currentPlayer;
|
||||||
|
|
||||||
private const long PointValueMultiple = 23;
|
private const long PointValueMultiple = 23;
|
||||||
|
|
||||||
public void PlayGame(long numPlayers, long lastMarble, bool showStatus = false)
|
public void PlayGame(long numPlayers, long lastMarble, bool showStatus = false)
|
||||||
{
|
{
|
||||||
Scores.Clear();
|
Scores.Clear();
|
||||||
firstMarble = new Marble { Value = 0 };
|
_firstMarble = new Marble { Value = 0 };
|
||||||
firstMarble.Previous = firstMarble;
|
_firstMarble.Previous = _firstMarble;
|
||||||
firstMarble.Next = firstMarble;
|
_firstMarble.Next = _firstMarble;
|
||||||
currentMarble = firstMarble;
|
_currentMarble = _firstMarble;
|
||||||
|
|
||||||
for (long i = 1; i <= numPlayers; i++) { Scores.Add(i, 0); }
|
for (long i = 1; i <= numPlayers; i++) { Scores.Add(i, 0); }
|
||||||
|
|
||||||
@@ -121,27 +120,27 @@ namespace AdventOfCode2018
|
|||||||
{
|
{
|
||||||
if (showStatus) { PrintStatus(); }
|
if (showStatus) { PrintStatus(); }
|
||||||
|
|
||||||
currentPlayer = (i % numPlayers) + 1;
|
_currentPlayer = (i % numPlayers) + 1;
|
||||||
Marble newMarble = new Marble { Value = i + 1 };
|
Marble newMarble = new() { Value = i + 1 };
|
||||||
if ((newMarble.Value % PointValueMultiple) > 0)
|
if ((newMarble.Value % PointValueMultiple) > 0)
|
||||||
{
|
{
|
||||||
Marble previousMarble = currentMarble.Next;
|
Marble previousMarble = _currentMarble.Next;
|
||||||
Marble nextMarble = previousMarble.Next;
|
Marble nextMarble = previousMarble.Next;
|
||||||
newMarble.Previous = previousMarble;
|
newMarble.Previous = previousMarble;
|
||||||
newMarble.Next = nextMarble;
|
newMarble.Next = nextMarble;
|
||||||
previousMarble.Next = newMarble;
|
previousMarble.Next = newMarble;
|
||||||
nextMarble.Previous = newMarble;
|
nextMarble.Previous = newMarble;
|
||||||
currentMarble = newMarble;
|
_currentMarble = newMarble;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Marble marbleToRemove = currentMarble.Previous.Previous.Previous.Previous.Previous.Previous.Previous;
|
Marble marbleToRemove = _currentMarble.Previous.Previous.Previous.Previous.Previous.Previous.Previous;
|
||||||
currentMarble = marbleToRemove.Next;
|
_currentMarble = marbleToRemove.Next;
|
||||||
marbleToRemove.Previous.Next = marbleToRemove.Next;
|
marbleToRemove.Previous.Next = marbleToRemove.Next;
|
||||||
marbleToRemove.Next.Previous = marbleToRemove.Previous;
|
marbleToRemove.Next.Previous = marbleToRemove.Previous;
|
||||||
|
|
||||||
long currentPlayerScore = Scores[currentPlayer] + (newMarble.Value + marbleToRemove.Value);
|
long currentPlayerScore = Scores[_currentPlayer] + (newMarble.Value + marbleToRemove.Value);
|
||||||
Scores[currentPlayer] = currentPlayerScore;
|
Scores[_currentPlayer] = currentPlayerScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -149,11 +148,11 @@ namespace AdventOfCode2018
|
|||||||
|
|
||||||
public void PrintStatus()
|
public void PrintStatus()
|
||||||
{
|
{
|
||||||
Console.Write("[{0}] ", currentPlayer);
|
Console.Write("[{0}] ", _currentPlayer);
|
||||||
Marble marble = firstMarble;
|
Marble marble = _firstMarble;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (currentMarble.Value == marble.Value)
|
if (_currentMarble.Value == marble.Value)
|
||||||
{
|
{
|
||||||
Console.Write("({0}) ", marble.Value);
|
Console.Write("({0}) ", marble.Value);
|
||||||
}
|
}
|
||||||
@@ -171,4 +170,3 @@ namespace AdventOfCode2018
|
|||||||
return Scores.Values.Max();
|
return Scores.Values.Max();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace AdventOfCode2018
|
namespace AdventOfCode2018;
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
--- Day 10: The Stars Align ---
|
--- Day 10: The Stars Align ---
|
||||||
|
|
||||||
@@ -165,7 +164,7 @@ namespace AdventOfCode2018
|
|||||||
|
|
||||||
public string ResolvePart1(string[] inputs)
|
public string ResolvePart1(string[] inputs)
|
||||||
{
|
{
|
||||||
LightField lightField = new LightField(inputs);
|
LightField lightField = new(inputs);
|
||||||
int t = lightField.SearchSmallerBoundindBox();
|
int t = lightField.SearchSmallerBoundindBox();
|
||||||
string result = lightField.Render(t, Width, Height);
|
string result = lightField.Render(t, Width, Height);
|
||||||
return result;
|
return result;
|
||||||
@@ -173,7 +172,7 @@ namespace AdventOfCode2018
|
|||||||
|
|
||||||
public string ResolvePart2(string[] inputs)
|
public string ResolvePart2(string[] inputs)
|
||||||
{
|
{
|
||||||
LightField lightField = new LightField(inputs);
|
LightField lightField = new(inputs);
|
||||||
int t = lightField.SearchSmallerBoundindBox();
|
int t = lightField.SearchSmallerBoundindBox();
|
||||||
return t.ToString();
|
return t.ToString();
|
||||||
}
|
}
|
||||||
@@ -188,9 +187,8 @@ namespace AdventOfCode2018
|
|||||||
|
|
||||||
public static LightPoint FromString(string strPoint)
|
public static LightPoint FromString(string strPoint)
|
||||||
{
|
{
|
||||||
string[] parts = strPoint.Split(new string[] { "position=<", " ", ",", "> velocity=<", ">" }, StringSplitOptions.RemoveEmptyEntries);
|
string[] parts = strPoint.Split(new[] { "position=<", " ", ",", "> velocity=<", ">" }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
LightPoint point = new LightPoint
|
LightPoint point = new() {
|
||||||
{
|
|
||||||
X = Convert.ToInt32(parts[0]),
|
X = Convert.ToInt32(parts[0]),
|
||||||
Y = Convert.ToInt32(parts[1]),
|
Y = Convert.ToInt32(parts[1]),
|
||||||
VX = Convert.ToInt32(parts[2]),
|
VX = Convert.ToInt32(parts[2]),
|
||||||
@@ -212,11 +210,11 @@ namespace AdventOfCode2018
|
|||||||
|
|
||||||
public class LightField
|
public class LightField
|
||||||
{
|
{
|
||||||
private List<LightPoint> points;
|
private readonly List<LightPoint> _points;
|
||||||
|
|
||||||
public LightField(string[] strPoints)
|
public LightField(string[] strPoints)
|
||||||
{
|
{
|
||||||
points = strPoints.Select(strPoint => LightPoint.FromString(strPoint)).ToList();
|
_points = strPoints.Select(strPoint => LightPoint.FromString(strPoint)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int SearchSmallerBoundindBox()
|
public int SearchSmallerBoundindBox()
|
||||||
@@ -229,7 +227,7 @@ namespace AdventOfCode2018
|
|||||||
{
|
{
|
||||||
int minY = int.MaxValue;
|
int minY = int.MaxValue;
|
||||||
int maxY = int.MinValue;
|
int maxY = int.MinValue;
|
||||||
foreach (LightPoint point in points)
|
foreach (LightPoint point in _points)
|
||||||
{
|
{
|
||||||
int y = point.GetY(t);
|
int y = point.GetY(t);
|
||||||
if (y < minY) { minY = y; }
|
if (y < minY) { minY = y; }
|
||||||
@@ -259,7 +257,7 @@ namespace AdventOfCode2018
|
|||||||
int maxX = int.MinValue;
|
int maxX = int.MinValue;
|
||||||
int maxY = int.MinValue;
|
int maxY = int.MinValue;
|
||||||
|
|
||||||
foreach (LightPoint point in points)
|
foreach (LightPoint point in _points)
|
||||||
{
|
{
|
||||||
int x = point.GetX(t);
|
int x = point.GetX(t);
|
||||||
int y = point.GetY(t);
|
int y = point.GetY(t);
|
||||||
@@ -277,7 +275,7 @@ namespace AdventOfCode2018
|
|||||||
double scaleY = (maxY - minY) / (double)height;
|
double scaleY = (maxY - minY) / (double)height;
|
||||||
|
|
||||||
int[,] field = new int[width, height];
|
int[,] field = new int[width, height];
|
||||||
foreach (LightPoint point in points)
|
foreach (LightPoint point in _points)
|
||||||
{
|
{
|
||||||
int x = point.GetX(t);
|
int x = point.GetX(t);
|
||||||
int y = point.GetY(t);
|
int y = point.GetY(t);
|
||||||
@@ -288,7 +286,7 @@ namespace AdventOfCode2018
|
|||||||
field[x, y]++;
|
field[x, y]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new();
|
||||||
for (int j = 0; j < height; j++)
|
for (int j = 0; j < height; j++)
|
||||||
{
|
{
|
||||||
sb.AppendLine();
|
sb.AppendLine();
|
||||||
@@ -307,4 +305,3 @@ namespace AdventOfCode2018
|
|||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace AdventOfCode2018
|
namespace AdventOfCode2018;
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
--- Day 11: Chronal Charge ---
|
--- Day 11: Chronal Charge ---
|
||||||
@@ -83,14 +82,14 @@ namespace AdventOfCode2018
|
|||||||
{
|
{
|
||||||
int serial = Convert.ToInt32(inputs[0]);
|
int serial = Convert.ToInt32(inputs[0]);
|
||||||
SearchBestRegionOfOneSize(300, 300, 3, serial, out int x, out int y);
|
SearchBestRegionOfOneSize(300, 300, 3, serial, out int x, out int y);
|
||||||
return string.Format("{0},{1}", x, y);
|
return $"{x},{y}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ResolvePart2(string[] inputs)
|
public string ResolvePart2(string[] inputs)
|
||||||
{
|
{
|
||||||
int serial = Convert.ToInt32(inputs[0]);
|
int serial = Convert.ToInt32(inputs[0]);
|
||||||
SearchBestRegion(300, 300, serial, out int x, out int y, out int size);
|
SearchBestRegion(300, 300, serial, out int x, out int y, out int size);
|
||||||
return string.Format("{0},{1},{2}", x, y, size);
|
return $"{x},{y},{size}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int CalculatePowerLevelOfCell(int x, int y, int serial)
|
public static int CalculatePowerLevelOfCell(int x, int y, int serial)
|
||||||
@@ -223,4 +222,3 @@ namespace AdventOfCode2018
|
|||||||
size = bestSize;
|
size = bestSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace AdventOfCode2018
|
namespace AdventOfCode2018;
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
--- Day 12: Subterranean Sustainability ---
|
--- Day 12: Subterranean Sustainability ---
|
||||||
|
|
||||||
@@ -93,7 +92,7 @@ namespace AdventOfCode2018
|
|||||||
public string ResolvePart2(string[] inputs)
|
public string ResolvePart2(string[] inputs)
|
||||||
{
|
{
|
||||||
Initialize(inputs);
|
Initialize(inputs);
|
||||||
Simulate(500, false);
|
Simulate(500);
|
||||||
_offsetField -= (50000000000L - 500);
|
_offsetField -= (50000000000L - 500);
|
||||||
return CalculateChecksum().ToString();
|
return CalculateChecksum().ToString();
|
||||||
}
|
}
|
||||||
@@ -112,9 +111,9 @@ namespace AdventOfCode2018
|
|||||||
private const int SideMargin = 5;
|
private const int SideMargin = 5;
|
||||||
private const int SideProcessMargin = 2;
|
private const int SideProcessMargin = 2;
|
||||||
|
|
||||||
private List<bool> _initialState = new List<bool>();
|
private List<bool> _initialState = new();
|
||||||
private List<PlantRule> _rules = new List<PlantRule>();
|
private List<PlantRule> _rules = new();
|
||||||
private long _offsetField = 0;
|
private long _offsetField;
|
||||||
private bool[] _field;
|
private bool[] _field;
|
||||||
private bool[] _workField;
|
private bool[] _workField;
|
||||||
|
|
||||||
@@ -130,7 +129,7 @@ namespace AdventOfCode2018
|
|||||||
for (int i = 2; i < inputs.Length; i++)
|
for (int i = 2; i < inputs.Length; i++)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(inputs[i])) { continue; }
|
if (string.IsNullOrEmpty(inputs[i])) { continue; }
|
||||||
string[] parts = inputs[i].Split(new string[] { " => " }, StringSplitOptions.RemoveEmptyEntries);
|
string[] parts = inputs[i].Split(new[] { " => " }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
_rules.Add(new PlantRule
|
_rules.Add(new PlantRule
|
||||||
{
|
{
|
||||||
Minus2 = (parts[0][0] == '#'),
|
Minus2 = (parts[0][0] == '#'),
|
||||||
@@ -280,4 +279,3 @@ namespace AdventOfCode2018
|
|||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace AdventOfCode2018
|
namespace AdventOfCode2018;
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
--- Day 13: Mine Cart Madness ---
|
--- Day 13: Mine Cart Madness ---
|
||||||
@@ -222,25 +221,25 @@ namespace AdventOfCode2018
|
|||||||
public string ResolvePart1(string[] inputs)
|
public string ResolvePart1(string[] inputs)
|
||||||
{
|
{
|
||||||
Initialize(inputs);
|
Initialize(inputs);
|
||||||
Train colidingTrain = null;
|
Train collidingTrain;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (ShowProgress) { ShowGrid(); }
|
if (ShowProgress) { ShowGrid(); }
|
||||||
colidingTrain = SimulateForFirstCollision();
|
collidingTrain = SimulateForFirstCollision();
|
||||||
} while (colidingTrain == null);
|
} while (collidingTrain == null);
|
||||||
return string.Format("{0},{1}", colidingTrain.X, colidingTrain.Y);
|
return $"{collidingTrain.X},{collidingTrain.Y}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ResolvePart2(string[] inputs)
|
public string ResolvePart2(string[] inputs)
|
||||||
{
|
{
|
||||||
Initialize(inputs);
|
Initialize(inputs);
|
||||||
Train lastCart = null;
|
Train lastCart;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (ShowProgress) { ShowGrid(); }
|
if (ShowProgress) { ShowGrid(); }
|
||||||
lastCart = SimulateForLastCart();
|
lastCart = SimulateForLastCart();
|
||||||
} while (lastCart == null);
|
} while (lastCart == null);
|
||||||
return string.Format("{0},{1}", lastCart.X, lastCart.Y);
|
return $"{lastCart.X},{lastCart.Y}";
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum TrainDirection
|
private enum TrainDirection
|
||||||
@@ -249,7 +248,7 @@ namespace AdventOfCode2018
|
|||||||
South,
|
South,
|
||||||
East,
|
East,
|
||||||
West,
|
West,
|
||||||
};
|
}
|
||||||
|
|
||||||
private enum TrainTurning
|
private enum TrainTurning
|
||||||
{
|
{
|
||||||
@@ -376,8 +375,8 @@ namespace AdventOfCode2018
|
|||||||
|
|
||||||
private int _width;
|
private int _width;
|
||||||
private int _height;
|
private int _height;
|
||||||
private char[,] _grid = null;
|
private char[,] _grid;
|
||||||
private List<Train> _trains = new List<Train>();
|
private List<Train> _trains = new();
|
||||||
|
|
||||||
private void Initialize(string[] inputs)
|
private void Initialize(string[] inputs)
|
||||||
{
|
{
|
||||||
@@ -509,4 +508,3 @@ namespace AdventOfCode2018
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace AdventOfCode2018
|
namespace AdventOfCode2018;
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
--- Day 14: Chocolate Charts ---
|
--- Day 14: Chocolate Charts ---
|
||||||
@@ -63,12 +62,12 @@ namespace AdventOfCode2018
|
|||||||
|
|
||||||
public class Day14 : IDay
|
public class Day14 : IDay
|
||||||
{
|
{
|
||||||
private long _numRecipes = 0;
|
private long _numRecipes;
|
||||||
private long _numRecipesAllocated = 0;
|
private long _numRecipesAllocated;
|
||||||
private byte[] _recipes = null;
|
private byte[] _recipes;
|
||||||
private long _idxA = 0;
|
private long _idxA;
|
||||||
private long _idxB = 0;
|
private long _idxB;
|
||||||
private long _searchSkip = 0;
|
private long _searchSkip;
|
||||||
|
|
||||||
private void Init(long hintAllocation = 128)
|
private void Init(long hintAllocation = 128)
|
||||||
{
|
{
|
||||||
@@ -165,7 +164,7 @@ namespace AdventOfCode2018
|
|||||||
Step();
|
Step();
|
||||||
} while (_numRecipes < (numSkipRecipes + 10));
|
} while (_numRecipes < (numSkipRecipes + 10));
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new();
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
sb.Append(_recipes[numSkipRecipes + i]);
|
sb.Append(_recipes[numSkipRecipes + i]);
|
||||||
@@ -177,7 +176,7 @@ namespace AdventOfCode2018
|
|||||||
{
|
{
|
||||||
byte[] pattern = inputs[0].Select(c => (byte)(c - '0')).ToArray();
|
byte[] pattern = inputs[0].Select(c => (byte)(c - '0')).ToArray();
|
||||||
Init();
|
Init();
|
||||||
long position = -1;
|
long position;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (Show) { Print(); }
|
if (Show) { Print(); }
|
||||||
@@ -187,4 +186,3 @@ namespace AdventOfCode2018
|
|||||||
return position.ToString();
|
return position.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AdventOfCode2018
|
namespace AdventOfCode2018;
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
--- Day 15: Beverage Bandits ---
|
--- Day 15: Beverage Bandits ---
|
||||||
@@ -450,12 +448,12 @@ namespace AdventOfCode2018
|
|||||||
public Entity Entity { get; set; }
|
public Entity Entity { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private int _width = 0;
|
private int _width;
|
||||||
private int _height = 0;
|
private int _height;
|
||||||
private char[,] _map = null;
|
private char[,] _map;
|
||||||
private List<Entity> _entities = null;
|
private List<Entity> _entities;
|
||||||
private BreadthFirstSearchGrid _search = null;
|
private BreadthFirstSearchGrid _search;
|
||||||
private int _rounds = 0;
|
private int _rounds;
|
||||||
|
|
||||||
private void Init(string[] inputs)
|
private void Init(string[] inputs)
|
||||||
{
|
{
|
||||||
@@ -575,7 +573,7 @@ namespace AdventOfCode2018
|
|||||||
|
|
||||||
// Move
|
// Move
|
||||||
_search.SearchCharGrid(_map, '.', entity.X, entity.Y);
|
_search.SearchCharGrid(_map, '.', entity.X, entity.Y);
|
||||||
List<Target> targets = new List<Target>();
|
List<Target> targets = new();
|
||||||
int priority = 0;
|
int priority = 0;
|
||||||
foreach (Entity entityTarget in entitiesTargets)
|
foreach (Entity entityTarget in entitiesTargets)
|
||||||
{
|
{
|
||||||
@@ -623,7 +621,6 @@ namespace AdventOfCode2018
|
|||||||
if (targetInRangeAfterMove != null)
|
if (targetInRangeAfterMove != null)
|
||||||
{
|
{
|
||||||
entity.Attack(_map, targetInRangeAfterMove);
|
entity.Attack(_map, targetInRangeAfterMove);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -689,16 +686,16 @@ namespace AdventOfCode2018
|
|||||||
{
|
{
|
||||||
private class BFSCell
|
private class BFSCell
|
||||||
{
|
{
|
||||||
public bool Visited { get; set; } =false;
|
public bool Visited { get; set; }
|
||||||
public BFSCell CameFrom { get; set; } = null;
|
public BFSCell CameFrom { get; set; }
|
||||||
public int Distance { get; set; } = -1;
|
public int Distance { get; set; } = -1;
|
||||||
public int X { get; set; }
|
public int X { get; set; }
|
||||||
public int Y { get; set; }
|
public int Y { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly BFSCell[,] _grid= null;
|
private readonly BFSCell[,] _grid;
|
||||||
private readonly int _width = 0;
|
private readonly int _width;
|
||||||
private readonly int _height = 0;
|
private readonly int _height;
|
||||||
|
|
||||||
public BreadthFirstSearchGrid(int width, int height)
|
public BreadthFirstSearchGrid(int width, int height)
|
||||||
{
|
{
|
||||||
@@ -747,7 +744,7 @@ namespace AdventOfCode2018
|
|||||||
public void SearchCharGrid(char[,] grid, char empty, int x, int y)
|
public void SearchCharGrid(char[,] grid, char empty, int x, int y)
|
||||||
{
|
{
|
||||||
Reset();
|
Reset();
|
||||||
Queue<BFSCell> frontier = new Queue<BFSCell>();
|
Queue<BFSCell> frontier = new();
|
||||||
ProcessCell(grid, empty, frontier, null, x, y);
|
ProcessCell(grid, empty, frontier, null, x, y);
|
||||||
while (frontier.Any())
|
while (frontier.Any())
|
||||||
{
|
{
|
||||||
@@ -767,4 +764,3 @@ namespace AdventOfCode2018
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AdventOfCode2018
|
namespace AdventOfCode2018;
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
--- Day 23: Experimental Emergency Teleportation ---
|
--- Day 23: Experimental Emergency Teleportation ---
|
||||||
|
|
||||||
@@ -159,10 +156,9 @@ namespace AdventOfCode2018
|
|||||||
|
|
||||||
public static NanoBot FromString(string strInput)
|
public static NanoBot FromString(string strInput)
|
||||||
{
|
{
|
||||||
string[] parts = strInput.Split(new string[] { "pos=<", ",", ">, r=", }, StringSplitOptions.RemoveEmptyEntries);
|
string[] parts = strInput.Split(new[] { "pos=<", ",", ">, r=", }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
if (parts.Length != 4) { return null; }
|
if (parts.Length != 4) { return null; }
|
||||||
NanoBot nanoBot = new NanoBot
|
NanoBot nanoBot = new() {
|
||||||
{
|
|
||||||
X = Convert.ToInt64(parts[0]),
|
X = Convert.ToInt64(parts[0]),
|
||||||
Y = Convert.ToInt64(parts[1]),
|
Y = Convert.ToInt64(parts[1]),
|
||||||
Z = Convert.ToInt64(parts[2]),
|
Z = Convert.ToInt64(parts[2]),
|
||||||
@@ -205,4 +201,3 @@ namespace AdventOfCode2018
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
namespace AdventOfCode2018
|
namespace AdventOfCode2018;
|
||||||
{
|
|
||||||
public interface IDay
|
public interface IDay
|
||||||
{
|
{
|
||||||
string ResolvePart1(string[] inputs);
|
string ResolvePart1(string[] inputs);
|
||||||
string ResolvePart2(string[] inputs);
|
string ResolvePart2(string[] inputs);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace AdventOfCode2018
|
namespace AdventOfCode2018;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
private static void Main(string[] args)
|
private static void Main()
|
||||||
{
|
{
|
||||||
int currentDayNumber = 15;
|
int currentDayNumber = 15;
|
||||||
IDay currentDay = null;
|
IDay currentDay = null;
|
||||||
@@ -30,7 +30,7 @@ namespace AdventOfCode2018
|
|||||||
case 23: currentDay = new Day23(); break;
|
case 23: currentDay = new Day23(); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] linesDay = File.ReadAllLines(string.Format("inputs/Day{0:00}.txt", currentDayNumber));
|
string[] linesDay = File.ReadAllLines($"inputs/Day{currentDayNumber:00}.txt");
|
||||||
string resultPart1 = currentDay.ResolvePart1(linesDay);
|
string resultPart1 = currentDay.ResolvePart1(linesDay);
|
||||||
Console.WriteLine("Day{1:00} Result Part1: {0}", resultPart1, currentDayNumber);
|
Console.WriteLine("Day{1:00} Result Part1: {0}", resultPart1, currentDayNumber);
|
||||||
string resultPart2 = currentDay.ResolvePart2(linesDay);
|
string resultPart2 = currentDay.ResolvePart2(linesDay);
|
||||||
@@ -39,4 +39,3 @@ namespace AdventOfCode2018
|
|||||||
Console.Read();
|
Console.Read();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2020.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2020.Tests
|
|
||||||
{
|
|
||||||
public class Day01_Tests
|
public class Day01_Tests
|
||||||
{
|
{
|
||||||
#region ResolvePart1
|
#region ResolvePart1
|
||||||
@@ -11,7 +9,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day01();
|
var day = new Day01();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"1721",
|
"1721",
|
||||||
"979",
|
"979",
|
||||||
"366",
|
"366",
|
||||||
@@ -32,7 +30,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day01();
|
var day = new Day01();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] {
|
string result = day.ResolvePart2(new[] {
|
||||||
"1721",
|
"1721",
|
||||||
"979",
|
"979",
|
||||||
"366",
|
"366",
|
||||||
@@ -46,4 +44,3 @@ namespace AdventOfCode2020.Tests
|
|||||||
|
|
||||||
#endregion ResolvePart2
|
#endregion ResolvePart2
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2020.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2020.Tests
|
|
||||||
{
|
|
||||||
public class Day02_Tests
|
public class Day02_Tests
|
||||||
{
|
{
|
||||||
#region ResolvePart1
|
#region ResolvePart1
|
||||||
@@ -11,7 +9,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day02();
|
var day = new Day02();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"1-3 a: abcde",
|
"1-3 a: abcde",
|
||||||
"1-3 b: cdefg",
|
"1-3 b: cdefg",
|
||||||
"2-9 c: ccccccccc",
|
"2-9 c: ccccccccc",
|
||||||
@@ -29,7 +27,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day02();
|
var day = new Day02();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] {
|
string result = day.ResolvePart2(new[] {
|
||||||
"1-3 a: abcde",
|
"1-3 a: abcde",
|
||||||
"1-3 b: cdefg",
|
"1-3 b: cdefg",
|
||||||
"2-9 c: ccccccccc",
|
"2-9 c: ccccccccc",
|
||||||
@@ -40,4 +38,3 @@ namespace AdventOfCode2020.Tests
|
|||||||
|
|
||||||
#endregion ResolvePart1
|
#endregion ResolvePart1
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2020.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2020.Tests
|
|
||||||
{
|
|
||||||
public class Day03_Tests
|
public class Day03_Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -9,7 +7,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day03();
|
var day = new Day03();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"..##.......",
|
"..##.......",
|
||||||
"#...#...#..",
|
"#...#...#..",
|
||||||
".#....#..#.",
|
".#....#..#.",
|
||||||
@@ -31,7 +29,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day03();
|
var day = new Day03();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] {
|
string result = day.ResolvePart2(new[] {
|
||||||
"..##.......",
|
"..##.......",
|
||||||
"#...#...#..",
|
"#...#...#..",
|
||||||
".#....#..#.",
|
".#....#..#.",
|
||||||
@@ -48,4 +46,3 @@ namespace AdventOfCode2020.Tests
|
|||||||
Assert.Equal("336", result);
|
Assert.Equal("336", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2020.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2020.Tests
|
|
||||||
{
|
|
||||||
public class Day04_Tests
|
public class Day04_Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -9,7 +7,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day04();
|
var day = new Day04();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"ecl:gry pid:860033327 eyr:2020 hcl:#fffffd",
|
"ecl:gry pid:860033327 eyr:2020 hcl:#fffffd",
|
||||||
"byr:1937 iyr:2017 cid:147 hgt:183cm",
|
"byr:1937 iyr:2017 cid:147 hgt:183cm",
|
||||||
"",
|
"",
|
||||||
@@ -33,7 +31,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day04();
|
var day = new Day04();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] {
|
string result = day.ResolvePart2(new[] {
|
||||||
"eyr:1972 cid:100",
|
"eyr:1972 cid:100",
|
||||||
"hcl:#18171d ecl:amb hgt:170 pid:186cm iyr:2018 byr:1926",
|
"hcl:#18171d ecl:amb hgt:170 pid:186cm iyr:2018 byr:1926",
|
||||||
"",
|
"",
|
||||||
@@ -57,7 +55,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day04();
|
var day = new Day04();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] {
|
string result = day.ResolvePart2(new[] {
|
||||||
"pid:087499704 hgt:74in ecl:grn iyr:2012 eyr:2030 byr:1980",
|
"pid:087499704 hgt:74in ecl:grn iyr:2012 eyr:2030 byr:1980",
|
||||||
"hcl:#623a2f",
|
"hcl:#623a2f",
|
||||||
"",
|
"",
|
||||||
@@ -75,4 +73,3 @@ namespace AdventOfCode2020.Tests
|
|||||||
Assert.Equal("4", result);
|
Assert.Equal("4", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2020.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2020.Tests
|
|
||||||
{
|
|
||||||
public class Day05_Tests
|
public class Day05_Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -9,7 +7,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day05();
|
var day = new Day05();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"FBFBBFFRLR",
|
"FBFBBFFRLR",
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -21,7 +19,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day05();
|
var day = new Day05();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"BFFFBBFRRR",
|
"BFFFBBFRRR",
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -33,7 +31,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day05();
|
var day = new Day05();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"FFFBBBFRRR",
|
"FFFBBBFRRR",
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -45,11 +43,10 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day05();
|
var day = new Day05();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"BBFFBBFRLL",
|
"BBFFBBFRLL",
|
||||||
});
|
});
|
||||||
|
|
||||||
Assert.Equal("820", result);
|
Assert.Equal("820", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2020.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2020.Tests
|
|
||||||
{
|
|
||||||
public class Day06_Tests
|
public class Day06_Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -9,7 +7,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day06();
|
var day = new Day06();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"abc",
|
"abc",
|
||||||
"",
|
"",
|
||||||
"a",
|
"a",
|
||||||
@@ -35,7 +33,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day06();
|
var day = new Day06();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] {
|
string result = day.ResolvePart2(new[] {
|
||||||
"abc",
|
"abc",
|
||||||
"",
|
"",
|
||||||
"a",
|
"a",
|
||||||
@@ -56,4 +54,3 @@ namespace AdventOfCode2020.Tests
|
|||||||
Assert.Equal("6", result);
|
Assert.Equal("6", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2020.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2020.Tests
|
|
||||||
{
|
|
||||||
public class Day07_Tests
|
public class Day07_Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -9,7 +7,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day07();
|
var day = new Day07();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"light red bags contain 1 bright white bag, 2 muted yellow bags.",
|
"light red bags contain 1 bright white bag, 2 muted yellow bags.",
|
||||||
"dark orange bags contain 3 bright white bags, 4 muted yellow bags.",
|
"dark orange bags contain 3 bright white bags, 4 muted yellow bags.",
|
||||||
"bright white bags contain 1 shiny gold bag.",
|
"bright white bags contain 1 shiny gold bag.",
|
||||||
@@ -29,7 +27,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day07();
|
var day = new Day07();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] {
|
string result = day.ResolvePart2(new[] {
|
||||||
"shiny gold bags contain 2 dark red bags.",
|
"shiny gold bags contain 2 dark red bags.",
|
||||||
"dark red bags contain 2 dark orange bags.",
|
"dark red bags contain 2 dark orange bags.",
|
||||||
"dark orange bags contain 2 dark yellow bags.",
|
"dark orange bags contain 2 dark yellow bags.",
|
||||||
@@ -42,4 +40,3 @@ namespace AdventOfCode2020.Tests
|
|||||||
Assert.Equal("126", result);
|
Assert.Equal("126", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2020.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2020.Tests
|
|
||||||
{
|
|
||||||
public class Day08_Tests
|
public class Day08_Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -9,7 +7,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day08();
|
var day = new Day08();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"nop +0",
|
"nop +0",
|
||||||
"acc +1",
|
"acc +1",
|
||||||
"jmp +4",
|
"jmp +4",
|
||||||
@@ -29,7 +27,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day08();
|
var day = new Day08();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] {
|
string result = day.ResolvePart2(new[] {
|
||||||
"nop +0",
|
"nop +0",
|
||||||
"acc +1",
|
"acc +1",
|
||||||
"jmp +4",
|
"jmp +4",
|
||||||
@@ -44,4 +42,3 @@ namespace AdventOfCode2020.Tests
|
|||||||
Assert.Equal("8", result);
|
Assert.Equal("8", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2020.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2020.Tests
|
|
||||||
{
|
|
||||||
public class Day09_Tests
|
public class Day09_Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -9,7 +7,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day09();
|
var day = new Day09();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"35",
|
"35",
|
||||||
"20",
|
"20",
|
||||||
"15",
|
"15",
|
||||||
@@ -40,7 +38,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day09();
|
var day = new Day09();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] {
|
string result = day.ResolvePart2(new[] {
|
||||||
"35",
|
"35",
|
||||||
"20",
|
"20",
|
||||||
"15",
|
"15",
|
||||||
@@ -66,4 +64,3 @@ namespace AdventOfCode2020.Tests
|
|||||||
Assert.Equal("62", result);
|
Assert.Equal("62", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2020.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2020.Tests
|
|
||||||
{
|
|
||||||
public class Day10_Tests
|
public class Day10_Tests
|
||||||
{
|
{
|
||||||
[Fact(Skip="Not implemented")]
|
[Fact(Skip="Not implemented")]
|
||||||
@@ -9,7 +7,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day10();
|
var day = new Day10();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"XXXXXXXXXXXXXXX",
|
"XXXXXXXXXXXXXXX",
|
||||||
"XXXXXXXXXXXXXXX",
|
"XXXXXXXXXXXXXXX",
|
||||||
"XXXXXXXXXXXXXXX",
|
"XXXXXXXXXXXXXXX",
|
||||||
@@ -28,7 +26,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day09();
|
var day = new Day09();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] {
|
string result = day.ResolvePart2(new[] {
|
||||||
"XXXXXXXXXXXXXXX",
|
"XXXXXXXXXXXXXXX",
|
||||||
"XXXXXXXXXXXXXXX",
|
"XXXXXXXXXXXXXXX",
|
||||||
"XXXXXXXXXXXXXXX",
|
"XXXXXXXXXXXXXXX",
|
||||||
@@ -42,4 +40,3 @@ namespace AdventOfCode2020.Tests
|
|||||||
Assert.Equal("YYY", result);
|
Assert.Equal("YYY", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
using Xunit;
|
namespace AdventOfCode2020.Tests;
|
||||||
|
|
||||||
namespace AdventOfCode2020.Tests
|
|
||||||
{
|
|
||||||
public class Day11_Tests
|
public class Day11_Tests
|
||||||
{
|
{
|
||||||
[Fact(Skip="Not implemented")]
|
[Fact(Skip="Not implemented")]
|
||||||
@@ -9,7 +7,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day11();
|
var day = new Day11();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"XXXXXXXXXXXXXXX",
|
"XXXXXXXXXXXXXXX",
|
||||||
"XXXXXXXXXXXXXXX",
|
"XXXXXXXXXXXXXXX",
|
||||||
"XXXXXXXXXXXXXXX",
|
"XXXXXXXXXXXXXXX",
|
||||||
@@ -28,7 +26,7 @@ namespace AdventOfCode2020.Tests
|
|||||||
{
|
{
|
||||||
var day = new Day11();
|
var day = new Day11();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] {
|
string result = day.ResolvePart2(new[] {
|
||||||
"XXXXXXXXXXXXXXX",
|
"XXXXXXXXXXXXXXX",
|
||||||
"XXXXXXXXXXXXXXX",
|
"XXXXXXXXXXXXXXX",
|
||||||
"XXXXXXXXXXXXXXX",
|
"XXXXXXXXXXXXXXX",
|
||||||
@@ -42,4 +40,3 @@ namespace AdventOfCode2020.Tests
|
|||||||
Assert.Equal("YYY", result);
|
Assert.Equal("YYY", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
1
AdventOfCode2020.Tests/Usings.cs
Normal file
1
AdventOfCode2020.Tests/Usings.cs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
global using Xunit;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace AdventOfCode2020
|
namespace AdventOfCode2020;
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
--- Day 1: Report Repair ---
|
--- Day 1: Report Repair ---
|
||||||
|
|
||||||
@@ -86,4 +86,3 @@ In your expense report, what is the product of the three entries that sum to 202
|
|||||||
return result.ToString();
|
return result.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace AdventOfCode2020
|
namespace AdventOfCode2020;
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
--- Day 2: Password Philosophy ---
|
--- Day 2: Password Philosophy ---
|
||||||
|
|
||||||
@@ -89,4 +88,3 @@ How many passwords are valid according to the new interpretation of the policies
|
|||||||
return cntValid.ToString();
|
return cntValid.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -74,8 +74,8 @@ What do you get if you multiply together the number of trees encountered on each
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace AdventOfCode2020
|
namespace AdventOfCode2020;
|
||||||
{
|
|
||||||
public class Day03 : IDay
|
public class Day03 : IDay
|
||||||
{
|
{
|
||||||
public string ResolvePart1(string[] inputs)
|
public string ResolvePart1(string[] inputs)
|
||||||
@@ -114,4 +114,3 @@ namespace AdventOfCode2020
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -124,16 +124,15 @@ Count the number of valid passports - those that have all required fields and va
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace AdventOfCode2020
|
namespace AdventOfCode2020;
|
||||||
{
|
|
||||||
public class Day04 : IDay
|
public class Day04 : IDay
|
||||||
{
|
{
|
||||||
public string ResolvePart1(string[] inputs)
|
public string ResolvePart1(string[] inputs)
|
||||||
{
|
{
|
||||||
List<Dictionary<string, string>> passports = Passports_Parse(inputs);
|
List<Dictionary<string, string>> passports = Passports_Parse(inputs);
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
List<string> neededFields = new List<string>
|
List<string> neededFields = new() {
|
||||||
{
|
|
||||||
"byr", // Birth Year
|
"byr", // Birth Year
|
||||||
"iyr", // Issue Year
|
"iyr", // Issue Year
|
||||||
"eyr", // Expiration Year
|
"eyr", // Expiration Year
|
||||||
@@ -173,8 +172,8 @@ namespace AdventOfCode2020
|
|||||||
|
|
||||||
private List<Dictionary<string, string>> Passports_Parse(string[] inputs)
|
private List<Dictionary<string, string>> Passports_Parse(string[] inputs)
|
||||||
{
|
{
|
||||||
List<Dictionary<string, string>> passports = new List<Dictionary<string, string>>();
|
List<Dictionary<string, string>> passports = new();
|
||||||
Dictionary<string, string> passport = new Dictionary<string, string>();
|
Dictionary<string, string> passport = new();
|
||||||
foreach (string input in inputs)
|
foreach (string input in inputs)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(input))
|
if (string.IsNullOrEmpty(input))
|
||||||
@@ -265,4 +264,3 @@ namespace AdventOfCode2020
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ What is the ID of your seat?
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace AdventOfCode2020
|
namespace AdventOfCode2020;
|
||||||
{
|
|
||||||
public class Day05 : IDay
|
public class Day05 : IDay
|
||||||
{
|
{
|
||||||
public string ResolvePart1(string[] inputs)
|
public string ResolvePart1(string[] inputs)
|
||||||
@@ -130,7 +130,7 @@ namespace AdventOfCode2020
|
|||||||
}
|
}
|
||||||
if (neighbourCount == 8)
|
if (neighbourCount == 8)
|
||||||
{
|
{
|
||||||
Seat mySeat = new Seat { Row = j, Column = i, };
|
Seat mySeat = new() { Row = j, Column = i, };
|
||||||
mySeatSerialNumber = mySeat.GetSerialNumber();
|
mySeatSerialNumber = mySeat.GetSerialNumber();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -178,9 +178,9 @@ namespace AdventOfCode2020
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Seat seat = new Seat();
|
Seat seat = new();
|
||||||
|
|
||||||
Range row = new Range { Start = 0, End = 127, };
|
Range row = new() { Start = 0, End = 127, };
|
||||||
for (int i = 0; i < 7; i++)
|
for (int i = 0; i < 7; i++)
|
||||||
{
|
{
|
||||||
if (input[i] == 'F')
|
if (input[i] == 'F')
|
||||||
@@ -194,7 +194,7 @@ namespace AdventOfCode2020
|
|||||||
}
|
}
|
||||||
seat.Row = row.Start;
|
seat.Row = row.Start;
|
||||||
|
|
||||||
Range column = new Range { Start = 0, End = 7, };
|
Range column = new() { Start = 0, End = 7, };
|
||||||
for (int i = 7; i < 10; i++)
|
for (int i = 7; i < 10; i++)
|
||||||
{
|
{
|
||||||
if (input[i] == 'L')
|
if (input[i] == 'L')
|
||||||
@@ -211,4 +211,3 @@ namespace AdventOfCode2020
|
|||||||
return seat;
|
return seat;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -52,14 +52,14 @@ For each group, count the number of questions to which anyone answered "yes". Wh
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace AdventOfCode2020
|
namespace AdventOfCode2020;
|
||||||
{
|
|
||||||
public class Day06 : IDay
|
public class Day06 : IDay
|
||||||
{
|
{
|
||||||
public string ResolvePart1(string[] inputs)
|
public string ResolvePart1(string[] inputs)
|
||||||
{
|
{
|
||||||
Dictionary<char, bool> groupMap = new Dictionary<char, bool>();
|
Dictionary<char, bool> groupMap = new();
|
||||||
List<Dictionary<char, bool>> groupMaps = new List<Dictionary<char, bool>>();
|
List<Dictionary<char, bool>> groupMaps = new();
|
||||||
foreach (string input in inputs)
|
foreach (string input in inputs)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(input) && groupMap.Count > 0)
|
if (string.IsNullOrEmpty(input) && groupMap.Count > 0)
|
||||||
@@ -90,8 +90,8 @@ namespace AdventOfCode2020
|
|||||||
public string ResolvePart2(string[] inputs)
|
public string ResolvePart2(string[] inputs)
|
||||||
{
|
{
|
||||||
int groupCount = 0;
|
int groupCount = 0;
|
||||||
Dictionary<char, int> groupMap = new Dictionary<char, int>();
|
Dictionary<char, int> groupMap = new();
|
||||||
List<Tuple<int, Dictionary<char, int>>> groupMaps = new List<Tuple<int, Dictionary<char, int>>>();
|
List<Tuple<int, Dictionary<char, int>>> groupMaps = new();
|
||||||
foreach (string input in inputs)
|
foreach (string input in inputs)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(input) && groupCount > 0)
|
if (string.IsNullOrEmpty(input) && groupCount > 0)
|
||||||
@@ -127,4 +127,3 @@ namespace AdventOfCode2020
|
|||||||
return total.ToString();
|
return total.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -68,23 +68,23 @@ How many individual bags are required inside your single shiny gold bag?
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace AdventOfCode2020
|
namespace AdventOfCode2020;
|
||||||
{
|
|
||||||
public class Day07 : IDay
|
public class Day07 : IDay
|
||||||
{
|
{
|
||||||
public string ResolvePart1(string[] inputs)
|
public string ResolvePart1(string[] inputs)
|
||||||
{
|
{
|
||||||
string myBagColor = "shiny gold";
|
string myBagColor = "shiny gold";
|
||||||
|
|
||||||
List<BaggageRule> rules = new List<BaggageRule>();
|
List<BaggageRule> rules = new();
|
||||||
foreach (string input in inputs)
|
foreach (string input in inputs)
|
||||||
{
|
{
|
||||||
BaggageRule rule = BaggageRule_Parse(input);
|
BaggageRule rule = BaggageRule_Parse(input);
|
||||||
rules.Add(rule);
|
rules.Add(rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<string> bagColorsToCheck = new List<string> { myBagColor };
|
List<string> bagColorsToCheck = new() { myBagColor };
|
||||||
List<string> bagColorsChecked = new List<string> { myBagColor };
|
List<string> bagColorsChecked = new() { myBagColor };
|
||||||
int cntBagColors = 0;
|
int cntBagColors = 0;
|
||||||
while (bagColorsToCheck.Count > 0)
|
while (bagColorsToCheck.Count > 0)
|
||||||
{
|
{
|
||||||
@@ -112,7 +112,7 @@ namespace AdventOfCode2020
|
|||||||
{
|
{
|
||||||
string myBagColor = "shiny gold";
|
string myBagColor = "shiny gold";
|
||||||
|
|
||||||
List<BaggageRule> rules = new List<BaggageRule>();
|
List<BaggageRule> rules = new();
|
||||||
foreach (string input in inputs)
|
foreach (string input in inputs)
|
||||||
{
|
{
|
||||||
BaggageRule rule = BaggageRule_Parse(input);
|
BaggageRule rule = BaggageRule_Parse(input);
|
||||||
@@ -142,7 +142,7 @@ namespace AdventOfCode2020
|
|||||||
{
|
{
|
||||||
string[] words = input.Split(' ');
|
string[] words = input.Split(' ');
|
||||||
string status = "Parse Color 1";
|
string status = "Parse Color 1";
|
||||||
BaggageRule rule = new BaggageRule();
|
BaggageRule rule = new();
|
||||||
rule.Contain = new List<BaggageContainRule>();
|
rule.Contain = new List<BaggageContainRule>();
|
||||||
BaggageContainRule containRule = null;
|
BaggageContainRule containRule = null;
|
||||||
string color1 = string.Empty;
|
string color1 = string.Empty;
|
||||||
@@ -204,4 +204,3 @@ namespace AdventOfCode2020
|
|||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -93,20 +93,20 @@ Fix the program so that it terminates normally by changing exactly one jmp (to n
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace AdventOfCode2020
|
namespace AdventOfCode2020;
|
||||||
{
|
|
||||||
public class Day08 : IDay
|
public class Day08 : IDay
|
||||||
{
|
{
|
||||||
public string ResolvePart1(string[] inputs)
|
public string ResolvePart1(string[] inputs)
|
||||||
{
|
{
|
||||||
VM vm = new VM(inputs);
|
VM vm = new(inputs);
|
||||||
vm.Run();
|
vm.Run();
|
||||||
return vm.Accumulator.ToString();
|
return vm.Accumulator.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ResolvePart2(string[] inputs)
|
public string ResolvePart2(string[] inputs)
|
||||||
{
|
{
|
||||||
VM vm = new VM(inputs);
|
VM vm = new(inputs);
|
||||||
foreach (Instruction instruction in vm.Instructions)
|
foreach (Instruction instruction in vm.Instructions)
|
||||||
{
|
{
|
||||||
if (instruction.OpCode == OpCode.Acc) { continue; }
|
if (instruction.OpCode == OpCode.Acc) { continue; }
|
||||||
@@ -133,7 +133,7 @@ namespace AdventOfCode2020
|
|||||||
Acc,
|
Acc,
|
||||||
Jmp,
|
Jmp,
|
||||||
Nop,
|
Nop,
|
||||||
};
|
}
|
||||||
|
|
||||||
public class Instruction
|
public class Instruction
|
||||||
{
|
{
|
||||||
@@ -170,7 +170,7 @@ namespace AdventOfCode2020
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class VM
|
private class VM
|
||||||
{
|
{
|
||||||
public List<Instruction> Instructions { get; set; }
|
public List<Instruction> Instructions { get; set; }
|
||||||
|
|
||||||
@@ -226,4 +226,3 @@ namespace AdventOfCode2020
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -91,8 +91,8 @@ What is the encryption weakness in your XMAS-encrypted list of numbers?
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace AdventOfCode2020
|
namespace AdventOfCode2020;
|
||||||
{
|
|
||||||
public class Day09 : IDay
|
public class Day09 : IDay
|
||||||
{
|
{
|
||||||
public string ResolvePart1(string[] inputs)
|
public string ResolvePart1(string[] inputs)
|
||||||
@@ -170,4 +170,3 @@ namespace AdventOfCode2020
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -91,8 +91,8 @@ Find a chain that uses all of your adapters to connect the charging outlet to yo
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace AdventOfCode2020
|
namespace AdventOfCode2020;
|
||||||
{
|
|
||||||
public class Day10 : IDay
|
public class Day10 : IDay
|
||||||
{
|
{
|
||||||
public string ResolvePart1(string[] inputs)
|
public string ResolvePart1(string[] inputs)
|
||||||
@@ -105,4 +105,3 @@ namespace AdventOfCode2020
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace AdventOfCode2020
|
namespace AdventOfCode2020;
|
||||||
{
|
|
||||||
public class Day11 : IDay
|
public class Day11 : IDay
|
||||||
{
|
{
|
||||||
public string ResolvePart1(string[] inputs)
|
public string ResolvePart1(string[] inputs)
|
||||||
@@ -21,4 +21,3 @@ namespace AdventOfCode2020
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
namespace AdventOfCode2020
|
namespace AdventOfCode2020;
|
||||||
{
|
|
||||||
public interface IDay
|
public interface IDay
|
||||||
{
|
{
|
||||||
string ResolvePart1(string[] inputs);
|
string ResolvePart1(string[] inputs);
|
||||||
string ResolvePart2(string[] inputs);
|
string ResolvePart2(string[] inputs);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace AdventOfCode2020
|
namespace AdventOfCode2020;
|
||||||
{
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main()
|
||||||
{
|
{
|
||||||
int currentDayNumber = 0;
|
int currentDayNumber = 0;
|
||||||
|
|
||||||
@@ -22,12 +22,12 @@ namespace AdventOfCode2020
|
|||||||
|
|
||||||
public static void RunDay(int currentDayNumber)
|
public static void RunDay(int currentDayNumber)
|
||||||
{
|
{
|
||||||
Console.WriteLine(string.Format("Day {0:00}", currentDayNumber));
|
Console.WriteLine($"Day {currentDayNumber:00}");
|
||||||
Console.WriteLine("------");
|
Console.WriteLine("------");
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
|
|
||||||
IDay currentDay = null;
|
IDay currentDay = null;
|
||||||
Type dayType = Type.GetType(string.Format("AdventOfCode2020.Day{0:00}", currentDayNumber));
|
Type dayType = Type.GetType($"AdventOfCode2020.Day{currentDayNumber:00}");
|
||||||
if (dayType != null)
|
if (dayType != null)
|
||||||
{
|
{
|
||||||
currentDay = Activator.CreateInstance(dayType) as IDay;
|
currentDay = Activator.CreateInstance(dayType) as IDay;
|
||||||
@@ -39,7 +39,7 @@ namespace AdventOfCode2020
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] linesDay = File.ReadAllLines(string.Format("inputs/Day{0:00}.txt", currentDayNumber));
|
string[] linesDay = File.ReadAllLines($"inputs/Day{currentDayNumber:00}.txt");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string resultPart1 = currentDay.ResolvePart1(linesDay);
|
string resultPart1 = currentDay.ResolvePart1(linesDay);
|
||||||
@@ -63,4 +63,3 @@ namespace AdventOfCode2020
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ public class Day01_Tests
|
|||||||
{
|
{
|
||||||
var day = new Day01();
|
var day = new Day01();
|
||||||
|
|
||||||
string result = day.ResolvePart1(new string[] {
|
string result = day.ResolvePart1(new[] {
|
||||||
"1abc2",
|
"1abc2",
|
||||||
"pqr3stu8vwx",
|
"pqr3stu8vwx",
|
||||||
"a1b2c3d4e5f",
|
"a1b2c3d4e5f",
|
||||||
@@ -22,7 +22,7 @@ public class Day01_Tests
|
|||||||
{
|
{
|
||||||
var day = new Day01();
|
var day = new Day01();
|
||||||
|
|
||||||
string result = day.ResolvePart2(new string[] {
|
string result = day.ResolvePart2(new[] {
|
||||||
"two1nine",
|
"two1nine",
|
||||||
"eightwothree",
|
"eightwothree",
|
||||||
"abcone2threexyz",
|
"abcone2threexyz",
|
||||||
|
|||||||
@@ -78,8 +78,7 @@ public class Day01 : IDay
|
|||||||
|
|
||||||
public string ResolvePart2(string[] inputs)
|
public string ResolvePart2(string[] inputs)
|
||||||
{
|
{
|
||||||
List<(string Text, int Value)> digits = new List<(string Text, int Value)>
|
List<(string Text, int Value)> digits = new() {
|
||||||
{
|
|
||||||
("1", 1),
|
("1", 1),
|
||||||
("2", 2),
|
("2", 2),
|
||||||
("3", 3),
|
("3", 3),
|
||||||
|
|||||||
Reference in New Issue
Block a user