Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Regex;
- namespace Application
- {
- static class EmptyClass
- {
- static void ForEach(this int[] ints, Action<int> action)
- {
- foreach (int i in ints)
- action(i);
- }
- static void Main()
- {
- int x = 0;
- int y = 0;
- string xString = x.ToString();
- string yString = y.ToString();
- string direction = "north";
- List<Dictionary<string, string>> Locations = new List<Dictionary<string, string>>();
- var stringinput = new Dictionary<string, string>();
- stringinput.Add(xString, yString);
- Console.WriteLine("Insert directions(R1, R2, L3 etc...: ");
- string s = Console.ReadLine();
- string[] words = s.Split(',');
- foreach (string word in words)
- {
- var Rwords = word;
- if (Regex.IsMatch(Rwords, "R"))
- {
- Regex re = new Regex(@"\d+");
- Match m = re.Match(Rwords);
- if (direction == "north")
- {
- x = x + Convert.ToInt32(m.Value);
- direction = "east";
- Console.WriteLine("Your location is (x{0},y{1})", x, y);
- Locations.Add(stringinput);
- }
- else if (direction == "east")
- {
- y = y - Convert.ToInt32(m.Value);
- direction = "south";
- Console.WriteLine("Your location is (x{0},y{1})", x, y);
- Locations.Add(stringinput);
- }
- else if (direction == "south")
- {
- x = x - Convert.ToInt32(m.Value);
- direction = "west";
- Console.WriteLine("Your location is (x{0},y{1})", x, y);
- Locations.Add(stringinput);
- }
- else if (direction == "west")
- {
- y = y + Convert.ToInt32(m.Value);
- direction = "north";
- Console.WriteLine("Your location is (x{0},y{1})", x, y);
- Locations.Add(stringinput);
- }
- }
- var Lwords = word;
- if (Regex.IsMatch(Lwords, "L"))
- {
- Regex re = new Regex(@"\d+");
- Match m = re.Match(Rwords);
- if (direction == "north")
- {
- x = x - Convert.ToInt32(m.Value);
- direction = "west";
- Console.WriteLine("Your location is (x{0},y{1})", x, y);
- Locations.Add(stringinput);
- }
- else if (direction == "west")
- {
- y = y - Convert.ToInt32(m.Value);
- direction = "south";
- Console.WriteLine("Your location is (x{0},y{1})", x, y);
- Locations.Add(stringinput);
- }
- else if (direction == "south")
- {
- x = x + Convert.ToInt32(m.Value);
- direction = "east";
- Console.WriteLine("Your location is (x{0},y{1})", x, y);
- Locations.Add(stringinput);
- }
- else if (direction == "east")
- {
- y = y + Convert.ToInt32(m.Value);
- direction = "north";
- Console.WriteLine("Your location is (x{0},y{1})", x, y);
- Locations.Add(stringinput);
- }
- }
- }
- int Distance = x + y;
- Distance *= -1;
- Console.WriteLine("Calculating distance to HQ......");
- Console.WriteLine("Your location is (x{0},y{1}) wich is {2} Blocks away from Easter Bunny HQ", x, y, Distance, ",");
- var duplicates = Locations
- .GroupBy(i => i)
- .Where(g => g.Count() > 1)
- .Select(g => g.Key);
- foreach (var d in duplicates)
- Console.WriteLine(d);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement