Automatic code cleanup
This commit is contained in:
@@ -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<int, int>
|
||||
{
|
||||
@@ -59,4 +55,4 @@ internal class LookAndSay : Problem<int, int>
|
||||
|
||||
input = next;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ public class NiceList : Problem<int, int>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsNice2(string value)
|
||||
{
|
||||
var pairs = new Dictionary<string, List<int>>();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<int, int>
|
||||
{
|
||||
@@ -33,4 +27,4 @@ internal class ChanceOfAsteroids : Problem<int, int>
|
||||
{
|
||||
_baseInput = InputParsing.ParseIntCsv(GetInputFile("input.csv"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<int, int>
|
||||
{
|
||||
@@ -14,7 +9,7 @@ internal class UniversalOrbits : Problem<int, int>
|
||||
|
||||
public override void CalculatePart1()
|
||||
{
|
||||
if(_map == null)
|
||||
if (_map == null)
|
||||
return;
|
||||
Part1 = _map.CalculateOrbits();
|
||||
}
|
||||
@@ -31,7 +26,6 @@ internal class UniversalOrbits : Problem<int, int>
|
||||
|
||||
HashSet<string> 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<int, int>
|
||||
}
|
||||
}
|
||||
Part2 = dist - 2;
|
||||
|
||||
}
|
||||
|
||||
public override void LoadInput()
|
||||
{
|
||||
_map = new OrbitMap(ReadInputLines());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<int, int>, IEnumerable<byte>
|
||||
{
|
||||
Increment(ref data);
|
||||
Flash(ref data, ref flashes);
|
||||
|
||||
}
|
||||
|
||||
private static void Increment(ref byte[] data)
|
||||
|
||||
@@ -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<int, int>
|
||||
|
||||
Part2 = oxygenLevel * carbonLevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<long, long>
|
||||
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<long, long>
|
||||
|
||||
return lifetimes.Sum();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
@@ -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<List<int>>
|
||||
{
|
||||
new List<int>()
|
||||
@@ -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<int>());
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<int, int> 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++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -25,11 +25,10 @@ internal class CathodeRayTube : Problem<int, string>
|
||||
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] = '█';
|
||||
});
|
||||
|
||||
|
||||
@@ -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)}]";
|
||||
}
|
||||
}
|
||||
@@ -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<int, int>
|
||||
{
|
||||
@@ -37,7 +31,6 @@ internal class MonkeyInTheMiddle : Problem<int, int>
|
||||
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<int, int>
|
||||
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<int, int>
|
||||
}
|
||||
monkey.Items.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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<string>();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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<int, int>
|
||||
{
|
||||
@@ -19,7 +13,7 @@ internal class CampCleanup : Problem<int, int>
|
||||
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<int, int>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void CalculatePart1()
|
||||
{
|
||||
var total = 0;
|
||||
@@ -50,10 +43,9 @@ internal class CampCleanup : Problem<int, int>
|
||||
{
|
||||
if (a.OverlapsWith(b))
|
||||
Part2++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
record Range(int A, int B)
|
||||
{
|
||||
public bool Contains(Range other)
|
||||
@@ -66,6 +58,6 @@ internal class CampCleanup : Problem<int, int>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<char>[] _stacksPart1 = Array.Empty<List<char>>();
|
||||
private List<char>[] _stacksPart2 = Array.Empty<List<char>>();
|
||||
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<char>[] 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<int, int>
|
||||
{
|
||||
_input = ReadInputText();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<DirectoryNode> Where(Func<DirectoryNode, bool> filter)
|
||||
{
|
||||
var result = new List<DirectoryNode>();
|
||||
if(filter(this))
|
||||
if (filter(this))
|
||||
result.Add(this);
|
||||
result.AddRange(Children.SelectMany(c => c.Where(filter)));
|
||||
return result;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace AdventOfCode.Problems.AOC2022.Day7;
|
||||
|
||||
[ProblemInfo(2022, 7, "No Space Left On Device")]
|
||||
internal class NoSpace : Problem<int,int>
|
||||
internal class NoSpace : Problem<int, int>
|
||||
{
|
||||
private DirectoryNode _dirTree = new DirectoryNode("/");
|
||||
|
||||
@@ -37,7 +37,8 @@ internal class NoSpace : Problem<int,int>
|
||||
ParseCommand(line[2..], ref curDir);
|
||||
dir = $"/{string.Join("/", curDir.Reverse())}";
|
||||
_dirTree.AddDirectory(dir);
|
||||
}else
|
||||
}
|
||||
else
|
||||
ReadDirectory(line, _dirTree.GetDirectory(dir)!);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<int, int>
|
||||
{
|
||||
_inputData = ReadInputLines();
|
||||
}
|
||||
|
||||
public override void CalculatePart1()
|
||||
{
|
||||
Part1 = _inputData.Select(GetCalibrationValues)
|
||||
@@ -48,7 +40,7 @@ public partial class Trebuchet : Problem<int, int>
|
||||
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<int, int>
|
||||
{
|
||||
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<int, int>
|
||||
}
|
||||
return (left, right);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<int, int>
|
||||
{
|
||||
@@ -33,4 +28,4 @@ internal class CubeConundrum : Problem<int, int>
|
||||
return _gameInfo.Where(g => !g.Rounds.Any(r => !r.IsPossible(constraints)))
|
||||
.Select(r => r.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
global using AdventOfCode.Runner;
|
||||
global using AdventOfCode.Runner;
|
||||
|
||||
namespace AdventOfCode;
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ public class AOCRunner
|
||||
_years = new List<int>();
|
||||
_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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user