From: Jared F on
I came across the "brain teaser" of finding the best approximation of pi by dividing one 9-digit number by another 9-digit number. Both numbers contain 1 through 9 once.

I found a very close approximation by hand (728691345 / 231948765 = 3.141604763) but I want to know if there are any better ones.

I've tried a couple different methods of writing a program to find a better approximation, but all I can come up with is a massive number of loops that would take way too long for my computer to process.

I'll paste my current program below. If you can think of a better way to write this, let me know. I don't have an extensive background in matlab, so I'm at a loss for how to optimize this. Thanks!

Program Below
____________________________________

for a = 3:9;
for b = 1:9;
for c = 1:9;
for d = 1:9;
for e = 1:9;
for f = 1:9;
for g = 1:9;
for h = 1:9;
for i = 1:9;
for j = 1:9;
for k = 1:9;
for l = 1:9;
for m = 1:9;
for n = 1:9;
for o = 1:9;
for p = 1:9;
for q = 1:9;
for r = 1:9;

x = 100000000.*a+10000000.*b+1000000.*c+100000.*d+10000.*e+1000.*f+100.*g+10.*h+i;
y = 100000000.*j+10000000.*k+1000000.*l+100000.*m+10000.*n+1000.*o+100.*p+10.*q+r;

z = x/y;


if (z - pi < .001)

format short;

printf('x = %i\n', x);
printf('y = %i\n', y);
format long;
printf('z = %i\n', z);
disp('----------');

endif

endfor
endfor
endfor
endfor
endfor
endfor
endfor
endfor
endfor
endfor
endfor
endfor
endfor
endfor
endfor
endfor
endfor
endfor