From d86a65dec5ad4fabece8ddcf1bf9c30d7847ba52 Mon Sep 17 00:00:00 2001 From: Rob Date: Mon, 5 Dec 2022 20:00:56 +0100 Subject: [PATCH] Removed utils class, changed interface to abstract and incorparated util methods. Added Day 5 --- Advend Of Code Runner/Program.cs | 2 +- .../2022/Day 01/Day01Part1.cs | 12 +- .../2022/Day 01/Day01Part2.cs | 13 +- .../2022/Day 02/Day02Part1.cs | 12 +- .../2022/Day 02/Day02Part2.cs | 12 +- .../2022/Day 03/Day03Part1.cs | 12 +- .../2022/Day 03/Day03Part2.cs | 12 +- .../2022/Day 04/Day04Part1.cs | 12 +- .../2022/Day 04/Day04Part2.cs | 12 +- .../2022/Day 05/CraneWork.cs | 84 +++ .../2022/Day 05/Day05Part1.cs | 25 + .../2022/Day 05/Day05Part2.cs | 25 + .../2022/Day 05/day-05-input.txt | 513 ++++++++++++++++++ Advent Of Code Library/Shared/Answerable.cs | 26 + .../Shared/AnswerableListBuilder.cs | 10 +- Advent Of Code Library/Shared/ByteHelper.cs | 11 - Advent Of Code Library/Shared/IAnswerable.cs | 20 - 17 files changed, 727 insertions(+), 86 deletions(-) create mode 100644 Advent Of Code Library/2022/Day 05/CraneWork.cs create mode 100644 Advent Of Code Library/2022/Day 05/Day05Part1.cs create mode 100644 Advent Of Code Library/2022/Day 05/Day05Part2.cs create mode 100644 Advent Of Code Library/2022/Day 05/day-05-input.txt create mode 100644 Advent Of Code Library/Shared/Answerable.cs delete mode 100644 Advent Of Code Library/Shared/ByteHelper.cs delete mode 100644 Advent Of Code Library/Shared/IAnswerable.cs diff --git a/Advend Of Code Runner/Program.cs b/Advend Of Code Runner/Program.cs index f41e82c..c8e430f 100644 --- a/Advend Of Code Runner/Program.cs +++ b/Advend Of Code Runner/Program.cs @@ -8,7 +8,7 @@ string _demoData = @"2-4,6-8 6-6,4-6 2-6,4-8"; -IAnswerable answerable = new Day04Part1(); +Answerable answerable = new Day05Part2(); byte[] dataArray = File.ReadAllBytes(answerable.DefaultInputFile); //dataArray = Encoding.UTF8.GetBytes(_demoData); diff --git a/Advent Of Code Library/2022/Day 01/Day01Part1.cs b/Advent Of Code Library/2022/Day 01/Day01Part1.cs index 26bfadf..278556e 100644 --- a/Advent Of Code Library/2022/Day 01/Day01Part1.cs +++ b/Advent Of Code Library/2022/Day 01/Day01Part1.cs @@ -2,15 +2,15 @@ { using AdventOfCodeLibrary.Shared; - public class Day01Part1 : IAnswerable + public class Day01Part1 : Answerable { - public int Year { get; set; } = 2022; - public int Day { get; set; } = 1; - public int Part { get; set; } = 1; + public override int Year { get; set; } = 2022; + public override int Day { get; set; } = 1; + public override int Part { get; set; } = 1; - public string GetAwner(byte[] data) + public override string GetAwner(byte[] data) { - return ByteHelper.GetAsString(data).TrimEnd() + return GetAsString(data).TrimEnd() .Split(Environment.NewLine + Environment.NewLine) .Select(s => s.Split(Environment.NewLine) .Sum(Convert.ToInt32)) diff --git a/Advent Of Code Library/2022/Day 01/Day01Part2.cs b/Advent Of Code Library/2022/Day 01/Day01Part2.cs index 5287fb8..28ea161 100644 --- a/Advent Of Code Library/2022/Day 01/Day01Part2.cs +++ b/Advent Of Code Library/2022/Day 01/Day01Part2.cs @@ -2,16 +2,15 @@ { using AdventOfCodeLibrary.Shared; - public class Day01Part2 : IAnswerable + public class Day01Part2 : Answerable { - public int Year { get; set; } = 2022; - public int Day { get; set; } = 1; - public int Part { get; set; } = 2; - public string DefaultInputFile { get; set; } = "Day 01/day-01-input.txt"; + public override int Year { get; set; } = 2022; + public override int Day { get; set; } = 1; + public override int Part { get; set; } = 2; - public string GetAwner(byte[] data) + public override string GetAwner(byte[] data) { - return ByteHelper.GetAsString(data).TrimEnd() + return GetAsString(data).TrimEnd() .TrimEnd() .Split(Environment.NewLine + Environment.NewLine) .Select(s => s.Split(Environment.NewLine) diff --git a/Advent Of Code Library/2022/Day 02/Day02Part1.cs b/Advent Of Code Library/2022/Day 02/Day02Part1.cs index be63954..eb438ab 100644 --- a/Advent Of Code Library/2022/Day 02/Day02Part1.cs +++ b/Advent Of Code Library/2022/Day 02/Day02Part1.cs @@ -3,16 +3,16 @@ using AdventOfCodeLibrary._2022.Day02; using AdventOfCodeLibrary.Shared; - public class Day02Part1 : IAnswerable + public class Day02Part1 : Answerable { - public int Year { get; set; } = 2022; - public int Day { get; set; } = 2; - public int Part { get; set; } = 1; + public override int Year { get; set; } = 2022; + public override int Day { get; set; } = 2; + public override int Part { get; set; } = 1; - public string GetAwner(byte[] data) + public override string GetAwner(byte[] data) { GameRules.BuildScoreDic(); - return ByteHelper.GetAsStringArray(data) + return GetAsStringArray(data) .Select(GameRules.GetScore) .Sum() .ToString(); diff --git a/Advent Of Code Library/2022/Day 02/Day02Part2.cs b/Advent Of Code Library/2022/Day 02/Day02Part2.cs index 2e34b00..b888f01 100644 --- a/Advent Of Code Library/2022/Day 02/Day02Part2.cs +++ b/Advent Of Code Library/2022/Day 02/Day02Part2.cs @@ -3,16 +3,16 @@ using AdventOfCodeLibrary._2022.Day02; using AdventOfCodeLibrary.Shared; - public class Day02Part2 : IAnswerable + public class Day02Part2 : Answerable { - public int Year { get; set; } = 2022; - public int Day { get; set; } = 2; - public int Part { get; set; } = 2; + public override int Year { get; set; } = 2022; + public override int Day { get; set; } = 2; + public override int Part { get; set; } = 2; - public string GetAwner(byte[] data) + public override string GetAwner(byte[] data) { GameRules.BuildWinDrawLoseTable(); - return ByteHelper.GetAsStringArray(data) + return GetAsStringArray(data) .Select(GameRules.GetScore) .Sum() .ToString(); diff --git a/Advent Of Code Library/2022/Day 03/Day03Part1.cs b/Advent Of Code Library/2022/Day 03/Day03Part1.cs index c4d8e3a..eda432b 100644 --- a/Advent Of Code Library/2022/Day 03/Day03Part1.cs +++ b/Advent Of Code Library/2022/Day 03/Day03Part1.cs @@ -2,15 +2,15 @@ { using AdventOfCodeLibrary.Shared; - public class Day03Part1 : IAnswerable + public class Day03Part1 : Answerable { - public int Year { get; set; } = 2022; - public int Day { get; set; } = 3; - public int Part { get; set; } = 1; + public override int Year { get; set; } = 2022; + public override int Day { get; set; } = 3; + public override int Part { get; set; } = 1; - public string GetAwner(byte[] data) + public override string GetAwner(byte[] data) { - string[] rucksackData = ByteHelper.GetAsStringArray(data); + string[] rucksackData = GetAsStringArray(data); int priorityCount = 0; // go throu each ruchsack diff --git a/Advent Of Code Library/2022/Day 03/Day03Part2.cs b/Advent Of Code Library/2022/Day 03/Day03Part2.cs index 3f10277..016c27e 100644 --- a/Advent Of Code Library/2022/Day 03/Day03Part2.cs +++ b/Advent Of Code Library/2022/Day 03/Day03Part2.cs @@ -2,15 +2,15 @@ { using AdventOfCodeLibrary.Shared; - public class Day03Part2 : IAnswerable + public class Day03Part2 : Answerable { - public int Year { get; set; } = 2022; - public int Day { get; set; } = 3; - public int Part { get; set; } = 2; + public override int Year { get; set; } = 2022; + public override int Day { get; set; } = 3; + public override int Part { get; set; } = 2; - public string GetAwner(byte[] data) + public override string GetAwner(byte[] data) { - string[] rucksackData = ByteHelper.GetAsStringArray(data); + string[] rucksackData = GetAsStringArray(data); int priorityCount = 0; // go throu each ruchsack diff --git a/Advent Of Code Library/2022/Day 04/Day04Part1.cs b/Advent Of Code Library/2022/Day 04/Day04Part1.cs index 54eb3e8..27e4a5d 100644 --- a/Advent Of Code Library/2022/Day 04/Day04Part1.cs +++ b/Advent Of Code Library/2022/Day 04/Day04Part1.cs @@ -2,15 +2,15 @@ { using AdventOfCodeLibrary.Shared; - public class Day04Part1 : IAnswerable + public class Day04Part1 : Answerable { - public int Year { get; set; } = 2022; - public int Day { get; set; } = 4; - public int Part { get; set; } = 1; + public override int Year { get; set; } = 2022; + public override int Day { get; set; } = 4; + public override int Part { get; set; } = 1; - public string GetAwner(byte[] data) + public override string GetAwner(byte[] data) { - return ByteHelper.GetAsStringArray(data) + return GetAsStringArray(data) .Where(line => !string.IsNullOrWhiteSpace(line)) .Select(line => line.Split(',') diff --git a/Advent Of Code Library/2022/Day 04/Day04Part2.cs b/Advent Of Code Library/2022/Day 04/Day04Part2.cs index 59e3d10..1de9733 100644 --- a/Advent Of Code Library/2022/Day 04/Day04Part2.cs +++ b/Advent Of Code Library/2022/Day 04/Day04Part2.cs @@ -2,15 +2,15 @@ { using AdventOfCodeLibrary.Shared; - public class Day04Part2 : IAnswerable + public class Day04Part2 : Answerable { - public int Year { get; set; } = 2022; - public int Day { get; set; } = 4; - public int Part { get; set; } = 2; + public override int Year { get; set; } = 2022; + public override int Day { get; set; } = 4; + public override int Part { get; set; } = 2; - public string GetAwner(byte[] data) + public override string GetAwner(byte[] data) { - return ByteHelper.GetAsStringArray(data) + return GetAsStringArray(data) .Where(line => !string.IsNullOrWhiteSpace(line)) .Select(line => line.Split(',') diff --git a/Advent Of Code Library/2022/Day 05/CraneWork.cs b/Advent Of Code Library/2022/Day 05/CraneWork.cs new file mode 100644 index 0000000..61d67cc --- /dev/null +++ b/Advent Of Code Library/2022/Day 05/CraneWork.cs @@ -0,0 +1,84 @@ +using System.ComponentModel; + +namespace AdventOfCodeLibrary._2022.Day_05 +{ + internal class CraneWork + { + private List> containerStacks = new List>(); + + internal void ReadInitialContainerArrangement(string[] data) + { + // get all the existing stacks + string stackNumbers = data[data.Length - 1]; + string[] containerStacksWithoutNumbser = data.Take(data.Length - 1).ToArray(); + for (int stackIndex = 0; stackIndex < stackNumbers.Length; stackIndex++) + { + if (stackNumbers[stackIndex] == ' ') + { + continue; + } + + Stack stack = new Stack(); + for (int containerIndex = containerStacksWithoutNumbser.Length - 1; containerIndex >= 0; containerIndex--) + { + char container = containerStacksWithoutNumbser[containerIndex][stackIndex]; + if (container != ' ') + { + stack.Push(container); + } + else + { + break; + } + } + + + containerStacks.Add(stack); + } + } + + internal void DoCraneWork(string craneInstruction, bool is9000Crane = true) + { + string[] instructions = craneInstruction.Split(' '); + int numberToMove = Convert.ToInt32(instructions[1]); + + // remove one because zero based index + int fromContainerStackIndex = Convert.ToInt32(instructions[3]) - 1; + int toContainerStackIndex = Convert.ToInt32(instructions[5]) - 1; + Stack storage = new Stack(); + + for (int toMove = numberToMove; toMove > 0; toMove--) + { + if (is9000Crane) + { + containerStacks[toContainerStackIndex].Push(containerStacks[fromContainerStackIndex].Pop()); + } + else + { + // make a stack to store the containers in order + storage.Push(containerStacks[fromContainerStackIndex].Pop()); + } + } + + if (!is9000Crane) + { + // move the stored conainers to the new pile + for (int toMove = numberToMove; toMove > 0; toMove--) + { + containerStacks[toContainerStackIndex].Push(storage.Pop()); + } + } + } + + internal string GetTopContainers() + { + string result = string.Empty; + foreach (char topContainer in containerStacks.Select(s => s.Peek())) + { + result += topContainer; + } + + return result; + } + } +} diff --git a/Advent Of Code Library/2022/Day 05/Day05Part1.cs b/Advent Of Code Library/2022/Day 05/Day05Part1.cs new file mode 100644 index 0000000..db5653b --- /dev/null +++ b/Advent Of Code Library/2022/Day 05/Day05Part1.cs @@ -0,0 +1,25 @@ +namespace AdventOfCodeLibrary._2022 +{ + using AdventOfCodeLibrary._2022.Day_05; + using AdventOfCodeLibrary.Shared; + + public class Day05Part1 : Answerable + { + public override int Year { get; set; } = 2022; + public override int Day { get; set; } = 5; + public override int Part { get; set; } = 1; + + public override string GetAwner(byte[] data) + { + string[] initAndInstructions = GetAsString(data).Split(Environment.NewLine + Environment.NewLine); + CraneWork work = new CraneWork(); + work.ReadInitialContainerArrangement(initAndInstructions[0].Split(Environment.NewLine)); + foreach (string instruction in initAndInstructions[1].Split(Environment.NewLine)) + { + work.DoCraneWork(instruction); + } + + return work.GetTopContainers(); + } + } +} diff --git a/Advent Of Code Library/2022/Day 05/Day05Part2.cs b/Advent Of Code Library/2022/Day 05/Day05Part2.cs new file mode 100644 index 0000000..99f8ceb --- /dev/null +++ b/Advent Of Code Library/2022/Day 05/Day05Part2.cs @@ -0,0 +1,25 @@ +namespace AdventOfCodeLibrary._2022 +{ + using AdventOfCodeLibrary._2022.Day_05; + using AdventOfCodeLibrary.Shared; + + public class Day05Part2 : Answerable + { + public override int Year { get; set; } = 2022; + public override int Day { get; set; } = 5; + public override int Part { get; set; } = 2; + + public override string GetAwner(byte[] data) + { + string[] initAndInstructions = GetAsString(data).Split(Environment.NewLine + Environment.NewLine); + CraneWork work = new CraneWork(); + work.ReadInitialContainerArrangement(initAndInstructions[0].Split(Environment.NewLine)); + foreach (string instruction in initAndInstructions[1].Split(Environment.NewLine)) + { + work.DoCraneWork(instruction, false); + } + + return work.GetTopContainers(); + } + } +} diff --git a/Advent Of Code Library/2022/Day 05/day-05-input.txt b/Advent Of Code Library/2022/Day 05/day-05-input.txt new file mode 100644 index 0000000..2f33b25 --- /dev/null +++ b/Advent Of Code Library/2022/Day 05/day-05-input.txt @@ -0,0 +1,513 @@ + [M] [B] [N] +[T] [H] [V] [Q] [H] +[Q] [N] [H] [W] [T] [Q] +[V] [P] [F] [Q] [P] [C] [R] +[C] [D] [T] [N] [N] [L] [S] [J] +[D] [V] [W] [R] [M] [G] [R] [N] [D] +[S] [F] [Q] [Q] [F] [F] [F] [Z] [S] +[N] [M] [F] [D] [R] [C] [W] [T] [M] + 1 2 3 4 5 6 7 8 9 + +move 1 from 8 to 7 +move 1 from 2 to 7 +move 6 from 9 to 8 +move 1 from 9 to 1 +move 1 from 9 to 1 +move 3 from 3 to 6 +move 3 from 3 to 9 +move 1 from 9 to 2 +move 5 from 7 to 9 +move 9 from 1 to 6 +move 3 from 4 to 9 +move 2 from 9 to 2 +move 1 from 4 to 2 +move 1 from 3 to 9 +move 8 from 9 to 4 +move 14 from 6 to 7 +move 1 from 3 to 2 +move 5 from 4 to 2 +move 5 from 5 to 7 +move 4 from 2 to 1 +move 2 from 4 to 9 +move 1 from 4 to 3 +move 3 from 5 to 7 +move 1 from 8 to 6 +move 2 from 8 to 7 +move 2 from 1 to 2 +move 1 from 9 to 7 +move 2 from 1 to 3 +move 5 from 6 to 5 +move 4 from 5 to 7 +move 3 from 8 to 4 +move 20 from 7 to 1 +move 11 from 7 to 5 +move 1 from 6 to 9 +move 3 from 9 to 2 +move 12 from 1 to 9 +move 2 from 8 to 3 +move 4 from 2 to 8 +move 8 from 2 to 1 +move 4 from 8 to 9 +move 1 from 2 to 5 +move 12 from 9 to 7 +move 4 from 4 to 9 +move 4 from 9 to 5 +move 13 from 5 to 4 +move 4 from 4 to 7 +move 1 from 7 to 9 +move 2 from 9 to 5 +move 9 from 1 to 2 +move 1 from 8 to 3 +move 5 from 4 to 2 +move 1 from 3 to 6 +move 7 from 2 to 8 +move 6 from 1 to 6 +move 6 from 8 to 7 +move 6 from 2 to 1 +move 3 from 9 to 3 +move 7 from 3 to 7 +move 4 from 4 to 9 +move 1 from 8 to 9 +move 1 from 3 to 9 +move 1 from 2 to 4 +move 1 from 9 to 6 +move 5 from 1 to 9 +move 1 from 4 to 9 +move 2 from 9 to 1 +move 8 from 6 to 7 +move 4 from 9 to 7 +move 2 from 5 to 2 +move 2 from 1 to 9 +move 14 from 7 to 4 +move 22 from 7 to 2 +move 2 from 7 to 4 +move 3 from 7 to 5 +move 9 from 4 to 7 +move 6 from 2 to 4 +move 8 from 4 to 3 +move 14 from 2 to 9 +move 2 from 3 to 9 +move 3 from 2 to 9 +move 4 from 4 to 2 +move 1 from 4 to 5 +move 1 from 1 to 4 +move 5 from 7 to 8 +move 1 from 1 to 3 +move 4 from 5 to 2 +move 6 from 3 to 9 +move 1 from 3 to 4 +move 4 from 8 to 9 +move 2 from 4 to 6 +move 4 from 5 to 3 +move 1 from 7 to 6 +move 1 from 8 to 5 +move 3 from 3 to 1 +move 33 from 9 to 5 +move 5 from 2 to 1 +move 1 from 3 to 5 +move 1 from 7 to 6 +move 18 from 5 to 1 +move 1 from 2 to 8 +move 6 from 5 to 4 +move 1 from 8 to 7 +move 2 from 4 to 1 +move 4 from 1 to 2 +move 19 from 1 to 2 +move 4 from 6 to 8 +move 4 from 1 to 8 +move 14 from 2 to 9 +move 5 from 2 to 4 +move 1 from 8 to 2 +move 8 from 2 to 5 +move 5 from 8 to 4 +move 4 from 9 to 7 +move 1 from 8 to 1 +move 16 from 5 to 4 +move 15 from 4 to 5 +move 1 from 9 to 5 +move 5 from 7 to 6 +move 2 from 7 to 6 +move 1 from 1 to 9 +move 7 from 6 to 7 +move 1 from 8 to 5 +move 1 from 1 to 9 +move 12 from 5 to 7 +move 7 from 5 to 9 +move 12 from 7 to 2 +move 1 from 7 to 4 +move 7 from 4 to 7 +move 2 from 9 to 4 +move 5 from 4 to 9 +move 8 from 2 to 3 +move 4 from 2 to 4 +move 9 from 4 to 8 +move 6 from 3 to 5 +move 8 from 7 to 3 +move 1 from 4 to 3 +move 7 from 8 to 9 +move 4 from 5 to 4 +move 6 from 3 to 1 +move 4 from 3 to 4 +move 1 from 3 to 6 +move 6 from 4 to 9 +move 1 from 6 to 5 +move 17 from 9 to 4 +move 3 from 7 to 3 +move 1 from 7 to 9 +move 2 from 5 to 3 +move 2 from 1 to 3 +move 2 from 8 to 9 +move 1 from 5 to 1 +move 14 from 4 to 5 +move 2 from 3 to 2 +move 1 from 7 to 6 +move 10 from 9 to 4 +move 12 from 9 to 4 +move 9 from 4 to 5 +move 1 from 2 to 9 +move 13 from 5 to 9 +move 2 from 5 to 1 +move 1 from 2 to 9 +move 3 from 4 to 2 +move 12 from 4 to 7 +move 8 from 5 to 7 +move 1 from 1 to 9 +move 1 from 6 to 4 +move 1 from 5 to 4 +move 1 from 4 to 8 +move 5 from 3 to 4 +move 10 from 9 to 6 +move 3 from 6 to 2 +move 7 from 6 to 5 +move 6 from 5 to 4 +move 1 from 8 to 5 +move 1 from 1 to 4 +move 2 from 7 to 2 +move 5 from 4 to 9 +move 2 from 5 to 8 +move 1 from 1 to 3 +move 2 from 1 to 7 +move 6 from 7 to 9 +move 9 from 9 to 8 +move 1 from 1 to 3 +move 4 from 2 to 7 +move 11 from 7 to 3 +move 11 from 8 to 6 +move 7 from 3 to 1 +move 4 from 7 to 2 +move 3 from 2 to 9 +move 8 from 1 to 5 +move 2 from 7 to 5 +move 2 from 2 to 9 +move 2 from 3 to 9 +move 11 from 4 to 7 +move 7 from 9 to 5 +move 6 from 6 to 5 +move 2 from 2 to 9 +move 1 from 2 to 3 +move 6 from 9 to 4 +move 3 from 9 to 1 +move 4 from 3 to 5 +move 6 from 7 to 1 +move 2 from 6 to 3 +move 2 from 9 to 2 +move 3 from 3 to 2 +move 3 from 6 to 8 +move 2 from 7 to 5 +move 20 from 5 to 6 +move 8 from 5 to 1 +move 1 from 5 to 9 +move 2 from 8 to 4 +move 1 from 8 to 7 +move 16 from 1 to 8 +move 8 from 8 to 9 +move 4 from 2 to 4 +move 1 from 1 to 5 +move 1 from 5 to 4 +move 3 from 8 to 4 +move 14 from 4 to 6 +move 5 from 8 to 7 +move 6 from 7 to 8 +move 29 from 6 to 2 +move 3 from 9 to 8 +move 21 from 2 to 3 +move 1 from 8 to 3 +move 6 from 9 to 4 +move 8 from 3 to 5 +move 7 from 8 to 4 +move 7 from 3 to 9 +move 3 from 7 to 2 +move 12 from 4 to 8 +move 2 from 3 to 1 +move 2 from 9 to 1 +move 1 from 6 to 7 +move 1 from 7 to 6 +move 1 from 6 to 3 +move 3 from 1 to 8 +move 2 from 4 to 1 +move 4 from 6 to 1 +move 5 from 2 to 7 +move 1 from 1 to 2 +move 5 from 1 to 2 +move 2 from 8 to 1 +move 1 from 4 to 5 +move 9 from 8 to 4 +move 3 from 7 to 9 +move 7 from 5 to 7 +move 2 from 5 to 9 +move 4 from 9 to 2 +move 3 from 3 to 2 +move 5 from 2 to 7 +move 2 from 8 to 2 +move 2 from 7 to 3 +move 1 from 8 to 6 +move 2 from 1 to 2 +move 1 from 6 to 7 +move 1 from 8 to 1 +move 12 from 7 to 1 +move 5 from 2 to 7 +move 7 from 4 to 2 +move 2 from 4 to 1 +move 5 from 3 to 8 +move 7 from 1 to 9 +move 4 from 7 to 1 +move 7 from 1 to 5 +move 12 from 9 to 2 +move 27 from 2 to 4 +move 3 from 8 to 9 +move 6 from 2 to 5 +move 6 from 1 to 8 +move 1 from 7 to 6 +move 9 from 5 to 2 +move 3 from 9 to 2 +move 13 from 4 to 5 +move 10 from 2 to 7 +move 1 from 9 to 8 +move 11 from 5 to 7 +move 1 from 8 to 7 +move 1 from 2 to 6 +move 13 from 4 to 3 +move 23 from 7 to 4 +move 1 from 6 to 9 +move 1 from 2 to 4 +move 7 from 3 to 5 +move 1 from 9 to 8 +move 19 from 4 to 1 +move 2 from 4 to 1 +move 1 from 7 to 6 +move 1 from 4 to 5 +move 1 from 5 to 7 +move 11 from 5 to 1 +move 2 from 5 to 4 +move 2 from 6 to 9 +move 3 from 8 to 2 +move 2 from 8 to 1 +move 3 from 2 to 1 +move 1 from 9 to 5 +move 6 from 1 to 3 +move 1 from 9 to 7 +move 2 from 7 to 5 +move 2 from 8 to 6 +move 1 from 3 to 2 +move 2 from 8 to 5 +move 1 from 2 to 1 +move 3 from 4 to 1 +move 3 from 5 to 1 +move 2 from 5 to 1 +move 2 from 6 to 9 +move 1 from 9 to 6 +move 1 from 4 to 5 +move 1 from 9 to 8 +move 1 from 8 to 6 +move 8 from 1 to 6 +move 7 from 1 to 8 +move 9 from 1 to 6 +move 1 from 5 to 3 +move 3 from 8 to 4 +move 11 from 3 to 4 +move 1 from 3 to 6 +move 10 from 6 to 8 +move 13 from 1 to 6 +move 3 from 4 to 5 +move 7 from 8 to 6 +move 3 from 8 to 5 +move 6 from 5 to 3 +move 22 from 6 to 9 +move 4 from 3 to 6 +move 4 from 9 to 5 +move 1 from 1 to 5 +move 2 from 3 to 4 +move 2 from 1 to 5 +move 1 from 9 to 2 +move 5 from 8 to 3 +move 2 from 9 to 2 +move 11 from 6 to 9 +move 3 from 2 to 7 +move 1 from 6 to 7 +move 12 from 9 to 8 +move 4 from 7 to 1 +move 12 from 4 to 8 +move 2 from 4 to 7 +move 1 from 1 to 8 +move 1 from 5 to 1 +move 19 from 8 to 4 +move 4 from 5 to 1 +move 1 from 7 to 4 +move 1 from 7 to 1 +move 3 from 3 to 4 +move 2 from 8 to 4 +move 1 from 5 to 7 +move 1 from 7 to 9 +move 8 from 1 to 8 +move 1 from 1 to 4 +move 1 from 3 to 9 +move 1 from 3 to 5 +move 1 from 5 to 2 +move 7 from 8 to 7 +move 16 from 4 to 7 +move 1 from 7 to 4 +move 3 from 8 to 2 +move 14 from 7 to 4 +move 1 from 5 to 8 +move 5 from 7 to 5 +move 16 from 4 to 5 +move 3 from 5 to 4 +move 3 from 2 to 1 +move 1 from 7 to 9 +move 11 from 4 to 2 +move 3 from 8 to 6 +move 2 from 1 to 8 +move 1 from 4 to 9 +move 18 from 5 to 1 +move 1 from 8 to 7 +move 3 from 7 to 9 +move 18 from 9 to 3 +move 3 from 6 to 9 +move 7 from 1 to 6 +move 1 from 8 to 4 +move 1 from 4 to 9 +move 3 from 6 to 4 +move 5 from 9 to 2 +move 2 from 4 to 7 +move 7 from 2 to 8 +move 1 from 7 to 3 +move 2 from 6 to 8 +move 1 from 9 to 5 +move 1 from 6 to 8 +move 1 from 4 to 8 +move 1 from 5 to 3 +move 1 from 7 to 5 +move 8 from 8 to 7 +move 10 from 2 to 6 +move 1 from 9 to 3 +move 6 from 6 to 2 +move 5 from 6 to 2 +move 7 from 2 to 7 +move 12 from 1 to 6 +move 2 from 2 to 1 +move 1 from 2 to 5 +move 4 from 7 to 6 +move 12 from 3 to 1 +move 2 from 7 to 2 +move 9 from 3 to 8 +move 1 from 2 to 6 +move 1 from 5 to 4 +move 9 from 6 to 5 +move 1 from 7 to 6 +move 1 from 4 to 9 +move 9 from 6 to 7 +move 7 from 8 to 3 +move 6 from 3 to 1 +move 4 from 8 to 3 +move 5 from 3 to 1 +move 1 from 9 to 8 +move 2 from 8 to 9 +move 5 from 5 to 7 +move 14 from 7 to 8 +move 1 from 9 to 4 +move 2 from 2 to 1 +move 3 from 5 to 3 +move 2 from 3 to 1 +move 1 from 4 to 6 +move 6 from 8 to 6 +move 6 from 8 to 3 +move 3 from 6 to 1 +move 2 from 8 to 9 +move 19 from 1 to 6 +move 3 from 9 to 3 +move 6 from 3 to 4 +move 6 from 6 to 2 +move 4 from 3 to 9 +move 1 from 7 to 9 +move 2 from 5 to 7 +move 5 from 9 to 6 +move 6 from 7 to 2 +move 11 from 2 to 5 +move 2 from 7 to 4 +move 4 from 4 to 3 +move 2 from 4 to 8 +move 12 from 1 to 2 +move 1 from 8 to 2 +move 8 from 5 to 7 +move 2 from 4 to 9 +move 2 from 7 to 1 +move 4 from 2 to 3 +move 1 from 8 to 6 +move 1 from 1 to 5 +move 2 from 9 to 1 +move 2 from 7 to 3 +move 2 from 5 to 2 +move 1 from 5 to 7 +move 2 from 7 to 8 +move 1 from 5 to 7 +move 5 from 3 to 4 +move 3 from 1 to 7 +move 1 from 2 to 4 +move 15 from 6 to 1 +move 4 from 4 to 1 +move 4 from 2 to 3 +move 8 from 3 to 2 +move 5 from 2 to 4 +move 1 from 8 to 6 +move 1 from 8 to 9 +move 1 from 3 to 1 +move 3 from 7 to 3 +move 5 from 7 to 6 +move 4 from 2 to 9 +move 6 from 2 to 6 +move 4 from 9 to 6 +move 12 from 1 to 5 +move 6 from 4 to 1 +move 1 from 3 to 6 +move 4 from 5 to 8 +move 7 from 5 to 3 +move 3 from 8 to 2 +move 1 from 2 to 3 +move 1 from 9 to 5 +move 1 from 4 to 5 +move 1 from 8 to 5 +move 8 from 6 to 9 +move 10 from 1 to 4 +move 3 from 6 to 1 +move 9 from 3 to 6 +move 1 from 3 to 8 +move 1 from 2 to 4 +move 6 from 9 to 1 +move 1 from 1 to 4 +move 10 from 1 to 6 +move 1 from 8 to 6 +move 13 from 6 to 7 +move 1 from 2 to 1 +move 1 from 9 to 6 +move 9 from 7 to 5 +move 1 from 9 to 4 +move 3 from 7 to 1 +move 3 from 5 to 6 +move 10 from 4 to 7 +move 5 from 6 to 5 +move 3 from 4 to 5 +move 13 from 6 to 9 +move 7 from 5 to 3 +move 6 from 3 to 2 +move 5 from 6 to 4 +move 4 from 2 to 8 \ No newline at end of file diff --git a/Advent Of Code Library/Shared/Answerable.cs b/Advent Of Code Library/Shared/Answerable.cs new file mode 100644 index 0000000..476aee2 --- /dev/null +++ b/Advent Of Code Library/Shared/Answerable.cs @@ -0,0 +1,26 @@ +using System.Text; + +namespace AdventOfCodeLibrary.Shared +{ + public abstract class Answerable + { + public abstract int Year { get; set; } + + public abstract int Day { get; set; } + + public abstract int Part { get; set; } + + public string DefaultInputFile { + get + { + return $"../../../../Advent Of Code Library/{Year}/Day {Day:00}/day-{Day:00}-input.txt"; + } + } + + public abstract string GetAwner(byte[] data); + + internal static string GetAsString(byte[] bytes) => Encoding.UTF8.GetString(bytes); + + internal static string[] GetAsStringArray(byte[] bytes) => Encoding.UTF8.GetString(bytes).Split(Environment.NewLine); + } +} diff --git a/Advent Of Code Library/Shared/AnswerableListBuilder.cs b/Advent Of Code Library/Shared/AnswerableListBuilder.cs index 5da0d86..5ca0384 100644 --- a/Advent Of Code Library/Shared/AnswerableListBuilder.cs +++ b/Advent Of Code Library/Shared/AnswerableListBuilder.cs @@ -4,23 +4,23 @@ namespace AdventOfCodeLibrary.Shared { public class AnswerableListBuilder { - public static IEnumerable AnswerableList() + public static IEnumerable AnswerableList() { - Type type = typeof(IAnswerable); - IEnumerable instances = + Type type = typeof(Answerable); + IEnumerable instances = Assembly.GetExecutingAssembly().GetTypes() .Where(t => t.GetInterfaces().Contains(type) && t.GetConstructor(Type.EmptyTypes) != null ) - .Select(t => Activator.CreateInstance(t) as IAnswerable) + .Select(t => Activator.CreateInstance(t) as Answerable) .Where(i => i != null); // try to filter null var noneNull = instances.Where(i => i != null); - return new List(); + return new List(); } } } diff --git a/Advent Of Code Library/Shared/ByteHelper.cs b/Advent Of Code Library/Shared/ByteHelper.cs deleted file mode 100644 index 8fdd4de..0000000 --- a/Advent Of Code Library/Shared/ByteHelper.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace AdventOfCodeLibrary.Shared -{ - using System.Text; - - public class ByteHelper - { - public static string GetAsString(byte[] bytes) => Encoding.UTF8.GetString(bytes); - - public static string[] GetAsStringArray(byte[] bytes) => Encoding.UTF8.GetString(bytes).Split(Environment.NewLine); - } -} diff --git a/Advent Of Code Library/Shared/IAnswerable.cs b/Advent Of Code Library/Shared/IAnswerable.cs deleted file mode 100644 index 52a6ff1..0000000 --- a/Advent Of Code Library/Shared/IAnswerable.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace AdventOfCodeLibrary.Shared -{ - public interface IAnswerable - { - int Year { get; set; } - - int Day { get; set; } - - int Part { get; set; } - - string DefaultInputFile { - get - { - return $"../../../../Advent Of Code Library/{Year}/Day {Day:00}/day-{Day:00}-input.txt"; - } - } - - string GetAwner(byte[] data); - } -}