Advertisement
SoundGuyChris

Advent of Code, Day 3: Perfectly Spherical Houses in

Dec 12th, 2015
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.38 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace SantasDeliveryRoute
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             //import the file as string
  11.             string input = System.IO.File.ReadAllText("input.txt");
  12.             int xSantaPos = input.Length;
  13.             int ySantaPos = input.Length;
  14.             int xRoboSantaPos = input.Length;
  15.             int yRoboSantaPos = input.Length;
  16.             int prezzieDeliveryCounter = 0;
  17.             int[,] houses = new int[input.Length * 2, input.Length * 2];
  18.             int uniquehouses = 0;
  19.             bool bSantasTurn = true;
  20.  
  21.             //Santa's First Present
  22.             houses[xSantaPos, ySantaPos]++;
  23.             prezzieDeliveryCounter++;
  24.             uniquehouses++;
  25.             Console.WriteLine("{0} Total Presents Delivered to {1} unique houses", prezzieDeliveryCounter, uniquehouses);
  26.  
  27.             //RoboSanta's First Present
  28.             houses[xRoboSantaPos, yRoboSantaPos]++;
  29.             prezzieDeliveryCounter++;
  30.             Console.WriteLine("{0} Total Presents Delivered to {1} unique houses", prezzieDeliveryCounter, uniquehouses);
  31.  
  32.             foreach (char dirToGo in input)
  33.             {
  34.                 //Track Santa's Movement
  35.                 if (bSantasTurn)
  36.                 {
  37.                     switch (dirToGo)
  38.                     {
  39.                         case '^':
  40.                             ySantaPos++;
  41.                             break;
  42.                         case 'v':
  43.                             ySantaPos--;
  44.                             break;
  45.                         case '>':
  46.                             xSantaPos++;
  47.                             break;
  48.                         case '<':
  49.                             xSantaPos--;
  50.                             break;
  51.                     }
  52.                     //Deliver a present at the current pos
  53.                     houses[xSantaPos, ySantaPos]++;
  54.                     prezzieDeliveryCounter++;
  55.                     if (houses[xSantaPos, ySantaPos] == 1)
  56.                     {
  57.                         uniquehouses++;
  58.                     }
  59.                     bSantasTurn = false;
  60.                 }
  61.                 else //Track RoboSanta's Movement
  62.                 {
  63.                     switch (dirToGo)
  64.                     {
  65.                         case '^':
  66.                             yRoboSantaPos++;
  67.                             break;
  68.                         case 'v':
  69.                             yRoboSantaPos--;
  70.                             break;
  71.                         case '>':
  72.                             xRoboSantaPos++;
  73.                             break;
  74.                         case '<':
  75.                             xRoboSantaPos--;
  76.                             break;
  77.                     }
  78.                     //Deliver a present at the current pos
  79.                     houses[xRoboSantaPos, yRoboSantaPos]++;
  80.                     prezzieDeliveryCounter++;
  81.                     if (houses[xRoboSantaPos, yRoboSantaPos] == 1)
  82.                     {
  83.                         uniquehouses++;
  84.                     }
  85.                     bSantasTurn = true;
  86.                 }
  87.  
  88.                 Console.WriteLine("{0} Total Presents Delivered to {1} unique houses", prezzieDeliveryCounter, uniquehouses);
  89.             }
  90.  
  91.             // Suspend the screen.
  92.             Console.ReadLine();
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement