Domanda di colloquio di Stellar Science

How would you code this specific algorithm?