Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That's not a correct solution. Try using that solution to find pi to 2 decimal places (delta of 0.005) and you'll wind up with 3.139..

A solution to this is looking at the distance from the current sum to the "boundary":

    abs(round(sum, 5) - sum) > next_term
which works because this is an alternating series.


You're right. Thanks for the correction.

I guess that demonstrates why it's important to have a REPL or a compiler available for the interviewee. (My computer wasn't available at the time that I wrote the comment.) I just wrote up my solution and confirmed that its terminating condition isn't correct.


It doesn't matter that it's not correct, the sad truth is that if you get that problem and write a loop and some math operators and update a variable for each run - you're in the top 10% of applicants!

There's a mindboggling amount of people applying for programming jobs who can't even do that!




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: