Why don't you ask the kids to come up with ways to measure the distance traveled?

Serving them the answer sounds more "gifted" than "talented".

Then ask them to write the algorithm. Not the actual code, but what happens when and what is triggered in which condition.

When you have that writing the actual code, in this situation, is a breeze.

Make them compete against each other to see who can come up with the simplest method and way for each part of the problem.