Task 174 Calculation of pi

Back to General discussions forum

Suman Dutta     2020-05-14 08:43:29

expexted ans- 314159265358979323843151646426332908840484683897389983893201554568642560 my ans- 314159265358979478289801511118377822379483923662804815679777338910834688 can anyone help me with sol as I am losing precision after 20 digits

The Black Knight     2020-05-15 14:15:03

Are you getting all the right numbers for the first few steps of the example on the page?

I had an issue with my sqrt function so without seeing your code, that might be somewhere to start.

Suman Dutta     2020-05-15 17:45:08

can you check mycode?tell me where to send?

The Black Knight     2020-05-16 09:36:36

I think its OK to just post it here. If you indent the code with four spaces, the forum will turn it into a code block and make it easier to read.

Suman Dutta     2020-05-16 09:40:21

I have already solved.thank you for your concern.

lipasofra     2022-02-01 16:07:08

and what was the issue? how you solved it? I have exactly the same mistake.

zelevin     2022-02-01 16:30:19

Hint: if you are using Python, you don't need sqrt. There's math.isqrt that's perfect for this purpose.

lipasofra     2022-02-01 16:41:27

Hi, im using vala (that is very similar to C#). and following the info in the problem's explanation I code the loop for calculating the sqrt using newton's method, but I still having the same answer. Also I use floor in all divisions by 2, as the problem suggest. :(

Rodion (admin)     2022-02-01 16:56:42
User avatar

but I still having the same answer

the what answer?

sorry, Friend, your code is bit too excessive to understand it easily... either try describing your problem more clearly, or perhaps switch temporarily to other problems and return to this one later

Also, I'm not sure, but if you use finite-precision numbers, probably you won't go far with them

zelevin     2022-02-01 17:49:01

Here's the crucial line in the problem:

we should use as a result the greatest integer M such that when squared it does not exceed Z (i.e. M*M <= Z).

However you implement that (say, as a standalone function), the rest of your code shouldn't have a single float (i.e., use only integer variables and computations).

Hope this helps.

Please login and solve 5 problems to be able to post at forum