69 lines
1.7 KiB
C#
69 lines
1.7 KiB
C#
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;
|
|
}
|
|
} |