Add day 2

This commit is contained in:
2022-12-05 13:35:24 +01:00
parent 2dfe5d1bb5
commit 6e55404b19
3 changed files with 2613 additions and 5 deletions

View File

@@ -11,7 +11,7 @@ public class Day1 : Day
{ {
int currentCalories = 0; int currentCalories = 0;
int maxCalories = 0; int maxCalories = 0;
foreach (var line in Input.Split('\n')) foreach (var line in Input.ReadAllLines())
{ {
// Next elf on empty line // Next elf on empty line
if (string.IsNullOrWhiteSpace(line)) if (string.IsNullOrWhiteSpace(line))
@@ -36,7 +36,7 @@ public class Day1 : Day
var elfCalories = new List<int>(); var elfCalories = new List<int>();
int currentCalories = 0; int currentCalories = 0;
foreach (var line in Input.Split('\n')) foreach (var line in Input.ReadAllLines())
{ {
// Next elf on empty line // Next elf on empty line
if (string.IsNullOrWhiteSpace(line)) if (string.IsNullOrWhiteSpace(line))

File diff suppressed because it is too large Load Diff

17
StringExtensions.cs Normal file
View File

@@ -0,0 +1,17 @@
namespace AdventOfCode;
public static class StringExtensions
{
public static IEnumerable<string> ReadAllLines(this StringReader reader)
{
while (reader.ReadLine() is { } line)
{
yield return line;
}
}
public static IEnumerable<string> ReadAllLines(this string text)
{
return new StringReader(text).ReadAllLines();
}
}