There is no alegbraic formula, per se, but it would pretty easy to set up a formula in Excel or a programmable calculator that compares differences and gives the closest and second closest set of differences. If limited to just 5 data points per set, and if they are provided in sorted order as in your example you have only 4 differences to compare with each other. But you will have to decide how to handle ties - for example if given a data set of 1, 2, 3, 4, and 5 there is no "closest" or "second closest" difference, so what answer do you expect? Also you mention a "last number remaining," but consider that there might be two last numbers remaining: for example in the set 5, 6, 8, 20, 50 the closest pair is 5,6 and the second closest is 6,8 so there are two numbers remaining (20 and 50).