From 8c91d6e206898ded4bb7b66d3b130733e77361e2 Mon Sep 17 00:00:00 2001 From: cyberdick Date: Sat, 3 Dec 2022 17:54:47 +0530 Subject: [PATCH] cleanup of old code finsihed day 2 --- AOC2022/AOC2022.csproj.user | 2 +- AOC2022/Program.cs | 5 +- AOC2022/Properties/launchSettings.json | 5 +- AOC2022/Puzzles/Day1.cs | 46 ++++++++++------ AOC2022/Puzzles/Day2.cs | 31 +++++++---- AOC2022/Puzzles/Day3.cs | 6 --- AOC2022/Puzzles/IPuzzle.cs | 6 --- AOCDayOne/AOCDayOne.csproj | 10 ---- AOCDayOne/Program.cs | 69 ------------------------ AOCDayOne/Properties/launchSettings.json | 9 ---- AdventOfCode.sln | 6 --- 11 files changed, 56 insertions(+), 139 deletions(-) delete mode 100644 AOCDayOne/AOCDayOne.csproj delete mode 100644 AOCDayOne/Program.cs delete mode 100644 AOCDayOne/Properties/launchSettings.json diff --git a/AOC2022/AOC2022.csproj.user b/AOC2022/AOC2022.csproj.user index 36d9b15..be47c2d 100644 --- a/AOC2022/AOC2022.csproj.user +++ b/AOC2022/AOC2022.csproj.user @@ -4,6 +4,6 @@ ProjectDebugger - WithoutParams + WithParams \ No newline at end of file diff --git a/AOC2022/Program.cs b/AOC2022/Program.cs index a876ddb..a5070cc 100644 --- a/AOC2022/Program.cs +++ b/AOC2022/Program.cs @@ -1,7 +1,5 @@ using AOC2022.Puzzles; -using System.Linq.Expressions; - namespace AOC2022; internal static class Program @@ -37,11 +35,9 @@ internal static class Program return; } daysToProcess.Add(dayNumber); - } ProcessDays(daysToProcess); } - } catch (Exception e) { @@ -63,6 +59,7 @@ internal static class Program { if (Activator.CreateInstance(typeName, new object[] { linesInFile }) is IPuzzle puzzle) { + Console.WriteLine($"Day {day} answers"); puzzle.FirstPuzzle(); puzzle.SecondPuzzle(); } diff --git a/AOC2022/Properties/launchSettings.json b/AOC2022/Properties/launchSettings.json index 2ac8753..0a2369f 100644 --- a/AOC2022/Properties/launchSettings.json +++ b/AOC2022/Properties/launchSettings.json @@ -2,13 +2,12 @@ "profiles": { "WithParams": { "commandName": "Project", - "commandLineArgs": "1 2 3" + "commandLineArgs": "1 2", + "workingDirectory": "./" }, "WithoutParams": { "commandName": "Project", "workingDirectory": "./" - - //"commandLineArgs": "1 2 3" } } } \ No newline at end of file diff --git a/AOC2022/Puzzles/Day1.cs b/AOC2022/Puzzles/Day1.cs index 4a9f641..b4376b3 100644 --- a/AOC2022/Puzzles/Day1.cs +++ b/AOC2022/Puzzles/Day1.cs @@ -1,31 +1,47 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace AOC2022.Puzzles; internal class Day1 : IPuzzle { - private readonly string[] linesFromFile; + private readonly string[] _linesFromFile; + private readonly List _elfFoodSumList = new(); public Day1(string[] linesFromFile) { - this.linesFromFile = linesFromFile; + _linesFromFile = linesFromFile; + try + { + GetElfFoodSumList(); + } + catch (Exception) + { + throw; + } + } + void GetElfFoodSumList() + { + var elfFoodSum = 0; + //var elfFoodSumList = new List(); + foreach (var line in _linesFromFile) + { + if (!string.IsNullOrWhiteSpace(line)) + { + elfFoodSum += int.Parse(line); + } + else + { + _elfFoodSumList.Add(elfFoodSum); + elfFoodSum = 0; + } + _elfFoodSumList.Sort((x, y) => y.CompareTo(x)); + } } - public void FirstPuzzle() { - foreach (var line in linesFromFile) - { - Console.WriteLine(line); - } + Console.WriteLine($"Fattest fucker has {_elfFoodSumList[0]} borgers"); } public void SecondPuzzle() { - throw new NotImplementedException(); + Console.WriteLine($"Top 3 Fatties have {_elfFoodSumList.Take(3).Sum()} borgers"); } } - diff --git a/AOC2022/Puzzles/Day2.cs b/AOC2022/Puzzles/Day2.cs index a62fd50..d3354d4 100644 --- a/AOC2022/Puzzles/Day2.cs +++ b/AOC2022/Puzzles/Day2.cs @@ -1,21 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace AOC2022.Puzzles; internal class Day2 : IPuzzle { + private readonly string[] _linesFromFile; + + public Day2(string[] linesFromFile) + { + _linesFromFile = linesFromFile; + } public void FirstPuzzle() { - throw new NotImplementedException(); + int score = 0; + + foreach (var line in _linesFromFile) + { + score += ((line[2] - line[0] - 1) % 3 * 3) + (line[2] - 'X' + 1); + } + Console.WriteLine($"Elf trickery knows no bounds, without the elf the score is {score}"); } public void SecondPuzzle() { - throw new NotImplementedException(); - } -} + int score = 0; + foreach (var line in _linesFromFile) + { + score += ((line[0] - 'A' + line[2] - 'X' + 2) % 3) + 1 + (line[2] - 'X') * 3; + } + Console.WriteLine($"Elf trickery knows no bounds, with the elf help the score is {score}"); + } +} \ No newline at end of file diff --git a/AOC2022/Puzzles/Day3.cs b/AOC2022/Puzzles/Day3.cs index ef762c7..5743f31 100644 --- a/AOC2022/Puzzles/Day3.cs +++ b/AOC2022/Puzzles/Day3.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace AOC2022.Puzzles; internal class Day3 : IPuzzle diff --git a/AOC2022/Puzzles/IPuzzle.cs b/AOC2022/Puzzles/IPuzzle.cs index 3cd47b6..8f07d80 100644 --- a/AOC2022/Puzzles/IPuzzle.cs +++ b/AOC2022/Puzzles/IPuzzle.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace AOC2022.Puzzles { internal interface IPuzzle diff --git a/AOCDayOne/AOCDayOne.csproj b/AOCDayOne/AOCDayOne.csproj deleted file mode 100644 index f02677b..0000000 --- a/AOCDayOne/AOCDayOne.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - - Exe - net7.0 - enable - enable - - - diff --git a/AOCDayOne/Program.cs b/AOCDayOne/Program.cs deleted file mode 100644 index 9ba101e..0000000 --- a/AOCDayOne/Program.cs +++ /dev/null @@ -1,69 +0,0 @@ -namespace AOCDayOne; - -internal static class Program -{ - private static async Task Main(string[] args) - { - switch (args.Length) - { - case 0: - Console.WriteLine("Nigga enter the filename!"); - break; - case 1: - { - var result = await ProcessElfFoodListFile(args[0]); - if (result is not null) - { - Console.WriteLine($"Fattest fucker has {result[0]} borgers"); - Console.WriteLine($"Top 3 Fatties have {result.Take(3).Sum()} borgers"); - } - else - { - Console.WriteLine("Processing error/File not found"); - } - break; - } - default: - Console.WriteLine("I don't even know what the fuck you typed, just the filename as argument"); - break; - } - } - - private static async Task?> ProcessElfFoodListFile(string filename) - { - //Set Current Directory in launchSettings.json or rider launch profiles - //var currentDirectory = Directory.GetCurrentDirectory(); - if (!File.Exists(filename)) return null; - - try - { - var lines = await File.ReadAllLinesAsync(filename); //no i dont care about memory poorcels out - var elfFoodSum = 0; - var elfFoodSumList = new List(); - foreach (var line in lines) - { - if (!string.IsNullOrWhiteSpace(line)) - { - elfFoodSum += int.Parse(line); - } - else - { - elfFoodSumList.Add(elfFoodSum); - elfFoodSum = 0; - } - elfFoodSumList.Sort((x, y) => y.CompareTo(x)); - } - - //elfFoodSumList.ForEach(Console.WriteLine); - //Console.WriteLine(elfFoodSumList.Count); - //Console.WriteLine(elfFoodSumList.Max()); - return elfFoodSumList; - } - catch (Exception ex) - { - Console.WriteLine($"Shieeeeeeeetttt I Crashed!! coz of this {ex}"); - } - - return null; - } -} \ No newline at end of file diff --git a/AOCDayOne/Properties/launchSettings.json b/AOCDayOne/Properties/launchSettings.json deleted file mode 100644 index 943a3e7..0000000 --- a/AOCDayOne/Properties/launchSettings.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "profiles": { - "InputTxtParam": { - "commandName": "Project", - "commandLineArgs": "input.txt", - "workingDirectory": ".\\" - } - } -} \ No newline at end of file diff --git a/AdventOfCode.sln b/AdventOfCode.sln index 4138cd2..2c5d535 100644 --- a/AdventOfCode.sln +++ b/AdventOfCode.sln @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.4.33122.133 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AOCDayOne", "AOCDayOne\AOCDayOne.csproj", "{9A5F75A3-4FD2-4CE1-9047-639AE19F86A1}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{99F5AC62-C5E8-4264-A511-C2ED59988EDA}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig @@ -18,10 +16,6 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {9A5F75A3-4FD2-4CE1-9047-639AE19F86A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9A5F75A3-4FD2-4CE1-9047-639AE19F86A1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9A5F75A3-4FD2-4CE1-9047-639AE19F86A1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9A5F75A3-4FD2-4CE1-9047-639AE19F86A1}.Release|Any CPU.Build.0 = Release|Any CPU {E9B704DE-D6D2-4A72-971D-28E9F326B6EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E9B704DE-D6D2-4A72-971D-28E9F326B6EA}.Debug|Any CPU.Build.0 = Debug|Any CPU {E9B704DE-D6D2-4A72-971D-28E9F326B6EA}.Release|Any CPU.ActiveCfg = Release|Any CPU