[Question]
  [
Here is another simple one:
# The Challenge
Given two points in an n-dimensional space, output the distance between them, also called the Euclidean distance.
* The coordinates will be rational numbers; the only limits are the restrictions of your language.
* Lowest dimension is 1, highest is whatever your language can handle
* You may assume that the two points are of the same dimension and that there will be no empty input.
* The distance has to be correct to at least 3 decimal places. If your language does not support floating point numbers, output the nearest whole number.
# Rules
* As usual, function or full program allowed.
* Input may be taken from STDIN, command line- or function arguments.
* Input format is up to you, specify which one you used in your answer.
* Output may be provided by printing to stdout or return value.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so lowest byte-count wins! In case of a tie, the earlier answer wins.
# Test cases
Each point is represented by a list of length n.
```
[1], [3] -> 2
[1,1], [1,1] -> 0
[1,2], [3,4] -> 2.82842712475
[1,2,3,4], [5,6,7,8] -> 8
[1.5,2,-5], [-3.45,-13,145] -> 150.829382085
[13.37,2,6,-7], [1.2,3.4,-5.6,7.89] -> 22.5020221314
```
**Happy Coding!**
  
[Answer]
# [MATL](https://esolangs.org/wiki/MATL), 2 bytes
```
ZP
```
[**Try it online**!](http://matl.tryitonline.net/#code=WlA&input=WzEsIDIsIDMsIDRdCls1LCA2LCA3LCA4XQ)
The `ZP` function (corresponding to MATLAB's `pdist2`) computes all pairwise distances between two sets of points, using Euclidean distance by default. Each set of points is a matrix, and each point is a row. In this case it produces a single result, which is the distance between the two points.
[Answer]
# MATL, ~~~~4.0~~~~ 3 bytes
Thanks for -1 by @AndrasDeak!
```
-Zn
```
Reads two vectors (via implicit input that is requested by `-`) then substracts those and calculates the norm of their difference with `Zn`.
[Try it Online!](http://matl.tryitonline.net/#code=LVpu&input=WzEsMiwzLDRdCls1LDYsNyw4XQo)
[Answer]
# Pyth, 2 bytes
```
.a
```
> 
> `.a` - L2 norm of vector difference of A[0] and A[1].
> 
> 
> 
Literally a function that does this problem
[Try it here.](http://pyth.herokuapp.com/?code=.a&input=%5B%5B13.37%2C2%2C6%2C-7%5D%2C+%5B1.2%2C3.4%2C-5.6%2C7.89%5D%5D&debug=0)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 [bytes](https://github.com/DennisMitchell/jelly/blob/master/docs/code-page.md)
```
_¬≤S¬Ω
```
[Try it online!](http://jelly.tryitonline.net/#code=X8KyU8K9&input=&args=WzEzLjM3LDIsNiwtN10+WzEuMiwzLjQsLTUuNiw3Ljg5XQ)
### How it works
```
_¬≤S¬Ω    Main link. Left input: A (list). Right input: B (list).
_       Subtract B from A, element by element.
 ¬≤      Square all differences.
  S     Add all squares.
   ¬Ω    Take the square root of the sum.
```
[Answer]
## Mathematica, 11 bytes
```
Norm[#-#2]&
```
Input as two lists, output as a number. If the input is exact (integers, rationals, etc.) the output will be exact as well. If the input contains a floating-point number, the output will be a float as well.
[Answer]
# Octave, 15 bytes
```
@(x,y)norm(x-y)
```
Example:
```
octave:1> d=@(x,y)norm(x-y);
octave:2> d([13.37,2,6,-7], [1.2,3.4,-5.6,7.89])
ans =  22.502
```
[Answer]
## CJam, ~~11~~ 8 bytes
*Thanks to Dennis for saving 3 bytes.*
```
q~.-:mhz
```
[Run all test cases.](http://cjam.aditsu.net/#code=qN%2F%7B%22%20-%3E%20%22%2F0%3D'%2CSer%3AQ%3B%0A%0AQ~.-%3Amhz%0A%0A%5DoNo%7D%2F&input=%5B1%5D%2C%20%5B3%5D%20-%3E%202%0A%5B1%2C1%5D%2C%20%5B1%2C1%5D%20-%3E%200%0A%5B1%2C2%5D%2C%20%5B3%2C4%5D%20-%3E%202.82842712475%0A%5B1%2C2%2C3%2C4%5D%2C%20%5B5%2C6%2C7%2C8%5D%20-%3E%208%0A%5B1.5%2C2%2C-5%5D%2C%20%5B-3.45%2C-13%2C145%5D%20-%3E%20150.829382085%0A%5B13.37%2C2%2C6%2C-7%5D%2C%20%5B1.2%2C3.4%2C-5.6%2C7.89%5D%20-%3E%2022.5020221314)
### Explanation
```
q~   e# Read and evaluate input.
.-   e# Vectorised difference.
:mh  e# Reduce ‚àö(x¬≤+y¬≤) over the list.
z    e# Take abs() to handle 1D input.
```
[See this tip for why `:mh` works.](https://codegolf.stackexchange.com/a/61089/8478)
[Answer]
# Haskell, 46 bytes
```
d :: Floating c => [c] -> [c] -> c
d a=sqrt.sum.map((^2).uncurry(flip(-))).zip a
```
# Haskell, 35 bytes (By @nimi)
```
d :: Float c => [c] -> [c] -> c
d a=sqrt.sum.zipWith(((^2).).(-))a
```
# Haskell, 31 bytes
> 
> Like [this Scala answer](https://codegolf.stackexchange.com/a/70543/29474), takes input as a sequence of tuples
> 
> 
> 
<hack> 
```
d :: Float c => [(c,c)] -> c
d=sqrt.sum.map$(^2).uncurry(-)
```
</hack>
## Examples:
```
Prelude> d [1] [3]
2.0
Prelude> d [1,1] [1,1]
0.0
Prelude> d [1,2,3,4] [5,6,7,8]
8.0
Prelude> d [1.5,2,-5] [-3.45,-13,145]
150.82938208452623
Prelude> d [13.37,2,6,-7] [1.2,3.4,-5.6,7.89]
22.50202213135522
```
[Answer]
# APL, ~~14~~ 11 bytes
```
.5*‚ç®(+/-√ó-)
```
This is dyadic function train that takes the vectors on the left and right and returns the Euclidean norm of their difference.
Explanation:
```
       -√ó-)  ‚çù Squared differences
    (+/      ‚çù Sum them
.5*‚ç®         ‚çù Take the square root
```
[Try it here](http://tryapl.org/?a=f%u2190.5*%u2368%28+/-%D7-%29%20%u22C4%2013.37%202%206%20%AF7%20f%201.2%203.4%20%AF5.6%207.89&run)
Saved 3 bytes thanks to Dennis!
[Answer]
# Julia, 16 bytes
```
N(x,y)=norm(x-y)
```
This is a function that accepts two arrays and returns the Euclidean norm of their difference as a float.
You can verify all test cases at once online [here](http://goo.gl/dMBgy0).
[Answer]
# J, 9 bytes
```
+&.*:/-/>
```
This is a function that takes one set of coordinates from the other (`-/>`), and then performs a sum `+` under `&.` square `*:`.
The input should be in the format `x y z;a b c` where `x y z` is your first set of co-ordinates and `a b c` is the other.
[Answer]
# Java, ~~130~~ ~~117~~ ~~114~~ ~~107~~ 105 bytes
This is the obvious solution. I don't usually golf in Java, but I was curious to see if Java could beat the Brainfuck version. Doesn't seem like I did a good job then.. Maybe one could use the new Map/Reduce from Java 8 to save some bytes.
Thanks to @flawr (13 bytes), @KevinCruijssen (9 bytes) and @DarrelHoffman (3 bytes)!
Golfed:
```
double d(float[]a,float[]b){float x=0,s;for(int i=0;i<a.length;x+=s*s)s=a[i]-b[i++];return Math.sqrt(x);}
```
Ungolfed:
```
double d(float[] a, float[] b) {
  float x=0,s;
  for(int i=0; i<a.length; x+=s*s)
    s = a[i] - b[i++];
  return Math.sqrt(x);
}
```
[Answer]
# [golflua](http://mniip.com/misc/conv/golflua/), 43 chars
```
\d(x,y)s=0~@i,v i(x)s=s+(v-y[i])^2$~M.q(s)$
```
Works by calling it as
```
> w(d({1,1},{1,1}))
0
> w(d({1,2},{3,4}))
2.82842712475
> w (d({1,2,3,4},{5,6,7,8}))
8
```
  
A Lua equivalent would be
```
function dist(x, y)
    s = 0
    for index,value in ipairs(x)
       s = s + (value - y[index])^2
    end
    return math.sqrt(s)
end
```
[Answer]
## Seriously, 12 bytes
```
,iZ`i-¬™`MŒ£‚àöA
```
[Try it online!](http://seriously.tryitonline.net/#code=LGlaYGktwqpgTc6j4oia&input=WzEzLjM3LDIsNiwtN10sIFsxLjIsMy40LC01LjYsNy44OV0)
Explanation:
```
,iZ`i-¬™`MŒ£‚àöA
,iZ           get input, flatten, zip
   `   `M     map:
    i-¬™         flatten, subtract, square
         Œ£‚àöA  sum, sqrt, abs
```
[Answer]
# Perl 6, ~~30~~ ~~29~~ ~~26~~ 24 bytes
```
{sqrt [+] ([Z-] $_)¬ª¬≤}
```
(Thanks @b2gills for 2 more bytes lost)
**usage**
```
my &f = {sqrt [+] (@^a Z-@^b)¬ª¬≤};
say f([1], [3]); # 2
say f([1,1], [1,1]); # 0
say f([1,2], [3,4]); # 2.82842712474619
say f([1,2,3,4], [5,6,7,8]); # 8
say f([1.5,2,-5], [-3.45,-13,145]); # 150.829382084526
say f([13.37,2,6,-7], [1.2,3.4,-5.6,7.89]); # 22.5020221313552
```
[Answer]
# Python 2, 47 bytes
A straight forward solution. The function expects 2 points as sequences of numbers, and returns the distance between them.
```
lambda a,b:sum((d-e)**2for d,e in zip(a,b))**.5
```
Example:
```
>>> f([13.37, 2, 6, -7], [1.2, 3.4, -5.6, 7.89])
22.50202213135522
```
[Answer]
# Ruby, 52
```
->p,q{t=0;p.size.times{|i|t+=(p[i]-q[i])**2}
t**0.5}
```
**In test program**
```
f=->p,q{t=0;p.size.times{|i|t+=(p[i]-q[i])**2}
t**0.5}
p f[[1], [3]] # 2
p f[[1,1], [1,1]] # 0
p f[[1,2], [3,4]] # 2.82842712475
p f[[1,2,3,4], [5,6,7,8]] # 8
p f[[1.5,2,-5], [-3.45,-13,145]] # 150.829382085
p f[[13.37,2,6,-7], [1.2,3.4,-5.6,7.89]] # 22.5020221314
```
[Answer]
# AppleScript, ~~241~~ 239 bytes
This is golfed code, but I've put comments in in the form `--`.
```
on a()    -- Calling for getting input
set v to{1}          -- Arbitrary placeholder
repeat until v's item-1=""       -- Repeat until no input is gathered
set v to v&(display dialog""default answer"")'s text returned   -- Add input to list
end      -- End the repeat
end      -- End the method
set x to a()   -- Set the array inputs
set y to a()
set z to 0     -- Sum placeholder
set r to 2     -- 2 is the first significant array index
repeat(count of items in x)-2     -- Loop through all but first and last of the array
set z to z+(x's item r-y's item r)^2    -- Add the square of the difference
end   -- End the repeat
z^.5  -- Return the square root of the sum
```
This uses the same algorithm as most of the other programs here.
[![run sample](https://i.stack.imgur.com/3mZqI.gif)](https://i.stack.imgur.com/3mZqI.gif)
[Answer]
## JavaScript ~~ES7, 45~~ ES6, 37 bytes
```
a=>Math.hypot(...a.map(([b,c])=>b-c))
```
Expects an array of pairs of coordinates, one from each vector, e.g. `[[1, 5], [2, 6], [3, 7], [4, 8]]`. If that is unacceptable, then for 42 bytes:
```
(a,b)=>Math.hypot(...a.map((e,i)=>e-b[i]))
```
Expects two arrays of equal length corresponding to the two N-dimensional vectors, e.g. `[1, 2, 3, 4], [5, 6, 7, 8]`. Edit: Saved 3 bytes thanks to @l4m2. (Also, did nobody notice my typo?)
[Answer]
## Haskell, 32 bytes
```
((sqrt.sum.map(^2)).).zipWith(-)
```
---
```
Œª> let d = ((sqrt.sum.map(^2)).).zipWith(-)
Œª> d [1] [3]
2.0
Œª> d [1,1] [1,1]
0.0
Œª> d [1,2] [3,4]
2.8284271247461903
Œª> d [1..4] [5..8]
8.0
Œª> d [1.5,2,-5] [-3.45,-13,145]
150.82938208452623
Œª> d [13.37,2,6,-7] [1.2,3.4,-5.6,7.89]
22.50202213135522
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~79~~ 77 bytes
-2 bytes thanks to ceilingcat.
TIO requires compiler flag `-lm`. GCC of MinGW (that I use) does not.
```
f(p,q,d,s)float*p,*q,s;{for(s=0;d--;)s+=*p++*=*p-=*q++;printf("%f",sqrt(s));}
```
[Try it online!](https://tio.run/##lVHNboMwDD7DU1hIFQESVJLQdmNsD1L1UMFASP2Bhu1S8epjMSWwdpftYiJ/f7bJWJllfV@QmjY0p8orDud969fUb6hKrsX5QlS6THLGEk8FqV8Hga8rS/0mCJL6Up3agjiLwqGqubREeV7S9Z/nKoeSDFbg1xEF8@QUtALy6ujZV9vCd5XYlm3pICDGbut4mgcpLBP9eUG6fgSBZ1vWFBnyYpGBQ6GOttVu4KfIBAYRvIG7c@EZXOp6v/0p/DOB/yHByNgrOGMmwdVxZ9z3RvpoFXEQ72wbtz/uqxMZbnE7Ufuu2khvtNOzXaNw2dGxxW8toVvJTzL/QaYwK7hRTP07mbiTcSwCi5wMhDGIsb/CssayebSSs1U8WrF4spHGholQapxFQ04k40efePIRoViPTkMuW0928bwWx5HlELbC2TZP3XBj2yrJeMbpeDoQf8AN4AbgCPAZEAYQCMgZkAaQCIgZiA0QG0XXf2XFYV@qnh2O3w "C (gcc) ‚Äì Try It Online")
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 2 bytes
```
‚àÜd
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLiiIZkIiwiIiwiNywgNCwgM1xuMTcsIDYsIDIiXQ==)
Laughs in built-in. Generalised euclidian distance do be like that sometimes.
[Answer]
# ùîºùïäùïÑùïöùïü, 6 chars / 13 bytes
```
–ú≈∞–ú≈∑‚Ä¶√Ø
```
`[Try it here (Firefox only).](http://molarmanful.github.io/ESMin/interpreter2.html?eval=true&input=%5B%5B1%2C1%5D%2C%20%5B1%2C1%5D%5D&code=%D0%9C%C5%B0%D0%9C%C5%B7%E2%80%A6%C3%AF)`
Calculates norm of difference of input arrays.
[Answer]
# Scala, 67 62 bytes
```
def e(a:(Int,Int)*)=math.sqrt(a map(x=>x._2-x._1)map(x=>x*x)sum)
```
Requires input as a sequence/vector of var-arg tuples  
Example:
```
scala> e((1, 5), (2, 6), (3, 7), (4, 8))
res1: Double = 8.0
```
[Answer]
# C#, 72 bytes
```
(float[]i,float[]n)=>System.Math.Sqrt(i.Zip(n,(x,y)=>(x-y)*(x-y)).Sum())
```
A simple solution using Linq.
[Answer]
## Sage, 35 bytes
```
lambda a,b,v=vector:norm(v(a)-v(b))
```
This function takes 2 lists as input and returns a symbolic expression. The distance is calculated by performing vector subtraction on the lists and computing the Euclidean norm of the resultant vector.
[Try it online](http://sagecell.sagemath.org/?z=eJwlkdFuhCAQRd9N_IdJ-qA2IxGE1d1k-yObPuDKbklVLKDt_n0BeZlk7pk7XHhcJzkPowSJA-7XXd29sZfF2LncS1nVezlUVZ7lmVfOO7hCURQ3-olwaz-h_gCWZzeKqRFLbDWpxRKD_KBIz3rOOsp4Jw4ZoxYQgSfssE9YHyUigliLqNUt4QJr2iLlIhFUNMHq3Pas6ZNRS9ou8Cesu3QHEowJD_Mk2JL-fKxnRDSsYYy2lIcAxK2T9pNelCtTuIexEAOCXlJ1lzyDcKR9OgSz-RB8lmupdjlhBA6HsojuRXygSK9WLx4e5Xscq465N_BfCqzym13UCGF-U6AdSHCveTCTvoP6W61yTpsFwRkYtQ2fML3gbuZVBssnqJ9NhnUvGI1yS-Hh19jvfyPhd7o=&lang=sage)
[Answer]
## Clojure, 48 bytes
```
#(Math/sqrt(apply +(for[d(map - % %2)](* d d))))
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 4 bytes
```
-nOt
```
[Try it online!](https://tio.run/nexus/05ab1e#@6@b51/y/3@0obGesbmOkY6Zjq55LFe0oZ6RjrGeiY6uqZ6ZjrmehWUsAA "05AB1E ‚Äì TIO Nexus")
Negative not y'all!
```
-    # a-b
 n   # (a-b)**2
  O  # sum((a-b)**2) for all a,b
   t # sqrt(sum((a-b)**2) for all a,b)
```
[Answer]
# [Elixir](https://elixir-lang.org/), 74 bytes
```
:math.sqrt Enum.reduce Enum.zip(p,q),0,fn({a,b},c)->:math.pow(a-b,2)+c end
```
[**You can try it online**](http://elixirplayground.com?gist=663568808c8f5eaa09070363516c9e30)
[Answer]
# TI-Basic (TI-84 Plus CE), 15 bytes
```
Prompt A,B
‚àö(sum((LA-LB)2
```
TI-Basic is a [tokenized language](http://tibasicdev.wikidot.com/one-byte-tokens).
Prompts for input as two lists, and returns the Euclidian distance betwrrn them in `Ans`
Explanation:
```
Prompt A,B    # 5 bytes, Prompts for two inputs; if the user inputs lists:
           # they are stored in LA and LB
‚àö(sum((LA-LB)2 # 10 bytes, Euclidian distance between points
           #(square root of (sum of (squares of (differences of coordinates))))
```
]