Retirement tax questions

Seems like the earnings are applied in the prior year, as I originally thought.  Not sure how this is supposed to practically work: I don't even know what the earnings will be until my broker calculates it, so how can I iterate the calculation?

 

So here's my solution: My actual earnings on $120 is going to be somewhere around $5.  That's not going to move the needle much on eligibility, (which moves in ten-dollar increments anyway).  So I'll just take out $150, and that should cover whatever recursive mess results.

 

But seriously, how is this supposed to be done?