We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 891b752 commit 12c08b0Copy full SHA for 12c08b0
1 file changed
Manhattan_distance/Lua/Yonaba/manhattan_distance.lua
@@ -0,0 +1,18 @@
1
+-- Manhattan distance distance implementation
2
+-- See: http://xlinux.nist.gov/dads//HTML/manhattanDistance.html
3
+-- See: http://en.wikipedia.org/wiki/Manhattan_distance
4
+
5
+-- Returns the Manhattan distance between two vectors
6
+-- p : a first vector
7
+-- q : a second vector
8
+-- returns : the distance between p and q
9
+local function manhattan_distance(p, q)
10
+ assert(#p == #q, 'vectors must have the same length')
11
+ local s = 0
12
+ for i in ipairs(p) do
13
+ s = s + math.abs(p[i] - q[i])
14
+ end
15
+ return s
16
+end
17
18
+return manhattan_distance
0 commit comments