Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.54 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Regex;
  6.  
  7. namespace Application
  8. {
  9.     static class EmptyClass
  10.     {
  11.         static void ForEach(this int[] ints, Action<int> action)
  12.         {
  13.             foreach (int i in ints)
  14.                 action(i);
  15.         }
  16.  
  17.         static void Main()
  18.         {
  19.             int x = 0;
  20.             int y = 0;
  21.             string xString = x.ToString();
  22.             string yString = y.ToString();
  23.             string direction = "north";
  24.  
  25.             List<Dictionary<string, string>> Locations = new List<Dictionary<string, string>>();
  26.             var stringinput = new Dictionary<string, string>();
  27.             stringinput.Add(xString, yString);
  28.             Console.WriteLine("Insert directions(R1, R2, L3 etc...: ");
  29.             string s = Console.ReadLine();
  30.             string[] words = s.Split(',');
  31.             foreach (string word in words)
  32.             {
  33.                 var Rwords = word;
  34.                 if (Regex.IsMatch(Rwords, "R"))
  35.                 {
  36.                     Regex re = new Regex(@"\d+");
  37.                     Match m = re.Match(Rwords);
  38.  
  39.                     if (direction == "north")
  40.                     {
  41.                         x = x + Convert.ToInt32(m.Value);
  42.                         direction = "east";
  43.                         Console.WriteLine("Your location is (x{0},y{1})", x, y);
  44.                         Locations.Add(stringinput);
  45.                     }
  46.                     else if (direction == "east")
  47.                     {
  48.                         y = y - Convert.ToInt32(m.Value);
  49.                         direction = "south";
  50.                         Console.WriteLine("Your location is (x{0},y{1})", x, y);
  51.                         Locations.Add(stringinput);
  52.                     }
  53.                     else if (direction == "south")
  54.                     {
  55.                         x = x - Convert.ToInt32(m.Value);
  56.                         direction = "west";
  57.                         Console.WriteLine("Your location is (x{0},y{1})", x, y);
  58.                         Locations.Add(stringinput);
  59.                     }
  60.                     else if (direction == "west")
  61.                     {
  62.                         y = y + Convert.ToInt32(m.Value);
  63.                         direction = "north";
  64.                         Console.WriteLine("Your location is (x{0},y{1})", x, y);
  65.                         Locations.Add(stringinput);
  66.                     }
  67.                 }
  68.                 var Lwords = word;
  69.                 if (Regex.IsMatch(Lwords, "L"))
  70.                 {
  71.                     Regex re = new Regex(@"\d+");
  72.                     Match m = re.Match(Rwords);
  73.  
  74.                     if (direction == "north")
  75.                     {
  76.                         x = x - Convert.ToInt32(m.Value);
  77.                         direction = "west";
  78.                         Console.WriteLine("Your location is (x{0},y{1})", x, y);
  79.                         Locations.Add(stringinput);
  80.                     }
  81.  
  82.                     else if (direction == "west")
  83.                     {
  84.                         y = y - Convert.ToInt32(m.Value);
  85.                         direction = "south";
  86.                         Console.WriteLine("Your location is (x{0},y{1})", x, y);
  87.                         Locations.Add(stringinput);
  88.                     }
  89.                     else if (direction == "south")
  90.                     {
  91.                         x = x + Convert.ToInt32(m.Value);
  92.                         direction = "east";
  93.                         Console.WriteLine("Your location is (x{0},y{1})", x, y);
  94.                         Locations.Add(stringinput);
  95.                     }
  96.                     else if (direction == "east")
  97.                     {
  98.                         y = y + Convert.ToInt32(m.Value);
  99.                         direction = "north";
  100.                         Console.WriteLine("Your location is (x{0},y{1})", x, y);
  101.                         Locations.Add(stringinput);
  102.                     }
  103.                 }
  104.             }
  105.             int Distance = x + y;
  106.             Distance *= -1;
  107.             Console.WriteLine("Calculating distance to HQ......");
  108.             Console.WriteLine("Your location is (x{0},y{1}) wich is {2} Blocks away from Easter Bunny HQ", x, y, Distance, ",");
  109.             var duplicates = Locations
  110.             .GroupBy(i => i)
  111.             .Where(g => g.Count() > 1)
  112.             .Select(g => g.Key);
  113.  
  114.             foreach (var d in duplicates)
  115.                 Console.WriteLine(d);
  116.  
  117.         }
  118.     }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement