Skip to content

Instantly share code, notes, and snippets.

@Mr-Byte
Created December 9, 2013 16:26
Show Gist options
  • Save Mr-Byte/7875136 to your computer and use it in GitHub Desktop.
Save Mr-Byte/7875136 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Math;
public class Point(double x, double y)
{
public double X { get; } = x;
public double Y { get; } = y;
public double DistanceTo(Point other) => Sqrt(Pow(X - other.X, 2) + Pow(Y - other.Y, 2));
}
class Program
{
static void Main()
{
var points = new List { new Point(0, 0), new Point(1, 1,), new Point(2, 2) };
var totalDistance = points.Zip(points.Skip(1), (lhs, rhs) => lhs.DistanceTo(rhs)).Sum();
Console.WriteLine(totalDistance);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment