From 5b3d4ca1f74bfbd9d795c470375b3ada6b20c780 Mon Sep 17 00:00:00 2001 From: Brandon Scott Date: Mon, 11 Dec 2017 21:16:29 -0600 Subject: [PATCH] Adding Day 1 Solution --- csharp/Day1Solution.cs | 51 ++++++++++++++++++++++++++++++++++++++++++ csharp/Solution.cs | 15 +++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 csharp/Day1Solution.cs create mode 100644 csharp/Solution.cs diff --git a/csharp/Day1Solution.cs b/csharp/Day1Solution.cs new file mode 100644 index 0000000..fe37c30 --- /dev/null +++ b/csharp/Day1Solution.cs @@ -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; + } + } +} diff --git a/csharp/Solution.cs b/csharp/Solution.cs new file mode 100644 index 0000000..1b2f895 --- /dev/null +++ b/csharp/Solution.cs @@ -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(); + } +}