From: Mark Shore on
"Jared F" <jfritz408(a)yahoo.com> wrote in message <hnf1bd$rhe$1(a)fred.mathworks.com>...
> Thanks for the hint. Since 987654321 is the largest pan-digital number, the max denominator is 314298765. And vice-versa, since 123456789 is the smallest combination, the minimum numerator is 387695421. (These are found by using: numerator = pi * denominator).
>
> This leaves about 80220 possible denominators like you said, but still leaves 252000 possible numerators. That's a lot of possibilities. Also, I don't know how else to come up with a string of pan-digital numbers other than using the loops I created. Is there a more efficient way?
>
> I'm just doing problem this for fun, but yes it would be a good homework assignment. Especially with pi day just around the corner.
>
> :)
>
>
>
> >
> > I won't do homework assignments, which this sounds
> > surprisingly like. And even if this is something you wish
> > to try yourself, you won't gain anything by me doing
> > it for you. However, you did make a start at it, so I''ll
> > give you a hint.
> >
> > You want to find a ratio of TWO pan-digital numbers
> > that yields pi to as high an approximation as possible.
> >
> > Rather than looping massively as you tried, why not
> > search over all denominators? How many 9 digit
> > pan-digital numbers are there? (Hint: factorial(9).)
> > Of them, how many might possibly form the
> > denominator? (By my count, the number is only
> > about 84360 of them.)
> >
> > So this is quite solvable.
> >
> > John

I'll take your word that it's not homework. If it is, it's more interesting than any of my math assignments were.

Two hints: help perms, and pi will be bracketed by a pair of numerators for each given denominator.
From: John D'Errico on
"Jared F" <jfritz408(a)yahoo.com> wrote in message <hnf1bd$rhe$1(a)fred.mathworks.com>...
> Thanks for the hint. Since 987654321 is the largest pan-digital number, the max denominator is 314298765. And vice-versa, since 123456789 is the smallest combination, the minimum numerator is 387695421. (These are found by using: numerator = pi * denominator).
>
> This leaves about 80220 possible denominators like you said, but still leaves 252000 possible numerators. That's a lot of possibilities. Also, I don't know how else to come up with a string of pan-digital numbers other than using the loops I created. Is there a more efficient way?
>
> I'm just doing problem this for fun, but yes it would be a good homework assignment. Especially with pi day just around the corner.
>

Start with perms. Toss anything that starts with 4
and above. That can be used to define all possible
denominators.

Hint: there are roughly 29 different pandigit ratios
that yield at least about 9 correct digits of pi.

This is already more than I should tell you, else
it takes all the fun out of the problem.

John
From: Mark Shore on
"John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <hng5dq$h4b$1(a)fred.mathworks.com>...
> "Sadik " <sadik.hava(a)gmail.com> wrote in message <hng3aa$fr9$1(a)fred.mathworks.com>...
> > Hi Jared,
> >
> > Here is my version of it. The operation is limited by the available memory, as well as the maximum number of elements allowed by matlab. Therefore, the following may not be the best solution, but it could hopefully show you another direction of doing it. [It seems that the search for the optimal combination is going to take about 10 hours!]
> >
>
> But then your solution will take a half day to solve.
> Since I don't believe that giving a solution to someone
> who is trying to learn actually helps them at all, all I
> will do is to suggest that there are far better ways to
> approach it.
>
> Be creative. There is at least one solution with error
> as low as:
>
> error =
> -8.49968984084626e-11
>
> This took 11 lines of code to generate, and 0.23
> seconds of cpu time.
>
> John

Hi John. I managed to do it in 4 lines, also 0.23 seconds on a dual core CPU. Hope the OP puts a working solution up, so we can compare.
From: Greg Heath on
On Mar 12, 11:38 pm, "Jared F" <jfritz...(a)yahoo.com> wrote:
> Thanks for the hint.  Since 987654321 is the largest pan-digital number, the max denominator is 314298765.  And vice-versa, since 123456789 is the smallest combination, the minimum numerator is 387695421.  (These are found by using: numerator = pi * denominator).
Since

>> 123456789*pi

ans =

3.8785e+008

I get the lower bound as

Nlb = 387912456

Greg
From: Mark Shore on
It's been a month, so Jared has either solved this or given up. My solution is longer than the four lines I originally claimed since I realized afterward that the order of the two numbers of the solution could not be assumed.

% create array of pandigital numbers; change to perms(0:9) to include zeros
pandigs=perms(1:9)*[1e9; 1e8; 1e7; 1e6; 1e5; 1e4; 1e3; 100; 10; 1];
merged=sort([pandigs; pandigs*pi]);
[err,ind]=min(diff(merged));
if mod(merged(ind),1)<10^-12 % first (smaller) number is an integer within tolerance
pair=[merged(ind) round(merged(ind+1)/pi)]
else
pair=[merged(ind+1) round(merged(ind)/pi)]
end