static void Main(string[] args) { StreamReader file = new StreamReader("input.txt"); string stream = file.ReadLine(); file.Close(); HexGridPosition start = new HexGridPosition(); HexGridPosition goal = new HexGridPosition(); string[] directions = stream.Split(','); int maxDistance = int.MinValue; int distance; foreach (string dir in directions) { goal.Move(dir); distance = goal.Distance(start); if (distance > maxDistance) { maxDistance = distance; } } Console.WriteLine(string.Format("End Distance: {0}", goal.Distance(start))); Console.WriteLine(string.Format("Max Distance: {0}", maxDistance)); Console.ReadLine(); }
public int Distance(HexGridPosition pos) { int diffx, diffy, diffz; int distance; diffx = Math.Abs(pos.X - this.X); diffy = Math.Abs(pos.Y - this.Y); diffz = Math.Abs(pos.Z - this.Z); distance = Math.Max(Math.Max(diffx, diffy), diffz); return(distance); }