Stellar Science Interview Question

How would you code this specific algorithm?