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

I'm interested if you could solve it if you gave it some thought. The interviewer is presumably not expecting you to write it instantly and perfectly, but to reason your way through it over a few minutes.

(I will try it now.)

it can be answered in about 10 lines of C# is an unhelpful way of expressing how difficult a question is.



It took me 6 minutes to code something that I think solves this, mainly spent on thinking about what the end condition of the loop should be.


I remember very well the first time I tried a programming exercise like this. I probably spent 2 minutes writing the loop, and then I must have spent another 20 minutes wondering what I’d done wrong, until I realised that the sequence I’d been given really did converge that slowly. :-)

In the spirit of helping anyone who’s at that stage now, if you’re running on a slow machine, I suggest you try this sequence instead:

π² = 12( 1 - 1/2² + 1/3² - 1/4² + ... )

It converges much faster.




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

Search: