Created
December 14, 2015 01:53
Revisions
-
atrauzzi created this gist
Dec 14, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,70 @@ namespace Day3Part1 { using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; public static class Extensions { public static void DeliverPresent(this Dictionary<Tuple<int, int>, int> houses, Tuple<int, int> house) { if (houses.ContainsKey(house)) houses[house] += 1; else houses[house] = 1; } public static Tuple<int, int> GoRight(this Tuple<int, int> currentHouse) { return new Tuple<int, int>(currentHouse.Item1 + 1, currentHouse.Item2); } public static Tuple<int, int> GoLeft(this Tuple<int, int> currentHouse) { return new Tuple<int, int>(currentHouse.Item1 - 1, currentHouse.Item2); } public static Tuple<int, int> GoUp(this Tuple<int, int> currentHouse) { return new Tuple<int, int>(currentHouse.Item1, currentHouse.Item2 + 1); } public static Tuple<int, int> GoDown(this Tuple<int, int> currentHouse) { return new Tuple<int, int>(currentHouse.Item1, currentHouse.Item2 - 1); } } public class Program { public static void Main(string[] args) { Dictionary<Tuple<int, int>, int> houses = new Dictionary<Tuple<int,int>, int>(); string input = File.ReadAllText("Input.txt"); Tuple<int, int> currentHouse = new Tuple<int, int>(0, 0); // For some reason, we deliver to where we're at. So do that. houses.DeliverPresent(currentHouse); foreach(char instruction in input) { if (instruction == '<') currentHouse = currentHouse.GoLeft(); else if (instruction == '>') currentHouse = currentHouse.GoRight(); else if (instruction == '^') currentHouse = currentHouse.GoUp(); else if (instruction == 'v') currentHouse = currentHouse.GoDown(); houses.DeliverPresent(currentHouse); } Console.WriteLine($"{houses.Count()} houses got presents!"); Console.ReadKey(); } } }