| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace D23._1
- {
- class Program
- {
- static int Manhattan((int x, int y, int z, int) a, (int x, int y, int z, int) b)
- {
- return Math.Abs(a.x - b.x) + Math.Abs(a.y - b.y) + Math.Abs(a.z - b.z);
- }
- static void Main(string[] args)
- {
- if (args.Length < 1) return;
- if (File.Exists(args[0]) == false) return;
- var file = File.OpenText(args[0]);
- var reg = new Regex(@"pos=<([\d-,]+)>, r=(\d+)");
- var nanoList = new List<(int x, int y, int z, int r)>();
- (int x, int y, int z, int r) strongest = (0, 0, 0, 0);
- do
- {
- var line = file.ReadLine();
- if (line == null) break;
- var res = reg.Match(line);
- var xyz = res.Groups[1].Value.Split(",").Select(s => int.Parse(s)).ToArray();
- var r = int.Parse(res.Groups[2].Value);
- nanoList.Add((xyz[0], xyz[1], xyz[2], r));
- if (r > strongest.r) strongest = (xyz[0], xyz[1], xyz[2], r);
- } while (true);
- file.Close();
- int inRange = 0;
- foreach (var n in nanoList)
- {
- int m = Manhattan(strongest, n);
- if (m <= strongest.r) inRange += 1;
- }
- Console.WriteLine($"Answer is : {inRange}");
- }
- }
- }
|