Consecutive Points

Closest subsequent point in sequence
def ClosestPointsSequence (stPt, pnts:var[]..[])
{
return = [Imperative]
{
cnt1 = List.Count (pnts);
pnt1 = pnts;
pnt2 = [stPt];
while (List.Count(pnt2)<cnt1)
{
pnt3 = List.SetDifference(pnt1,pnt2);
pnt4 = List.LastItem(pnt2);
dis1 = pnt4.DistanceTo(pnt3);
pnt5 = List.SortByKey(pnt3,dis1)["sorted list"];
pnt1 = List.RestOfItems(pnt5);
pnt2 = List.AddItemToEnd(List.FirstItem(pnt5),pnt2);
}
return pnt2;
}
};

This can be extended to obtain the shortest path connecting a list of points by obtaining sequences with all possible start points and then calculating the length of the connecting poly line