diff --git a/c#/.gitignore b/c#/.gitignore new file mode 100644 index 0000000..dcab270 --- /dev/null +++ b/c#/.gitignore @@ -0,0 +1 @@ +problem.exe \ No newline at end of file diff --git a/c#/2015/1/problem.cs b/c#/2015/1/problem.cs new file mode 100644 index 0000000..17bddc2 --- /dev/null +++ b/c#/2015/1/problem.cs @@ -0,0 +1,30 @@ +using System; +using System.IO; +class Hello { + static void Main(string[] args) { + using(StreamReader file = new StreamReader("../data/2015/1/input.txt")) { + Int32 c; + int floor = 0; + do { + c = file.Read(); + if ((char)c == '(') floor++; + else if((char)c == ')') floor--; + } while (c != -1); + Console.WriteLine("Part 1: " + floor); + } + + using(StreamReader file = new StreamReader("../data/2015/1/input.txt")) { + Int32 c; + int steps = 0; + int floor = 0; + do { + c = file.Read(); + if ((char)c == '(') floor++; + else if((char)c == ')') floor--; + steps++; + if (floor < 0) break; + } while (c != -1); + Console.WriteLine("Part 2: " + steps); + } + } +} diff --git a/c#/bin/run b/c#/bin/run new file mode 100755 index 0000000..8625d23 --- /dev/null +++ b/c#/bin/run @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +year=$1 +day=$2 + +mcs -out:$year/$day/problem.exe $year/$day/problem.cs && time mono $year/$day/problem.exe