Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HashSet<(int x, int y)> wireone = new HashSet<(int x, int y)>();
- Dictionary<(int, int), int> stepsone = new Dictionary<(int, int), int>();
- int x = 0;
- int y = 0;
- int totalstep = 0;
- foreach( string step in wires[0].Split(','))
- {
- string dir = step[0].ToString();
- int n = Convert.ToInt32( step.Substring(1) );
- int xd=0;
- int yd=0;
- if( dir == "U") { xd = 0; yd = -1;}
- if (dir == "D") { xd = 0; yd = 1; }
- if (dir == "L") { xd = -1; yd = 0; }
- if (dir == "R") { xd = 1; yd = 0; }
- for( int s=0;s<n;s++ )
- {
- if( !stepsone.ContainsKey((x,y)))
- {
- stepsone.Add((x,y), totalstep);
- }
- wireone.Add( (x,y));
- x+=xd;
- y+=yd;
- totalstep++;
- wireone.Add((x, y));
- if (!stepsone.ContainsKey((x, y)))
- {
- stepsone.Add((x, y), totalstep);
- }
- }
- }
- x = 0;
- y = 0;
- int answer = int.MaxValue;
- int steptwo = 0;
- foreach (string step in wires[1].Split(','))
- {
- string dir = step[0].ToString();
- int n = Convert.ToInt32(step.Substring(1));
- int xd = 0;
- int yd = 0;
- if (dir == "U") { xd = 0; yd = -1; }
- if (dir == "D") { xd = 0; yd = 1; }
- if (dir == "L") { xd = -1; yd = 0; }
- if (dir == "R") { xd = 1; yd = 0; }
- for (int s = 0; s < n; s++)
- {
- if( wireone.Contains((x,y)) && !(x == 0 && y == 0))
- {
- int distance = Math.Abs(x) + Math.Abs(y);
- if(distance < answer) answer = distance;
- Console.WriteLine(x + "," + y);
- }
- x += xd;
- y += yd;
- steptwo++;
- if (wireone.Contains((x, y)) && !(x == 0 && y == 0))
- {
- int distance = Math.Abs(x) + Math.Abs(y);
- if (distance < answer) answer = distance;
- Console.WriteLine(x + "," + y);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement