| Author |
why are the answers different?
|
Mahendra Kariya
Greenhorn
Joined: Aug 25, 2008
Posts: 26
|
|
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:
">
|
 |
Himanshu Kansal
Ranch Hand
Joined: Jul 05, 2009
Posts: 257
|
|
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
|
Experience and talent are independent of age
|
 |
Mahendra Kariya
Greenhorn
Joined: Aug 25, 2008
Posts: 26
|
|
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
Joined: Jul 05, 2009
Posts: 257
|
|
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
Joined: Aug 25, 2008
Posts: 26
|
|
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
Joined: Jul 05, 2009
Posts: 257
|
|
|
Could you please post the problem statement?
|
 |
Mahendra Kariya
Greenhorn
Joined: Aug 25, 2008
Posts: 26
|
|
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)
-------------------------
|
 |
Sean Clark
Rancher
Joined: Jul 15, 2009
Posts: 377
|
|
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
|
I love this place!
|
 |
Mahendra Kariya
Greenhorn
Joined: Aug 25, 2008
Posts: 26
|
|
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.
|
 |
 |
|
|
subject: why are the answers different?
|
|
|