Hacker News new | past | comments | ask | show | jobs | submit login

You don't even need to know that. Once the fractions update your estimate by less than 0.5x10^-5 (half of 0.00001), you can be sure that your estimate is accurate to 5 decimal places. I think it's reasonable to expect a programmer to be able to figure that out. If the programmer wants to use a REPL to find the pattern in the numbers, I think that's fair as it demonstrates using one's tools to solve a problem.



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!


How can people code without knowing math ? Atleast to the extent of knowing the value of PI? ( I am not asking for a 10 decimal places value ..How about just 2 decimal places )


I'm with you there. I didn't mean to imply that programmers don't need to know math. To the contrary, I find it very useful and keep a graphing calculator on my desk. I was just pointing out that knowing the value of PI isn't strictly necessary for this example, because by writing a quick script, one can determine the behavior of the sequence and figure out an appropriate stopping condition. The rest of it is just translating a formula into code.


How many other constants have you memorized? e? phi? sqrt(2)? and you know all those to 5 decimals? When I conduct interviews I try really really hard to set aside the things that I know and give candidates an opportunity to tell (or show) me what they know. Someone not having a constant memorized is not a show stopper, as I am after the logical thought processs.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: