diff --git a/AdventOfCode/Problems/AOC2015/Day10/LookAndSay.cs b/AdventOfCode/Problems/AOC2015/Day10/LookAndSay.cs index a79bd07..3eef30e 100644 --- a/AdventOfCode/Problems/AOC2015/Day10/LookAndSay.cs +++ b/AdventOfCode/Problems/AOC2015/Day10/LookAndSay.cs @@ -1,13 +1,9 @@ using AdventOfCode.Runner.Attributes; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http.Headers; using System.Text; -using System.Threading.Tasks; namespace AdventOfCode.Problems.AOC2015.Day10; + [ProblemInfo(2015, 10, "Evles Look, Elves Say")] internal class LookAndSay : Problem { @@ -59,4 +55,4 @@ internal class LookAndSay : Problem input = next; } -} +} \ No newline at end of file diff --git a/AdventOfCode/Problems/AOC2015/Day5/NiceList.cs b/AdventOfCode/Problems/AOC2015/Day5/NiceList.cs index 65da96d..65b8782 100644 --- a/AdventOfCode/Problems/AOC2015/Day5/NiceList.cs +++ b/AdventOfCode/Problems/AOC2015/Day5/NiceList.cs @@ -31,6 +31,7 @@ public class NiceList : Problem } } } + private static bool IsNice2(string value) { var pairs = new Dictionary>(); diff --git a/AdventOfCode/Problems/AOC2019/Day1/FuelCaluclation.cs b/AdventOfCode/Problems/AOC2019/Day1/FuelCaluclation.cs index 5c65e86..2a10c32 100644 --- a/AdventOfCode/Problems/AOC2019/Day1/FuelCaluclation.cs +++ b/AdventOfCode/Problems/AOC2019/Day1/FuelCaluclation.cs @@ -1,11 +1,5 @@ using AdventOfCode.Runner.Attributes; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; - namespace AdventOfCode.Problems.AOC2019.Day1 { [ProblemInfo(2019, 1, "The Tyranny of the Rocket Equation")] @@ -27,7 +21,7 @@ namespace AdventOfCode.Problems.AOC2019.Day1 return curCost + GetFuelCost(curCost); } - public static int GetCost(int mass) => mass/ 3 - 2; + public static int GetCost(int mass) => mass / 3 - 2; public override void LoadInput() { @@ -41,8 +35,7 @@ namespace AdventOfCode.Problems.AOC2019.Day1 public override void CalculatePart2() { - Part2 = GetFuelRequirement(_input); } } -} +} \ No newline at end of file diff --git a/AdventOfCode/Problems/AOC2019/Day3/CrossedWires.cs b/AdventOfCode/Problems/AOC2019/Day3/CrossedWires.cs index 0bd97d6..b232fc9 100644 --- a/AdventOfCode/Problems/AOC2019/Day3/CrossedWires.cs +++ b/AdventOfCode/Problems/AOC2019/Day3/CrossedWires.cs @@ -1,13 +1,6 @@ using AdventOfCode.Runner.Attributes; -using System; -using System.Collections.Generic; -using System.Diagnostics; using System.Drawing; -using System.IO; -using System.Linq; -using System.Net.Http.Headers; -using System.Text; namespace AdventOfCode.Problems.AOC2019.Day3 { @@ -157,7 +150,7 @@ namespace AdventOfCode.Problems.AOC2019.Day3 return false; } } - else //Both + else //Both { if (min.X != other.min.X) { @@ -227,7 +220,6 @@ namespace AdventOfCode.Problems.AOC2019.Day3 public static int SolveWires(string[] wires) { - var (wireSegmentsA, wireSegmentsB) = CreateWirePair(wires); int shortestWire = int.MaxValue; @@ -271,7 +263,6 @@ namespace AdventOfCode.Problems.AOC2019.Day3 var wireA = wires[0].Split(','); var wireSegmentsA = CreateWire(wireA); - var wireB = wires[1].Split(','); var wireSegmentsB = CreateWire(wireB); @@ -325,4 +316,4 @@ namespace AdventOfCode.Problems.AOC2019.Day3 Part2 = SolveWires(_inputLines); } } -} +} \ No newline at end of file diff --git a/AdventOfCode/Problems/AOC2019/Day4/SecureContainer.cs b/AdventOfCode/Problems/AOC2019/Day4/SecureContainer.cs index 2afea0a..4273046 100644 --- a/AdventOfCode/Problems/AOC2019/Day4/SecureContainer.cs +++ b/AdventOfCode/Problems/AOC2019/Day4/SecureContainer.cs @@ -1,11 +1,5 @@ using AdventOfCode.Runner.Attributes; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; - namespace AdventOfCode.Problems.AOC2019.Day4 { [ProblemInfo(2019, 4, "Secure Container")] @@ -30,7 +24,6 @@ namespace AdventOfCode.Problems.AOC2019.Day4 public static bool HasDoubles(int[] password) { - bool foundDouble = false; for (int i = 0; i < 6; i++) { @@ -53,7 +46,6 @@ namespace AdventOfCode.Problems.AOC2019.Day4 foundDouble = true; } return foundDouble; - } public static bool IsAssending(int[] password) @@ -68,8 +60,6 @@ namespace AdventOfCode.Problems.AOC2019.Day4 return true; } - - public static int CountPasswordsPart1(int lower, int upper) { int passwordCount = 0; @@ -87,6 +77,7 @@ namespace AdventOfCode.Problems.AOC2019.Day4 } return passwordCount; } + public static int CountPasswordsPart2(int lower, int upper) { int passwordCount = 0; @@ -139,7 +130,6 @@ namespace AdventOfCode.Problems.AOC2019.Day4 } } - public override void LoadInput() { } @@ -154,4 +144,4 @@ namespace AdventOfCode.Problems.AOC2019.Day4 Part2 = CountPasswordsPart2(147981, 691423); } } -} +} \ No newline at end of file diff --git a/AdventOfCode/Problems/AOC2019/Day5/ChanceOfAsteroids.cs b/AdventOfCode/Problems/AOC2019/Day5/ChanceOfAsteroids.cs index 3605c4a..2170772 100644 --- a/AdventOfCode/Problems/AOC2019/Day5/ChanceOfAsteroids.cs +++ b/AdventOfCode/Problems/AOC2019/Day5/ChanceOfAsteroids.cs @@ -1,14 +1,8 @@ using AdventOfCode.Day_5; using AdventOfCode.Runner.Attributes; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace AdventOfCode.Problems.AOC2019.Day5; + [ProblemInfo(2019, 5, "Sunny with a Chance of Asteroids")] internal class ChanceOfAsteroids : Problem { @@ -33,4 +27,4 @@ internal class ChanceOfAsteroids : Problem { _baseInput = InputParsing.ParseIntCsv(GetInputFile("input.csv")); } -} +} \ No newline at end of file diff --git a/AdventOfCode/Problems/AOC2019/Day5/IntCodeV2.cs b/AdventOfCode/Problems/AOC2019/Day5/IntCodeV2.cs index 25cdfdd..bca3eda 100644 --- a/AdventOfCode/Problems/AOC2019/Day5/IntCodeV2.cs +++ b/AdventOfCode/Problems/AOC2019/Day5/IntCodeV2.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Text; - -namespace AdventOfCode.Day_5 +namespace AdventOfCode.Day_5 { public class IntCodeV2 { @@ -19,7 +14,6 @@ namespace AdventOfCode.Day_5 this.paramCount = paramCount; this.action = action; } - } public bool IsHalted { get; private set; } @@ -167,10 +161,11 @@ namespace AdventOfCode.Day_5 { var opModes = new int[3]; var arr = instruction.ToIntArray(); - switch(arr.Length) + switch (arr.Length) { case 1: return (opModes, arr[0]); + case 2: return (opModes, (arr[^2] * 10) + arr[^1]); } @@ -234,7 +229,5 @@ namespace AdventOfCode.Day_5 _instructionPointer = 0; return this; } - - } -} +} \ No newline at end of file diff --git a/AdventOfCode/Problems/AOC2019/Day6/UniversalOrbits.cs b/AdventOfCode/Problems/AOC2019/Day6/UniversalOrbits.cs index 39887e3..27b06b1 100644 --- a/AdventOfCode/Problems/AOC2019/Day6/UniversalOrbits.cs +++ b/AdventOfCode/Problems/AOC2019/Day6/UniversalOrbits.cs @@ -1,12 +1,7 @@ using AdventOfCode.Runner.Attributes; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace AdventOfCode.Problems.AOC2019.Day6; + [ProblemInfo(2019, 6, "Universal Orbit Map")] internal class UniversalOrbits : Problem { @@ -14,7 +9,7 @@ internal class UniversalOrbits : Problem public override void CalculatePart1() { - if(_map == null) + if (_map == null) return; Part1 = _map.CalculateOrbits(); } @@ -31,7 +26,6 @@ internal class UniversalOrbits : Problem HashSet pathYOU = new(pathToYOU.Select(o => o.Name)); - for (int i = 0; i < pathToSAN.Count; i++) { if (pathYOU.Contains(pathToSAN[i].Name)) @@ -50,11 +44,10 @@ internal class UniversalOrbits : Problem } } Part2 = dist - 2; - } public override void LoadInput() { _map = new OrbitMap(ReadInputLines()); } -} +} \ No newline at end of file diff --git a/AdventOfCode/Problems/AOC2019/Day8/SpaceImageFormat.cs b/AdventOfCode/Problems/AOC2019/Day8/SpaceImageFormat.cs index 94eeb3c..5556273 100644 --- a/AdventOfCode/Problems/AOC2019/Day8/SpaceImageFormat.cs +++ b/AdventOfCode/Problems/AOC2019/Day8/SpaceImageFormat.cs @@ -1,11 +1,5 @@ using AdventOfCode.Runner.Attributes; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; - namespace AdventOfCode.Problems.AOC2019.Day8 { [ProblemInfo(2019, 8, "Space Image Format")] @@ -18,7 +12,6 @@ namespace AdventOfCode.Problems.AOC2019.Day8 var imageData = File.ReadAllText("Day8/input.txt").Replace("\n", "").Select(c => int.Parse(c.ToString())).ToArray(); Console.WriteLine(Checksum(imageData, 25, 6)); - } public static void RenderImage(int[] data, int h, int w) @@ -28,11 +21,9 @@ namespace AdventOfCode.Problems.AOC2019.Day8 for (int l = 0; l < layerCount; l++) { - } } - public static int Checksum(int[] data, int h, int w) { var imgSize = h * w; @@ -54,9 +45,11 @@ namespace AdventOfCode.Problems.AOC2019.Day8 case 0: zeroCount[l]++; break; + case 1: oneCount[l]++; break; + case 2: twoCount[l]++; break; @@ -70,7 +63,6 @@ namespace AdventOfCode.Problems.AOC2019.Day8 } return oneCount[smallestLayer] * twoCount[smallestLayer]; - } public override void LoadInput() @@ -88,4 +80,4 @@ namespace AdventOfCode.Problems.AOC2019.Day8 Part2 = null; } } -} +} \ No newline at end of file diff --git a/AdventOfCode/Problems/AOC2019/InputParsing.cs b/AdventOfCode/Problems/AOC2019/InputParsing.cs index 84d8bd2..251ce57 100644 --- a/AdventOfCode/Problems/AOC2019/InputParsing.cs +++ b/AdventOfCode/Problems/AOC2019/InputParsing.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; - -namespace AdventOfCode +namespace AdventOfCode { public static class InputParsing { @@ -34,4 +28,4 @@ namespace AdventOfCode return intArr; } } -} +} \ No newline at end of file diff --git a/AdventOfCode/Problems/AOC2021/Day11/DumboOctopus.cs b/AdventOfCode/Problems/AOC2021/Day11/DumboOctopus.cs index 60d5a44..aeb3bc5 100644 --- a/AdventOfCode/Problems/AOC2021/Day11/DumboOctopus.cs +++ b/AdventOfCode/Problems/AOC2021/Day11/DumboOctopus.cs @@ -1,9 +1,6 @@ using AdventOfCode.Runner.Attributes; using System.Collections; -using System.Numerics; -using System.Text; - namespace AdventOfCode.Problems.AOC2021.Day11; @@ -76,7 +73,6 @@ public class DumboOctopus : Problem, IEnumerable { Increment(ref data); Flash(ref data, ref flashes); - } private static void Increment(ref byte[] data) diff --git a/AdventOfCode/Problems/AOC2021/Day3/BinaryDiagnostic.cs b/AdventOfCode/Problems/AOC2021/Day3/BinaryDiagnostic.cs index 4106576..ec63e99 100644 --- a/AdventOfCode/Problems/AOC2021/Day3/BinaryDiagnostic.cs +++ b/AdventOfCode/Problems/AOC2021/Day3/BinaryDiagnostic.cs @@ -1,12 +1,5 @@ using AdventOfCode.Runner.Attributes; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - - namespace AdventOfCode.Problems.AOC2021.Day3; [ProblemInfo(2021, 3, "Binary Diagnostic")] @@ -75,4 +68,4 @@ public class BinaryDiagnostic : Problem Part2 = oxygenLevel * carbonLevel; } -} +} \ No newline at end of file diff --git a/AdventOfCode/Problems/AOC2021/Day6/LanternFish.cs b/AdventOfCode/Problems/AOC2021/Day6/LanternFish.cs index 410b5bd..e507ec2 100644 --- a/AdventOfCode/Problems/AOC2021/Day6/LanternFish.cs +++ b/AdventOfCode/Problems/AOC2021/Day6/LanternFish.cs @@ -1,11 +1,5 @@ using AdventOfCode.Runner.Attributes; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace AdventOfCode.Problems.AOC2021.Day6; [ProblemInfo(2021, 6, "Lanternfish")] @@ -18,11 +12,11 @@ internal class LanternFish : Problem var input = ReadInputLines(); Data = input.First().Split(",").Select(v => int.Parse(v)).ToArray(); } + public override void CalculatePart1() { var lifetimes = PrepareLifetimes(); Part1 = Simulate(lifetimes, 80); - } public override void CalculatePart2() @@ -53,8 +47,4 @@ internal class LanternFish : Problem return lifetimes.Sum(); } - - - - -} +} \ No newline at end of file diff --git a/AdventOfCode/Problems/AOC2022/Day0/TestProblem.cs b/AdventOfCode/Problems/AOC2022/Day0/TestProblem.cs index 6fd2c18..ccb7e78 100644 --- a/AdventOfCode/Problems/AOC2022/Day0/TestProblem.cs +++ b/AdventOfCode/Problems/AOC2022/Day0/TestProblem.cs @@ -1,7 +1,7 @@ -using AdventOfCode.Runner; -using AdventOfCode.Runner.Attributes; +using AdventOfCode.Runner.Attributes; namespace AdventOfCode.Problems.AOC2022.Day0; + [ProblemInfo(2022, 0, "Fancy Test")] public class TestProblem : Problem { @@ -20,7 +20,6 @@ public class TestProblem : Problem Thread.Sleep(1000); } - public override void PrintPart1() { Console.WriteLine("Result"); diff --git a/AdventOfCode/Problems/AOC2022/Day1/CalorieCounting.cs b/AdventOfCode/Problems/AOC2022/Day1/CalorieCounting.cs index 8093753..11555c9 100644 --- a/AdventOfCode/Problems/AOC2022/Day1/CalorieCounting.cs +++ b/AdventOfCode/Problems/AOC2022/Day1/CalorieCounting.cs @@ -1,13 +1,7 @@ -using AdventOfCode.Runner; -using AdventOfCode.Runner.Attributes; - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using AdventOfCode.Runner.Attributes; namespace AdventOfCode.Problems.AOC2022.Day1; + [ProblemInfo(2022, 1, "Calorie Counting")] internal class CalorieCounting : Problem { @@ -16,7 +10,8 @@ internal class CalorieCounting : Problem private (int calories, int elf)? _mostestElf; private IEnumerable<(int sum, int idx)>? _mostestElves; - public CalorieCounting() { + public CalorieCounting() + { FlaresFood = new List> { new List() @@ -24,12 +19,12 @@ internal class CalorieCounting : Problem } public override void LoadInput() - { - var lines = File.ReadAllLines(GetInputFile("input.txt")); + { + var lines = File.ReadAllLines(GetInputFile("input.txt")); var c = 0; foreach (var calorie in lines) { - if(string.IsNullOrWhiteSpace(calorie)) + if (string.IsNullOrWhiteSpace(calorie)) { FlaresFood.Add(new List()); c++; @@ -37,22 +32,23 @@ internal class CalorieCounting : Problem } FlaresFood[c].Add(int.Parse(calorie)); } - } - public override void CalculatePart1() - { - _mostestElf = FlaresFood + } + + public override void CalculatePart1() + { + _mostestElf = FlaresFood .Select((x, idx) => (sum: x.Sum(), idx)) .MaxBy(x => x.sum); Part1 = _mostestElf.Value.ToString(); - } + } - public override void CalculatePart2() - { - _mostestElves = FlaresFood + public override void CalculatePart2() + { + _mostestElves = FlaresFood .Select((x, idx) => (sum: x.Sum(), idx)) .OrderByDescending(e => e.sum) .Take(3); Part2 = _mostestElves.Sum(e => e.sum).ToString(); } -} +} \ No newline at end of file diff --git a/AdventOfCode/Problems/AOC2022/Day10/CathodeCPU.cs b/AdventOfCode/Problems/AOC2022/Day10/CathodeCPU.cs index 6903bfa..677a55b 100644 --- a/AdventOfCode/Problems/AOC2022/Day10/CathodeCPU.cs +++ b/AdventOfCode/Problems/AOC2022/Day10/CathodeCPU.cs @@ -1,10 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +namespace AdventOfCode.Problems.AOC2022.Day10; -namespace AdventOfCode.Problems.AOC2022.Day10; internal class CathodeCPU { public enum Instruction @@ -38,9 +33,9 @@ internal class CathodeCPU return result; } + public void ExecuteCode((Instruction ins, int value)[] code, Action processor) { - while (_programCounter < code.Length) { var (ins, value) = code[_programCounter]; @@ -52,23 +47,20 @@ internal class CathodeCPU case { ins: Instruction.NoOp }: _programCounter++; break; - case { ins: Instruction.AddX, _pending : -1 }: + + case { ins: Instruction.AddX, _pending: -1 }: _pending = 1; break; + case { ins: Instruction.AddX, _pending: 0 }: X += value; _programCounter++; break; } - - - if(_pending >= 0) + if (_pending >= 0) _pending--; - _cycleNumber++; + _cycleNumber++; } - } - - -} +} \ No newline at end of file diff --git a/AdventOfCode/Problems/AOC2022/Day10/CathodeRayTube.cs b/AdventOfCode/Problems/AOC2022/Day10/CathodeRayTube.cs index ade13dd..1ce3416 100644 --- a/AdventOfCode/Problems/AOC2022/Day10/CathodeRayTube.cs +++ b/AdventOfCode/Problems/AOC2022/Day10/CathodeRayTube.cs @@ -25,11 +25,10 @@ internal class CathodeRayTube : Problem if (cycle > output.Length) return; - var pos = signal % 40; var head = (cycle % 40); var sprite = Math.Abs(pos - head); - if(sprite <= 1) + if (sprite <= 1) output[cycle] = '█'; }); diff --git a/AdventOfCode/Problems/AOC2022/Day11/Monkey.cs b/AdventOfCode/Problems/AOC2022/Day11/Monkey.cs index b93c7d8..e26b678 100644 --- a/AdventOfCode/Problems/AOC2022/Day11/Monkey.cs +++ b/AdventOfCode/Problems/AOC2022/Day11/Monkey.cs @@ -38,7 +38,7 @@ internal class Monkey { InspectionCount++; value = Operate(value); - if(worryOffset != 0) + if (worryOffset != 0) value /= worryOffset; return value; } @@ -68,6 +68,6 @@ internal class Monkey public override string ToString() { - return $"{MonkeyNumber}: ({InspectionCount}) [{string.Join(", ",Items)}]"; + return $"{MonkeyNumber}: ({InspectionCount}) [{string.Join(", ", Items)}]"; } } \ No newline at end of file diff --git a/AdventOfCode/Problems/AOC2022/Day11/MonkeyInTheMiddle.cs b/AdventOfCode/Problems/AOC2022/Day11/MonkeyInTheMiddle.cs index 1bfdf4d..20526c7 100644 --- a/AdventOfCode/Problems/AOC2022/Day11/MonkeyInTheMiddle.cs +++ b/AdventOfCode/Problems/AOC2022/Day11/MonkeyInTheMiddle.cs @@ -1,13 +1,7 @@ using AdventOfCode.Runner.Attributes; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Threading.Tasks; - namespace AdventOfCode.Problems.AOC2022.Day11; + [ProblemInfo(2022, 11, "Monkey in the Middle")] internal class MonkeyInTheMiddle : Problem { @@ -37,7 +31,6 @@ internal class MonkeyInTheMiddle : Problem var lines = ReadInputLines("test.txt").Chunk(7); _monkeysPart1 = lines.Select(ln => new Monkey(ln)).ToArray(); _monkeysPart2 = lines.Select(ln => new Monkey(ln)).ToArray(); - } private static void Simulate(Monkey[] monkeys, int rounds, uint worry = 3) @@ -54,8 +47,8 @@ internal class MonkeyInTheMiddle : Problem SimulateTurn(monkey, monkeys, worry); } - - private static void SimulateTurn(Monkey monkey, Monkey[] monkeys, uint worry = 3) { + private static void SimulateTurn(Monkey monkey, Monkey[] monkeys, uint worry = 3) + { for (int i = 0; i < monkey.Items.Count; i++) { var item = monkey.Inspect(monkey.Items[i], worry); @@ -64,4 +57,4 @@ internal class MonkeyInTheMiddle : Problem } monkey.Items.Clear(); } -} +} \ No newline at end of file diff --git a/AdventOfCode/Problems/AOC2022/Day12/HillClimbing.cs b/AdventOfCode/Problems/AOC2022/Day12/HillClimbing.cs index d501cf5..4c0b0c2 100644 --- a/AdventOfCode/Problems/AOC2022/Day12/HillClimbing.cs +++ b/AdventOfCode/Problems/AOC2022/Day12/HillClimbing.cs @@ -1,12 +1,7 @@ using AdventOfCode.Runner.Attributes; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace AdventOfCode.Problems.AOC2022.Day12; + [ProblemInfo(2022, 12, "Hill Climbing Algorithm")] internal class HillClimbing : Problem { @@ -24,4 +19,4 @@ internal class HillClimbing : Problem { throw new NotImplementedException(); } -} +} \ No newline at end of file diff --git a/AdventOfCode/Problems/AOC2022/Day13/DistressSignal.cs b/AdventOfCode/Problems/AOC2022/Day13/DistressSignal.cs index e13f8b6..bba79ef 100644 --- a/AdventOfCode/Problems/AOC2022/Day13/DistressSignal.cs +++ b/AdventOfCode/Problems/AOC2022/Day13/DistressSignal.cs @@ -1,12 +1,7 @@ using AdventOfCode.Runner.Attributes; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace AdventOfCode.Problems.AOC2022.Day13; + [ProblemInfo(2022, 13, "Distress Signal")] internal class DistressSignal : Problem { @@ -24,4 +19,4 @@ internal class DistressSignal : Problem { throw new NotImplementedException(); } -} +} \ No newline at end of file diff --git a/AdventOfCode/Problems/AOC2022/Day14/RegolithReservoir.cs b/AdventOfCode/Problems/AOC2022/Day14/RegolithReservoir.cs index de47857..82dd291 100644 --- a/AdventOfCode/Problems/AOC2022/Day14/RegolithReservoir.cs +++ b/AdventOfCode/Problems/AOC2022/Day14/RegolithReservoir.cs @@ -1,12 +1,7 @@ using AdventOfCode.Runner.Attributes; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace AdventOfCode.Problems.AOC2022.Day14; + [ProblemInfo(2022, 14, "Regolith Reservoir")] internal class RegolithReservoir : Problem { @@ -24,4 +19,4 @@ internal class RegolithReservoir : Problem { throw new NotImplementedException(); } -} +} \ No newline at end of file diff --git a/AdventOfCode/Problems/AOC2022/Day2/RockPaperScissors.cs b/AdventOfCode/Problems/AOC2022/Day2/RockPaperScissors.cs index d635557..4029747 100644 --- a/AdventOfCode/Problems/AOC2022/Day2/RockPaperScissors.cs +++ b/AdventOfCode/Problems/AOC2022/Day2/RockPaperScissors.cs @@ -1,5 +1,4 @@ -using AdventOfCode.Runner; -using AdventOfCode.Runner.Attributes; +using AdventOfCode.Runner.Attributes; namespace AdventOfCode.Problems.AOC2022.Day2; @@ -74,7 +73,8 @@ internal class RockPaperScissors : Problem }; } - private static int GetResponseValue(char move, char result) { + private static int GetResponseValue(char move, char result) + { var p = result switch { 'X' => (GetMoveValue(move) + 2) % 3, //Lose @@ -85,7 +85,6 @@ internal class RockPaperScissors : Problem return p == 0 ? 3 : p; } - public override void CalculatePart2() { var score = 0; diff --git a/AdventOfCode/Problems/AOC2022/Day3/RucksackReorganization.cs b/AdventOfCode/Problems/AOC2022/Day3/RucksackReorganization.cs index 454bcb5..821ac0a 100644 --- a/AdventOfCode/Problems/AOC2022/Day3/RucksackReorganization.cs +++ b/AdventOfCode/Problems/AOC2022/Day3/RucksackReorganization.cs @@ -1,19 +1,14 @@ -using AdventOfCode.Runner; -using AdventOfCode.Runner.Attributes; - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using AdventOfCode.Runner.Attributes; namespace AdventOfCode.Problems.AOC2022.Day3; + [ProblemInfo(2022, 3, "Rucksack Reorganization")] internal class RucksackReorganization : Problem { private string[] _sacks; - public RucksackReorganization() { + public RucksackReorganization() + { _sacks = Array.Empty(); } @@ -21,6 +16,7 @@ internal class RucksackReorganization : Problem { _sacks = ReadInputLines("input.txt"); } + public override void CalculatePart1() { var total = 0; @@ -55,5 +51,4 @@ internal class RucksackReorganization : Problem } Part2 = total.ToString(); } - -} +} \ No newline at end of file diff --git a/AdventOfCode/Problems/AOC2022/Day4/CampCleanup.cs b/AdventOfCode/Problems/AOC2022/Day4/CampCleanup.cs index 984b453..ce307c3 100644 --- a/AdventOfCode/Problems/AOC2022/Day4/CampCleanup.cs +++ b/AdventOfCode/Problems/AOC2022/Day4/CampCleanup.cs @@ -1,13 +1,7 @@ -using AdventOfCode.Runner; -using AdventOfCode.Runner.Attributes; - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using AdventOfCode.Runner.Attributes; namespace AdventOfCode.Problems.AOC2022.Day4; + [ProblemInfo(2022, 4, "Camp Cleanup")] internal class CampCleanup : Problem { @@ -19,7 +13,7 @@ internal class CampCleanup : Problem foreach (var line in lines) { var (a, b) = line.Split(',') - .Select(range => + .Select(range => range.Split('-') .Select(v => int.Parse(v)) .Chunk(2) @@ -32,7 +26,6 @@ internal class CampCleanup : Problem } } - public override void CalculatePart1() { var total = 0; @@ -50,10 +43,9 @@ internal class CampCleanup : Problem { if (a.OverlapsWith(b)) Part2++; - } + } } - record Range(int A, int B) { public bool Contains(Range other) @@ -66,6 +58,6 @@ internal class CampCleanup : Problem return (B >= other.A && A <= other.A) || (A <= other.B && B >= other.B) || (A >= other.A && B <= other.B); } - public static implicit operator Range((int a, int b) value) => new (value.a, value.b); + public static implicit operator Range((int a, int b) value) => new(value.a, value.b); } -} +} \ No newline at end of file diff --git a/AdventOfCode/Problems/AOC2022/Day5/SupplyStacks.cs b/AdventOfCode/Problems/AOC2022/Day5/SupplyStacks.cs index 05b5136..f09d45f 100644 --- a/AdventOfCode/Problems/AOC2022/Day5/SupplyStacks.cs +++ b/AdventOfCode/Problems/AOC2022/Day5/SupplyStacks.cs @@ -3,7 +3,6 @@ using Superpower; using Superpower.Parsers; -using System.Diagnostics; using System.Text.RegularExpressions; namespace AdventOfCode.Problems.AOC2022.Day5; @@ -13,15 +12,16 @@ internal partial class SupplyStacks : Problem { private List[] _stacksPart1 = Array.Empty>(); private List[] _stacksPart2 = Array.Empty>(); - private readonly TextParser<(int, int, int)> _moveParser = from move in Character.Letter.Or(Character.WhiteSpace).Many() - from stack in Character.Digit.Many() - from frm in Character.Letter.Or(Character.WhiteSpace).Many() - from source in Character.Digit.Many() - from to in Character.Letter.Or(Character.WhiteSpace).Many() - from dst in Character.Digit.Many() - select (int.Parse(stack), int.Parse(source), int.Parse(dst)); - private List<(int stack, int from, int to)> _moves = new (); + private readonly TextParser<(int, int, int)> _moveParser = from move in Character.Letter.Or(Character.WhiteSpace).Many() + from stack in Character.Digit.Many() + from frm in Character.Letter.Or(Character.WhiteSpace).Many() + from source in Character.Digit.Many() + from to in Character.Letter.Or(Character.WhiteSpace).Many() + from dst in Character.Digit.Many() + select (int.Parse(stack), int.Parse(source), int.Parse(dst)); + + private List<(int stack, int from, int to)> _moves = new(); public override void CalculatePart1() { @@ -34,12 +34,12 @@ internal partial class SupplyStacks : Problem private static void PerformBasicMove(List[] data, (int stack, int from, int to) move) { - var from = data[move.from-1]; - var to = data[move.to-1]; + var from = data[move.from - 1]; + var to = data[move.to - 1]; for (int i = 0; i < move.stack; i++) { var item = from[^1]; - from.RemoveAt(from.Count-1); + from.RemoveAt(from.Count - 1); to.Add(item); } } diff --git a/AdventOfCode/Problems/AOC2022/Day6/TuningTrouble.cs b/AdventOfCode/Problems/AOC2022/Day6/TuningTrouble.cs index 62951c9..ab1be03 100644 --- a/AdventOfCode/Problems/AOC2022/Day6/TuningTrouble.cs +++ b/AdventOfCode/Problems/AOC2022/Day6/TuningTrouble.cs @@ -1,11 +1,5 @@ using AdventOfCode.Runner.Attributes; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace AdventOfCode.Problems.AOC2022.Day6; [ProblemInfo(2022, 6, "Tuning Trouble")] @@ -38,4 +32,4 @@ internal class TuningTrouble : Problem { _input = ReadInputText(); } -} +} \ No newline at end of file diff --git a/AdventOfCode/Problems/AOC2022/Day7/DirectoryNode.cs b/AdventOfCode/Problems/AOC2022/Day7/DirectoryNode.cs index 3e2beee..cf2586c 100644 --- a/AdventOfCode/Problems/AOC2022/Day7/DirectoryNode.cs +++ b/AdventOfCode/Problems/AOC2022/Day7/DirectoryNode.cs @@ -1,8 +1,6 @@ -using System.Collections; +namespace AdventOfCode.Problems.AOC2022.Day7; -namespace AdventOfCode.Problems.AOC2022.Day7; - -internal class DirectoryNode +internal class DirectoryNode { public DirectoryNode Parent { get; set; } public string Name { get; set; } @@ -40,7 +38,7 @@ internal class DirectoryNode { if (path == "/") return this; - if(string.IsNullOrWhiteSpace(path)) + if (string.IsNullOrWhiteSpace(path)) return this; var segments = path.Split("/").Where(s => !string.IsNullOrWhiteSpace(s)).ToArray(); if (segments.Length == 0) @@ -91,19 +89,19 @@ internal class DirectoryNode var child = Children.FirstOrDefault(c => c.Name == segments[0]); - if(child == null) + if (child == null) return null; else - if(segments.Length == 1) - return child; - else - return child.GetDirectory(segments[1..]); + if (segments.Length == 1) + return child; + else + return child.GetDirectory(segments[1..]); } public List Where(Func filter) { var result = new List(); - if(filter(this)) + if (filter(this)) result.Add(this); result.AddRange(Children.SelectMany(c => c.Where(filter))); return result; diff --git a/AdventOfCode/Problems/AOC2022/Day7/NoSpace.cs b/AdventOfCode/Problems/AOC2022/Day7/NoSpace.cs index e96e4fc..08a217d 100644 --- a/AdventOfCode/Problems/AOC2022/Day7/NoSpace.cs +++ b/AdventOfCode/Problems/AOC2022/Day7/NoSpace.cs @@ -3,7 +3,7 @@ namespace AdventOfCode.Problems.AOC2022.Day7; [ProblemInfo(2022, 7, "No Space Left On Device")] -internal class NoSpace : Problem +internal class NoSpace : Problem { private DirectoryNode _dirTree = new DirectoryNode("/"); @@ -37,7 +37,8 @@ internal class NoSpace : Problem ParseCommand(line[2..], ref curDir); dir = $"/{string.Join("/", curDir.Reverse())}"; _dirTree.AddDirectory(dir); - }else + } + else ReadDirectory(line, _dirTree.GetDirectory(dir)!); } } diff --git a/AdventOfCode/Problems/AOC2022/Day9/RopeSimulator.cs b/AdventOfCode/Problems/AOC2022/Day9/RopeSimulator.cs index ac2cfb6..5f6efdc 100644 --- a/AdventOfCode/Problems/AOC2022/Day9/RopeSimulator.cs +++ b/AdventOfCode/Problems/AOC2022/Day9/RopeSimulator.cs @@ -68,7 +68,6 @@ public class RopeSimulator else _visited.Add(tail, 1); } - } private void FollowHead() @@ -129,12 +128,12 @@ public class RopeSimulator Draw('s', (0, 0), lowerX, upperY); Draw('H', _head, lowerX, upperY); - for (int i = _segments.Length -1; i >= 0; i--) + for (int i = _segments.Length - 1; i >= 0; i--) { - if(segment == i) - Console.ForegroundColor= ConsoleColor.Red; + if (segment == i) + Console.ForegroundColor = ConsoleColor.Red; else - Console.ForegroundColor= ConsoleColor.Gray; + Console.ForegroundColor = ConsoleColor.Gray; Draw((i + 1).ToString()[0], _segments[i], lowerX, upperY); } } diff --git a/AdventOfCode/Problems/AOC2023/Day1/Trebuchet.cs b/AdventOfCode/Problems/AOC2023/Day1/Trebuchet.cs index 8402a62..5a0dc59 100644 --- a/AdventOfCode/Problems/AOC2023/Day1/Trebuchet.cs +++ b/AdventOfCode/Problems/AOC2023/Day1/Trebuchet.cs @@ -1,14 +1,5 @@ using AdventOfCode.Runner.Attributes; -using Superpower.Parsers; - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading.Tasks; - namespace AdventOfCode.Problems.AOC2023.Day1; [ProblemInfo(2023, 1, "Trebuchet!?")] @@ -20,6 +11,7 @@ public partial class Trebuchet : Problem { _inputData = ReadInputLines(); } + public override void CalculatePart1() { Part1 = _inputData.Select(GetCalibrationValues) @@ -48,7 +40,7 @@ public partial class Trebuchet : Problem return (left, right); } - private readonly (string word, int value)[] _numberWords = new [] + private readonly (string word, int value)[] _numberWords = new[] { ("one", 1), ("two", 2), @@ -78,13 +70,14 @@ public partial class Trebuchet : Problem { left = word; break; - }else if(line[i] - '0' >= 10) + } + else if (line[i] - '0' >= 10) continue; left = line[i] - '0'; break; } - + for (int i = line.Length - 1; i >= 0; i--) { var word = _numberWords.FirstOrDefault(v => line[..(i + 1)].EndsWith(v.word, StringComparison.Ordinal), (word: "", value: -1)).value; @@ -101,4 +94,4 @@ public partial class Trebuchet : Problem } return (left, right); } -} +} \ No newline at end of file diff --git a/AdventOfCode/Problems/AOC2023/Day2/CubeConundrum.cs b/AdventOfCode/Problems/AOC2023/Day2/CubeConundrum.cs index 5310486..88fef56 100644 --- a/AdventOfCode/Problems/AOC2023/Day2/CubeConundrum.cs +++ b/AdventOfCode/Problems/AOC2023/Day2/CubeConundrum.cs @@ -1,12 +1,7 @@ using AdventOfCode.Runner.Attributes; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace AdventOfCode.Problems.AOC2023.Day2; + [ProblemInfo(2023, 2, "Cube Conundrum")] internal class CubeConundrum : Problem { @@ -33,4 +28,4 @@ internal class CubeConundrum : Problem return _gameInfo.Where(g => !g.Rounds.Any(r => !r.IsPossible(constraints))) .Select(r => r.Id); } -} +} \ No newline at end of file diff --git a/AdventOfCode/Problems/AOC2023/Day2/CubeGame.cs b/AdventOfCode/Problems/AOC2023/Day2/CubeGame.cs index 8fe8283..0d9291b 100644 --- a/AdventOfCode/Problems/AOC2023/Day2/CubeGame.cs +++ b/AdventOfCode/Problems/AOC2023/Day2/CubeGame.cs @@ -1,12 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection.PortableExecutable; -using System.Security.Cryptography; -using System.Text; -using System.Threading.Tasks; - -namespace AdventOfCode.Problems.AOC2023.Day2; +namespace AdventOfCode.Problems.AOC2023.Day2; internal class CubeGame { @@ -25,12 +17,12 @@ internal class CubeGame Rounds[i] = CubeRound.ParseRound(roundsData[i]); } - public CubeRound GetMinimalConstraints() + public CubeRound GetMinimalConstraints() { var (r, g, b) = (0, 0, 0); foreach (var round in Rounds) { - if(round.Red > r) + if (round.Red > r) r = round.Red; if (round.Green > g) g = round.Green; @@ -54,15 +46,15 @@ internal record struct CubeRound(int Red, int Green, int Blue) var count = int.Parse(info[0]); switch (info[1]) { - case "red": + case ['r', ..]: r = count; break; - case "green": + case ['g', ..]: g = count; break; - case "blue": + case ['b', ..]: b = count; break; } @@ -72,7 +64,7 @@ internal record struct CubeRound(int Red, int Green, int Blue) public readonly bool IsPossible(CubeRound constraints) { - if(Red > constraints.Red) + if (Red > constraints.Red) return false; if (Green > constraints.Green) return false; @@ -86,4 +78,4 @@ internal record struct CubeRound(int Red, int Green, int Blue) { return Red * Green * Blue; } -}; +}; \ No newline at end of file diff --git a/AdventOfCode/Program.cs b/AdventOfCode/Program.cs index 95aa677..e189676 100644 --- a/AdventOfCode/Program.cs +++ b/AdventOfCode/Program.cs @@ -1,5 +1,4 @@ - -global using AdventOfCode.Runner; +global using AdventOfCode.Runner; namespace AdventOfCode; diff --git a/AdventOfCode/Runner/AOCRunner.cs b/AdventOfCode/Runner/AOCRunner.cs index 1c995b8..0f1bb82 100644 --- a/AdventOfCode/Runner/AOCRunner.cs +++ b/AdventOfCode/Runner/AOCRunner.cs @@ -25,8 +25,8 @@ public class AOCRunner _years = new List(); _selectedYear = DateTime.Now.Year; FindProblemClasses(); - - if(!_loadedProblems.ContainsKey(_selectedYear)) + + if (!_loadedProblems.ContainsKey(_selectedYear)) _selectedYear = _loadedProblems.Keys.First(); InitSizing(); @@ -291,7 +291,7 @@ public class AOCRunner Console.Write(" Problems "); RenderProblemList(); } - else + else RenderProblemResults(); } diff --git a/AdventOfCode/Runner/Attributes/ProblemInfoAttribute.cs b/AdventOfCode/Runner/Attributes/ProblemInfoAttribute.cs index 3fdb609..1ba6334 100644 --- a/AdventOfCode/Runner/Attributes/ProblemInfoAttribute.cs +++ b/AdventOfCode/Runner/Attributes/ProblemInfoAttribute.cs @@ -1,9 +1,11 @@ namespace AdventOfCode.Runner.Attributes; + public class ProblemInfoAttribute : Attribute { public int Day { get; init; } public int Year { get; init; } public string Name { get; init; } + public ProblemInfoAttribute(int year, int day, string name) { Year = year;