Measure the total distance travel of each car, and store it in local variable or in an array. The instance with the highest variable will be first, the instance with second highest will be second etc. It it will be hard to implement because you will need something like Bubble sort to find out what instance has the largest value.