Stellar Science interview question

How would you code this specific algorithm?