Objective

Create a program to calculate the Euclidean distance between two points.

Difficulty

Easy

Description

Given two points on a Cartesian plane, the distance between them is called the Euclidean distance and is calculated by applying the very elementary Pythagoras's theorem.

So for instance, if the point ::\text{A}:: has the co-ordinates ::(x_1, y_1):: and the point ::\text{B}:: has the co-ordinates ::(x_2, y_2)::, then the distance between them is calculated by the expression below:

::\sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}::

In this exercise, you have to create a program, utilising the idea of closures, that provides a function getDistanceCalculator() which could be used to obtain a distance calculator function.

This distance calculator function takes the co-ordinates of ::\text{B}:: as two separate arguments, and meanwhile remembers the co-ordinates of ::\text{A}:: from its enclosing environment. It returns back the distance between the given points ::\text{A}:: and ::\text{B}:: as a stringified number rounded to the 1 decimal place.

In the program, we shall be able to create as many distance calculator functions as we want to, each configured with a given point ::\text{A}::.

In the end, use this program to log the distances of the points ::(30, 5)::, ::(8, 8):: and ::(-5, -10):: from the origin, and of the points ::(10, 2)::, ::(0, 1):: and ::(-90, -1):: from the point ::(5, 5)::.

Hints