Saturday, March 30, 2013

project euler problem 080

Square root digital expansion

This is an interesting problem. I checked my old code, I used my bigInteger class, and used Newton's method iteratively to get the accurate result. It takes 0.7 second to find the number

This time I used continued fraction method, and I can figure out as many digits of p/q as required. The code is fast although my bigInteger class is slow. It only takes 1.6ms to find the answer. 

I also verified the result for the first 1000 digits of sqrt(2) to sqrt(99) as it is given in the discussion thread. It takes 0.77 second.

Update: 09/26/2017

Python is a great helper. With Decimal,  this problem is no-brainer.

No comments:

Post a Comment