Skip to content

2019-8: Going the Distance

Created by Causeway SVG engine - SharpPlot v3.61.0 Border ===== Region ===== X-Axis Ticks ===== X-Axis Grid X-Axis tickmarks Y-Axis Ticks ===== Y grid Y-Axis tickmarks Axes ===== Arrowhead(s) for the axes Y-axis labels ¯2 ¯1 1 2 3 for X-axis labels ¯2 ¯1 1 2 Heading, subheading and footnotes ===== Start of Line Chart =========== Points follow ... Line Data value labels ... A←(¯1.5 ¯1.5) B←(1.5 2.5) C←(1.5 ¯1.5) Reset to original origin

Given a vector of (X Y) points, or a single X Y point, determine the total distance covered when travelling in a straight line from the first point to the next one, and so on until the last point, then returning directly back to the start. For example, given the points (A B C) ← (¯1.5 ¯1.5)(1.5 2.5)(1.5 ¯1.5), the distance A to B is 5, B to C is 4 and C back to A is 3, for a total of 12.

💡 Hint: The rotate X⌽Y and power X*Y functions might be useful.

Examples:

      (your_function) (1 ¯1)(1 3)   ⍝ from A to B and back to A
8
      (your_function) (1 1)(1 2)(2 2)(2 1)   ⍝ from A to B to C to D to A
4
      (your_function) 5 5   ⍝ staying where we are
0
      (your_function) (1 1)(3 3)   ⍝ there and back again
5.656854249
your_function ←

Solutions

Video Thumbnail YouTube

Chat transcript Code on GitHub