Question #e6063

1 Answer
Mar 16, 2016

#928146375/295438167 = 3.141592653463...#

Explanation:

There are likely analytic ways of finding two such numbers, but as the method of solution was not specified, this is an excellent candidate for computer assistance. For some details on one possible way, see below. Running such a program showed that the closest representation is

#928146375/295438167 = 3.141592653463...#

which is accurate to #9# decimal places (#10# if you round at that spot).


What follows is a description of one way of arriving at the above.

Because the parameters are easy to define and the difficulty comes from having to check a large number of candidate values, a computer is a useful tool for this sort of problem. To make the program, we will use the fact that #p/q~~pi# if and only if #p ~~piq#

Our strategy, then, will be to take possible values for #q#, multiply them by #pi#, and see if #p# fulfills the conditions needed. To cut down on possibilities for #q#, we can note that #q < 987654321/pi#, as otherwise our #p# would be greater than any possible value which fulfills the conditions, and so we limit our search to

#q in [123456789, 987654321/pi]#

For the actual code, we will use two parts. The first will be a function called allDigits which takes in an integer as input and returns True if it contains #1-9# in its digits. As we are only considering #9#-digit integers, there is no need for any further specifications (e.g. no #0#'s).

The second part will be a loop which runs through each integer in our range for #q#, checks to see if #q# and the integer portion of #piq# fulfill the given conditions, and then prints them if they do.

In this case, we only need to match #5# digits, but there's no harm in getting more, so we will use a more accurate approximation of #pi#. An implementation in Python could look like:


"""First, we define our approximation for #pi#"""

pi = 3.1415926535

"""Next, we create a function which checks that every digit in 1-9 is in the input and output True if they are, and False otherwise"""

def allDigits(n):
return all(digit in str(n) for digit in '123456789')

"""Finally, we loop through the range of possibilities for #q#, and see if both #q# and the integer portion #p# of #piq# have all of the digits from 1-9. If so, we print them out in the form #p/q#"""

for q in range(123456789, int(987654321 / pi)):
#" "#if allDigits(q) and allDigits(int(q * pi)):
#" "#print(str(q*pi) + '/' + str(q))


The above produces #26# solutions, all of which are accurate to at least #7# decimal places, and are as follows:

#391625847/124658379, 428913756/136527489, 458629713/ 145986372, 482137956/153469278#

#482639571/153628947, 486125937/154738692, 517984326/164879532, 529136487/168429375#

#529436817/168524973, 529461387/168532794, 549231876/174825936, 549368271/174869352#

#587312964/186947523, 613987452/195438276, 683719254/217634598, 683794152/217658439#

#748162935/238147659, 748169523/238149756, 748316295/238196475, 784321596/249657318#

#796138542/253418769, 842951367/268319754, 869723514/276841593, 897463152/285671394#

#928146375/295438167, 937186245/298315647#