# why are the answers different?

posted 6 years ago

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:

">

My code follows:

">

Himanshu Kansal

Ranch Hand

Posts: 257

posted 6 years ago

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 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

posted 6 years ago

This will be a frequent case. Suppose we want to find the 100th digit. We have the milestone set to 100. If we check

I guess your condition will result in an infinite loop!

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

posted 6 years ago

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)

-------------------------

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)

-------------------------