46 lines
1.2 KiB
C#
46 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
|
|
|
|
namespace Day01CSharp
|
|
{
|
|
internal class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
var fileName = @"data\input.txt";
|
|
|
|
List<int> elves = new List<int>();
|
|
int elfNum = 0;
|
|
|
|
using (StreamReader reader = File.OpenText(fileName))
|
|
{
|
|
elfNum = 0;
|
|
int currentTotal = 0;
|
|
|
|
while (!reader.EndOfStream)
|
|
{
|
|
string line = reader.ReadLine();
|
|
|
|
int result;
|
|
if (Int32.TryParse(line, out result))
|
|
{
|
|
currentTotal += result;
|
|
}
|
|
else
|
|
{
|
|
elves.Add(currentTotal);
|
|
currentTotal = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
elves.Sort();
|
|
Console.WriteLine("Part01: " + elves[elves.Count-1]);
|
|
Console.WriteLine("Part02: " + (elves[elves.Count - 1] + elves[elves.Count - 3] + elves[elves.Count - 2]));
|
|
}
|
|
}
|
|
}
|