Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace SantasDeliveryRoute
- {
- class Program
- {
- static void Main(string[] args)
- {
- //import the file as string
- string input = System.IO.File.ReadAllText("input.txt");
- int xSantaPos = input.Length;
- int ySantaPos = input.Length;
- int xRoboSantaPos = input.Length;
- int yRoboSantaPos = input.Length;
- int prezzieDeliveryCounter = 0;
- int[,] houses = new int[input.Length * 2, input.Length * 2];
- int uniquehouses = 0;
- bool bSantasTurn = true;
- //Santa's First Present
- houses[xSantaPos, ySantaPos]++;
- prezzieDeliveryCounter++;
- uniquehouses++;
- Console.WriteLine("{0} Total Presents Delivered to {1} unique houses", prezzieDeliveryCounter, uniquehouses);
- //RoboSanta's First Present
- houses[xRoboSantaPos, yRoboSantaPos]++;
- prezzieDeliveryCounter++;
- Console.WriteLine("{0} Total Presents Delivered to {1} unique houses", prezzieDeliveryCounter, uniquehouses);
- foreach (char dirToGo in input)
- {
- //Track Santa's Movement
- if (bSantasTurn)
- {
- switch (dirToGo)
- {
- case '^':
- ySantaPos++;
- break;
- case 'v':
- ySantaPos--;
- break;
- case '>':
- xSantaPos++;
- break;
- case '<':
- xSantaPos--;
- break;
- }
- //Deliver a present at the current pos
- houses[xSantaPos, ySantaPos]++;
- prezzieDeliveryCounter++;
- if (houses[xSantaPos, ySantaPos] == 1)
- {
- uniquehouses++;
- }
- bSantasTurn = false;
- }
- else //Track RoboSanta's Movement
- {
- switch (dirToGo)
- {
- case '^':
- yRoboSantaPos++;
- break;
- case 'v':
- yRoboSantaPos--;
- break;
- case '>':
- xRoboSantaPos++;
- break;
- case '<':
- xRoboSantaPos--;
- break;
- }
- //Deliver a present at the current pos
- houses[xRoboSantaPos, yRoboSantaPos]++;
- prezzieDeliveryCounter++;
- if (houses[xRoboSantaPos, yRoboSantaPos] == 1)
- {
- uniquehouses++;
- }
- bSantasTurn = true;
- }
- Console.WriteLine("{0} Total Presents Delivered to {1} unique houses", prezzieDeliveryCounter, uniquehouses);
- }
- // Suspend the screen.
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement