Adding Day 1 Solution

This commit is contained in:
Brandon Scott 2017-12-11 21:16:29 -06:00
parent 64f30504ba
commit 5b3d4ca1f7
2 changed files with 66 additions and 0 deletions

51
csharp/Day1Solution.cs Normal file
View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AOC2015
{
class Day1Solution : Solution
{
public override int Day => 1;
public override string Name => "Day 1: Not Quite Lisp";
public override void Run()
{
string input = File.ReadAllText("Input\\Day1Input.txt");
Console.WriteLine($"Part 1 Answer: {Part1(input)}");
Console.WriteLine($"Part 2 Answer: {Part2(input)}");
}
private int Part1(string input)
{
int floor = 0;
for (int i = 0; i < input.Length; i++)
{
if (input[i] == '(')
floor++;
else if (input[i] == ')')
floor--;
}
return floor;
}
private int Part2(string input)
{
int floor = 0;
for (int i = 0; i < input.Length; i++)
{
if (input[i] == '(')
floor++;
else if (input[i] == ')')
floor--;
if (floor == -1)
return i+1;
}
return -1;
}
}
}

15
csharp/Solution.cs Normal file
View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AOC2015
{
abstract class Solution
{
public abstract string Name { get; }
public abstract int Day { get; }
public abstract void Run();
}
}