AutoGravity interview question

Making algorithm of simple things...