-6

Let's say I have few points : -5,-4,-3,-2,-1,0,1,2,3,4,5

I'm at point 0, I need to create a line that goes all through the points of 1,2,3,4,5,-1,-2... etc.

The line would start at 0 and end at whatever point that ends as the shortest.

The answer for this example would be that it'd go like this 0->1->2->3->4->5->-1->-2->-3->-4->-5 or that it'd go first to -1 and go all through the minus to the plus, same result (5*4=20 length).

If for example we'd go 0->1->-1->2->-2... it'd end as the longest line that goes straight from point to point (1+2+3+4+5+6+7+8+9+10=10*11/2=55 length)

The question is how to write this in code?

The points might also consist of 2 or 3 dimensional points, where the start would be (0,0,0,0) or whatever, eventually the line can go through all of these points, but which way will achieve the shortest line?

How to make it as a code, as we see it in the eye?

  • Possible duplicate of [get closest point to a line](https://stackoverflow.com/questions/3120357/get-closest-point-to-a-line) – maccettura Jul 07 '17 at 15:51
  • @maccettura nope that's not the same question, but thanks for the try. – Matan Yashar Jul 07 '17 at 15:56
  • "How to make it as a code, as we see it in the eye?" Simple: C# includes a huge range of Math library functions,... you would use some of those. – Rob Jul 07 '17 at 15:59
  • @maccettura - nah, that's the sort of thing I thought at first until I reread the question. The Title for the question is really badly stated. He's not looking for a 'closest' line; he's looking for a 'shortest' path. – Kevin Jul 07 '17 at 15:59
  • @Kevin I agree with you again kevin, It's a problem that got to my head and I find it hard to word it. The shortest path is what I meant. – Matan Yashar Jul 07 '17 at 16:02

1 Answers1

0

I think this is basically the Travelling Salesman problem. You've got N destinations, and each pair of destinations has a concrete length between them, and you're trying to find out the shortest travel time to visit all destinations.

You've got two different directions to pursue this, that I can see. First, is to read up on the Travelling Salesman problem and the various algorithms that have been proposed for it (it's a very famous algorithm problem) and then try to implement one in C# - though just to warn you, you should be very proficient in math, because it's not an easy problem. Or, alternatively, you can look for someone else's existing implementation for it and just use it without understanding the theoretical underpinnings.

Kevin
  • 2,133
  • 1
  • 9
  • 21
  • Yea that's exactly the problem! at least now I know the name of it. Alright I will look for it, thank you very much for the suggestion. – Matan Yashar Jul 07 '17 at 15:59
  • Thank you kevin, I think I got the answer to the problem, appreciate it so accepted your answer. I might add the code for it in the future, after I'll make it. – Matan Yashar Jul 07 '17 at 16:32