From da70944d565ab6c87f8514c9bac7e36cf9935b1e Mon Sep 17 00:00:00 2001 From: Jake Date: Fri, 2 Dec 2022 20:23:35 +0000 Subject: [PATCH] Completed 2015 Day 3 --- 2015/Day-03/Day03.cs | 75 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 2015/Day-03/Day03.cs diff --git a/2015/Day-03/Day03.cs b/2015/Day-03/Day03.cs new file mode 100644 index 0000000..0525a73 --- /dev/null +++ b/2015/Day-03/Day03.cs @@ -0,0 +1,75 @@ +class Santa{ + public int x; + public int y; + + public void move(char direction){ + switch(direction){ + case '^': + this.y++; + break; + case 'v': + this.y--; + break; + case '>': + this.x++; + break; + case '<': + this.x--; + break; + default: + throw new InvalidDataException("Input did not match expected format!"); + } + } +} + +class Program{ + // Load in the input. + static string input = File.ReadAllText(@"input.txt").ToString(); + + static int partOne(){ + Santa santa = new Santa(); + + // Put all houses we've delivered to in a list. + List delivered = new List(); + foreach(char direction in input){ + delivered.Add(santa.x.ToString() + "," + santa.y.ToString()); + santa.move(direction); + } + + // Dedupe the list. + return(delivered.Distinct().ToList().Count()); + } + + static int partTwo(){ + Santa realSanta = new Santa(); + Santa roboSanta = new Santa(); + + // Evry other move, move one set of coordinates and add them to the list. + int currentMove = 0; + List delivered = new List(); + + foreach(char move in input){ + switch(currentMove%2){ + case 0: + delivered.Add(roboSanta.x.ToString() + "," + roboSanta.y.ToString()); + roboSanta.move(move); + break; + default: + delivered.Add(realSanta.x.ToString() + "," + realSanta.y.ToString()); + realSanta.move(move); + break; + + } + currentMove++; + } + + // Return the deduped list. + return(delivered.Distinct().ToList().Count()); + } + + static void Main(){ + // Print Answers. + Console.WriteLine("Part 1: " + partOne().ToString()); + Console.WriteLine("Part 2: " + partTwo().ToString()); + } +}