Page 1 of 1

Problem 255

Posted: Tue Sep 15, 2009 8:25 pm
by louis0891
Hi,

I was just attempting to do this. I had an implementation that seemed to do what was required(see below). However the problem states that a 5-digit integer (10,000 ≤ n ≤ 99,999) has an average of 3.2102888889 (rounded to 10 Decimal Places). However I have run my code and get (rounded to 10 Decimal Places) 3.1470888888 as the average. Have I missed something, or is mine somehow more efficient? Please help as it really makes no sense!
[snip code]
Thanks In Advance

Re: Problem 255

Posted: Tue Sep 15, 2009 8:39 pm
by daniel.is.fischer
Hi, please don't post code that is closely related to the problem.
That said,

Code: Select all

Dim D As Long = Len(A.ToString)
If A Mod 2 = 0 Then
   X(0) = 7 * 10 ^ ((D - 2) / 2)
Else
   X(0) = 2 * 10 ^ ((D - 1) / 2)
End If
is wrong, it should be

Code: Select all

If D Mod 2 = 0 Then
Maybe that's all.

[Edit] Yes, it seems so.

Re: Problem 255

Posted: Wed Sep 16, 2009 1:02 pm
by louis0891
Thanks. I will try it as soon as I get on the right computer :D .

Ps Thanks for telling me about not posting code. I won't do it again.

Re: Problem 255

Posted: Sat Aug 17, 2013 2:25 pm
by rlindley
For an added twist, what if x0 is not constant for the whole interval??

Suppose the first part of the problem definition is changed from:

Let d be the number of digits of the number n.
If d is odd, set x0 = 2×10^(d-1)⁄2.
If d is even, set x0 = 7×10^(d-2)⁄2.

to:

Let d be the number of binary digits of the number n.
Set x0 = to n shifted floor(d/2) bits to the right.

Then I get 2.8067888888888888 for the 5-digit case and 4.0878091796900780 for the 14-digit case. Anyone care to check those values?

And for 10^13 <= n < 10^15 I get 4.4119614133043497 in about 30 seconds.

Re: Problem 255

Posted: Thu Dec 08, 2022 2:46 pm
by tchiari
I am able to get the correct answer for the test data with 5 digit numbers. I have a result for 7, 9 and 11 digit numbers and wonder if I could check those via PM with someone.