# A Few Useful Functions:

```
-- Squares x.
function square(x)
return x*x
end
-- Works out the difference between two numbers.
function diff(n1, n2)
if n2 > n1 then
return n2 - n1
elseif n1 > n2 then
return n1 - n2
else
return 0
end
end
-- Can be used in simulations to work out the distance (in pixels) between two points.
function dist(x1, y1, x2, y2)
return math.sqrt(square(diff(x1, x2))+square(diff(y1, y2)))
end
-- Can be used to find the triangular number of x.
function tri(x)
t = 0
for i = 1, x do
t = t + i
end
return t
end
-- Can be used to find the oblong number of x.
function ob(x)
o = 0
for i = 1, x do
o = o + i*2
end
return o
end
```

Above are some very useful math functions (by me), but most useful is the `dist(x1, y1, x2, y2)`

, which can calculate the distance (in pixels) between two points using Pythagorean theorem. Please let me know of any problems.