title: Quick algorithm for distance between 2 points on a grid?
body: <p>Given a grid of width by length (say 5 x 4) and an array of X and Y coords for points on that grid, print the distance from each point on the grid to the coords as below:</p>
  
  <p>width = 5</p>
  
  <p>len = 4</p>
  
  <p>x coords = (2,4)</p>
  
  <p>y coords = (2,3)</p>
  
  <pre><code>2123
  1012
  2112
  2101
  3212
  </code></pre>
  
  <p>A move "across" is + 2, vertical or horizontal move is +1</p>
  
  <p>Assume xCoords.length = yCoords.length</p>
  
  <p>I will post my solution later, or rather an attempt at a solution. I got stuck trying to come up with a function to transpose distance from grid coordinates (i,j) to coordinates for the points... So basically</p>
  
  <pre><code>for i .. width
    for j .. length
      getDistance(i,j, xCoords,yCoords)
  </code></pre>
  
  <p>(0,0) (0,1) (0,2) (0,3)</p>
  
  <p>(1,0) (1,1) (1,2) (1,3)</p>
  
  <p>(2,0) (2,1) (2,2) (2,3)</p>
  
  <p>etc...</p>
  
  <p>To the actual distance values at those coordinates.</p>