123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace EuclideanDistance
- {
-
-
-
- public class MainClass
- {
-
-
-
-
-
-
- public static void Main(string[] args)
- {
-
- var points = InitialDataPoints();
-
- var input = FocalPoint(points);
-
- var distances = points.Select(x => input.EuclideanDistance(x)).ToList();
-
- Console.WriteLine();
- Console.WriteLine(
- "Minimum distance: {0}",
- points.ElementAt(distances.IndexOf(distances.Min())).ToPoint());
- Console.WriteLine(
- "Maximum distance: {0}",
- points.ElementAt(distances.IndexOf(distances.Max())).ToPoint());
- }
-
-
-
-
-
-
- private static IEnumerable<IEnumerable<double>> InitialDataPoints()
- {
- var points = new List<IEnumerable<double>>();
- Console.WriteLine("Please enter the initial points");
- while (true)
- {
- Console.Write("Point [blank to stop]: ");
- var p = Console.ReadLine().ToPoint();
- if (p == null)
- {
- if (points.Count() > 0)
- {
- break;
- }
- else
- {
- Console.WriteLine("No points have been entered.");
- }
- }
- else if (points.Count() > 0 && p.Count() != points.First().Count())
- {
- Console.WriteLine("Dimensions do not match.");
- }
- else
- {
- points.Add(p);
- }
- }
- return points;
- }
-
-
-
-
-
-
-
-
-
- private static IEnumerable<double> FocalPoint(IEnumerable<IEnumerable<double>> points)
- {
- Console.WriteLine();
- Console.WriteLine("Please enter a focal point");
- while (true)
- {
- Console.Write("Point: ");
- var p = Console.ReadLine().ToPoint();
- if (p == null)
- {
- Console.WriteLine("Invalid input. Please try again.");
- }
- else if (p.Count() != points.First().Count())
- {
- Console.WriteLine("Dimensions do not match.");
- }
- else
- {
- return p;
- }
- }
- }
- }
- }
|