programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

# why are the answers different?

Greenhorn
Posts: 26
• Number of slices to send:
Optional 'thank-you' note:
I was solving Problem 40 of Project Euler. I tried it in two different ways. But I was getting an incorrect answer for one of the ways. Can someone tell me what is the mistake?

My code follows:

">

Ranch Hand
Posts: 257
• Number of slices to send:
Optional 'thank-you' note:
Is the condition at line 50 correct?

digits can have a max value of 5 and milestone has a value of 10 and increases only.

Regards

Mahendra Kariya
Greenhorn
Posts: 26
• Number of slices to send:
Optional 'thank-you' note:

Himanshu Kansal wrote:Is the condition at line 50 correct?

digits can have a max value of 5 and milestone has a value of 10 and increases only.

The output shows that only the last one is incorrect. I mean the millionth digit. Rest all are correct. I cross checked with the second method.

Himanshu Kansal
Ranch Hand
Posts: 257
• Number of slices to send:
Optional 'thank-you' note:
i think it should be:

well i don't know what the actual problem is, but I am just trying to shoot the trouble through your code.

Mahendra Kariya
Greenhorn
Posts: 26
• Number of slices to send:
Optional 'thank-you' note:

Himanshu Kansal wrote:i think it should be:

This will be a frequent case. Suppose we want to find the 100th digit. We have the milestone set to 100. If we check digits<milestone, then this condition will be true for every case. But if it is what I have done, this condition will be true once the milestone is reached. And once we reach a particular milestone, we increase it.

I guess your condition will result in an infinite loop!

Himanshu Kansal
Ranch Hand
Posts: 257
• Number of slices to send:
Optional 'thank-you' note:
Could you please post the problem statement?

Mahendra Kariya
Greenhorn
Posts: 26
• Number of slices to send:
Optional 'thank-you' note:

Himanshu Kansal wrote:Could you please post the problem statement?

Problem statement is available at http://projecteuler.net/index.php?section=problems&id=40

Still I have put it here for convenience.

------------------------
An irrational decimal fraction is created by concatenating the positive integers:

0.123456789101112131415161718192021...

It can be seen that the 12^(th) digit of the fractional part is 1.

If d(n) represents the n^(th) digit of the fractional part, find the value of the following expression.

d(1) × d(10) × d(100) × d(1000) × d(10000) × d(100000) × d(1000000)
-------------------------

Rancher
Posts: 377
• Number of slices to send:
Optional 'thank-you' note:
Hey,

I'm not sure if this makes a difference, but line 27 - 28

if n < 1000000 then number of digits could be 6 as well??

Dunno if that helps though.

Sean

Mahendra Kariya
Greenhorn
Posts: 26
• Number of slices to send:
Optional 'thank-you' note:

Sean Clark wrote:
I'm not sure if this makes a difference, but line 27 - 28

if n < 1000000 then number of digits could be 6 as well??

Thanks Sean, this was the error. At line 27-28, it should be something like this.

Thank you Sean and Himanshu.