Add day 2
This commit is contained in:
@@ -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))
|
||||||
|
|||||||
2597
Days/Day2.cs
2597
Days/Day2.cs
File diff suppressed because it is too large
Load Diff
17
StringExtensions.cs
Normal file
17
StringExtensions.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user