Initial Commit
This commit is contained in:
45
2022/Day01CSharp/Program.cs
Normal file
45
2022/Day01CSharp/Program.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
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]));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user