Skip to content

Instantly share code, notes, and snippets.

@atrauzzi
Created December 14, 2015 01:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atrauzzi/a442eecadbd0c4794c21 to your computer and use it in GitHub Desktop.
Save atrauzzi/a442eecadbd0c4794c21 to your computer and use it in GitHub Desktop.
Advent of Code - Day 3 Part 1
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();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment