For this week’s coding challenge, we’re taking a look at the problem of finding minimum distances in sets of points. Data for the problems below as well as some helper code can be found here: https://github.com/mbaptist34/st_coding_challenge_2
Challenge 1: Write a program that reads a series of numbers and calculates the smallest distance or difference between any of them. i.e. With the numbers 1, 1000, 500, and 2, the smallest distance would come from 1 and 2, and equal 2-1 = 1. Think about how to do this as efficiently as possible, and discuss why you think your approach is the fastest possible in your submission.
You can use the code in the provided file, load_data.py, to read the provided set of numbers or write your own code to do so.
The provided code can be used as follows:
from load_data import *
arr = load_list_1()
Things get more complicated when you are working with a list of 2D points.
Challenge 2: Write a program that reads in a series of 2D coordinates and calculates the smallest distance between any two points. For this problem, any solution that finds the correct solution is acceptable. The most efficient solution may be the subject of another Weekly Coding Challenge in the future (or a blog post)!
For this problem, the helper code can be used as follows:
from load_data import *
arr = load_list_2()