cleanup of old code finsihed day 2

master
cyberdick 2022-12-03 17:54:47 +05:30
parent 74fa2da997
commit 8c91d6e206
11 changed files with 56 additions and 139 deletions

View File

@ -4,6 +4,6 @@
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup>
<ActiveDebugProfile>WithoutParams</ActiveDebugProfile>
<ActiveDebugProfile>WithParams</ActiveDebugProfile>
</PropertyGroup>
</Project>

View File

@ -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();
}

View File

@ -2,13 +2,12 @@
"profiles": {
"WithParams": {
"commandName": "Project",
"commandLineArgs": "1 2 3"
"commandLineArgs": "1 2",
"workingDirectory": "./"
},
"WithoutParams": {
"commandName": "Project",
"workingDirectory": "./"
//"commandLineArgs": "1 2 3"
}
}
}

View File

@ -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<int> _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<int>();
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");
}
}

View File

@ -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}");
}
}

View File

@ -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

View File

@ -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

View File

@ -1,10 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -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<List<int>?> 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<int>();
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;
}
}

View File

@ -1,9 +0,0 @@
{
"profiles": {
"InputTxtParam": {
"commandName": "Project",
"commandLineArgs": "input.txt",
"workingDirectory": ".\\"
}
}
}

View File

@ -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