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

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: